Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/PluginTabBase.cpp

Issue 29323611: Issue #1234, #2058 - Rewrite log facility, improving thread implementation
Patch Set: address comments Created Feb. 4, 2016, 8:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginTabBase.h ('k') | test/plugin/ActiveQueueTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
19 #include "AdblockPlusClient.h" 19 #include "AdblockPlusClient.h"
20 #include "PluginClientBase.h"
21 #include "PluginSettings.h" 20 #include "PluginSettings.h"
22 #include "AdblockPlusDomTraverser.h" 21 #include "AdblockPlusDomTraverser.h"
23 #include "PluginTabBase.h" 22 #include "PluginTabBase.h"
24 #include "IeVersion.h" 23 #include "IeVersion.h"
25 #include "../shared/Utils.h" 24 #include "../shared/Utils.h"
26 #include <Mshtmhst.h> 25 #include <Mshtmhst.h>
27 26
28 CPluginTab::CPluginTab() 27 CPluginTab::CPluginTab()
29 : m_isActivated(false)
30 , m_continueThreadRunning(true)
31 { 28 {
32 m_filter.hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); 29 m_filter.hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
33 30
34 CPluginClient* client = CPluginClient::GetInstance(); 31 CPluginClient* client = CPluginClient::GetInstance();
35 if (AdblockPlus::IE::InstalledMajorVersion() < 10)
36 {
37 m_isActivated = true;
38 }
39
40 try
41 {
42 m_thread = std::thread(&CPluginTab::ThreadProc, this);
43 }
44 catch (const std::system_error& ex)
45 {
46 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREA TE_PROCESS,
47 "Tab::Thread - Failed to create tab thread");
48 }
49 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); 32 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this));
50 } 33 }
51 34
52
53 CPluginTab::~CPluginTab() 35 CPluginTab::~CPluginTab()
54 { 36 {
55 delete m_traverser; 37 delete m_traverser;
56 m_traverser = NULL; 38 m_traverser = NULL;
57 m_continueThreadRunning = false;
58 if (m_thread.joinable()) {
59 m_thread.join();
60 }
61 }
62
63 /** 39 /**
64 * ABP only intercepts protocols "http:" and "https:". 40 * ABP only intercepts protocols "http:" and "https:".
65 * We can disable any domain used in those protocol with an appropriate whitelis t filter. 41 * We can disable any domain used in those protocol with an appropriate whitelis t filter.
66 * Thus, the possibility to disable on a particular site depends only on the pro tocol. 42 * Thus, the possibility to disable on a particular site depends only on the pro tocol.
67 */ 43 */
68 bool CPluginTab::IsPossibleToDisableOnSite() 44 bool CPluginTab::IsPossibleToDisableOnSite()
69 { 45 {
70 auto url = GetDocumentUrl(); 46 auto url = GetDocumentUrl();
71 return BeginsWith(url, L"http:") || BeginsWith(url, L"https:"); 47 return BeginsWith(url, L"http:") || BeginsWith(url, L"https:");
72 } 48 }
73 49
74 void CPluginTab::OnActivate()
75 {
76 m_isActivated = true;
77 }
78
79
80 void CPluginTab::OnUpdate()
81 {
82 m_isActivated = true;
83 } 50 }
84 51
85 namespace 52 namespace
86 { 53 {
87 // Entry Point 54 // Entry Point
88 void FilterLoader(CPluginFilter* filter, const std::wstring& domain) 55 void FilterLoader(CPluginFilter* filter, const std::wstring& domain)
89 { 56 {
90 try 57 try
91 { 58 {
92 filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSele ctors(domain)); 59 filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSele ctors(domain));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 { 354 {
388 if (domain.empty() || domain != m_cacheDomain) 355 if (domain.empty() || domain != m_cacheDomain)
389 { 356 {
390 m_cacheFrames.clear(); 357 m_cacheFrames.clear();
391 m_cacheDomain = domain; 358 m_cacheDomain = domain;
392 } 359 }
393 } 360 }
394 m_criticalSectionCache.Unlock(); 361 m_criticalSectionCache.Unlock();
395 } 362 }
396 363
397 void CPluginTab::ThreadProc()
398 {
399 // Force loading/creation of settings
400 CPluginSettings::GetInstance();
401
402 std::string message =
403 "=========================================================================== =====\n"
404 "TAB THREAD process=";
405 message += std::to_string(::GetCurrentProcessId());
406 message + " thread=";
407 message += std::to_string(::GetCurrentThreadId());
408 message +=
409 "\n"
410 "=========================================================================== =====";
411 DEBUG_GENERAL(message);
412
413 // --------------------------------------------------------------------
414 // Tab loop
415 // --------------------------------------------------------------------
416
417 DWORD loopCount = 0;
418 DWORD tabLoopIteration = 1;
419
420 while (this->m_continueThreadRunning)
421 {
422 #ifdef ENABLE_DEBUG_THREAD
423 CStringA sTabLoopIteration;
424 sTabLoopIteration.Format("%u", tabLoopIteration);
425
426 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
427 DEBUG_THREAD("Loop iteration " + sTabLoopIteration);
428 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
429 #endif
430 this->m_isActivated = false;
431
432 // --------------------------------------------------------------------
433 // End loop
434 // --------------------------------------------------------------------
435
436 // Sleep loop
437 while (this->m_continueThreadRunning && !this->m_isActivated && (++loopCou nt % (TIMER_THREAD_SLEEP_TAB_LOOP / 50)) != 0)
438 {
439 // Post async plugin error
440 CPluginError pluginError;
441 if (LogQueue::PopFirstPluginError(pluginError))
442 {
443 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
444 }
445
446 // Non-hanging sleep
447 Sleep(50);
448 }
449
450 tabLoopIteration++;
451 }
452 }
OLDNEW
« no previous file with comments | « src/plugin/PluginTabBase.h ('k') | test/plugin/ActiveQueueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld