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: rebase only Created Nov. 26, 2015, 1:07 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 <Mshtmhst.h> 24 #include <Mshtmhst.h>
26 25
27 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) 26 CPluginTabBase::CPluginTabBase(CPluginClass* plugin)
28 : m_plugin(plugin) 27 : m_plugin(plugin)
29 , m_isActivated(false)
30 , m_continueThreadRunning(true)
31 { 28 {
32 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 29 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
33 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); 30 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
34 31
35 CPluginClient* client = CPluginClient::GetInstance(); 32 CPluginClient* client = CPluginClient::GetInstance();
36 if (AdblockPlus::IE::InstalledMajorVersion() < 10)
37 {
38 m_isActivated = true;
39 }
40
41 try
42 {
43 m_thread = std::thread(&CPluginTabBase::ThreadProc, this);
44 }
45 catch (const std::system_error& ex)
46 {
47 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREA TE_PROCESS,
48 "Tab::Thread - Failed to create tab thread");
49 }
50 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); 33 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this));
51 } 34 }
52 35
53 36
54 CPluginTabBase::~CPluginTabBase() 37 CPluginTabBase::~CPluginTabBase()
55 { 38 {
56 delete m_traverser; 39 delete m_traverser;
57 m_traverser = NULL; 40 m_traverser = NULL;
58 m_continueThreadRunning = false;
59 if (m_thread.joinable()) {
60 m_thread.join();
61 }
62 }
63
64 void CPluginTabBase::OnActivate()
65 {
66 m_isActivated = true;
67 }
68
69
70 void CPluginTabBase::OnUpdate()
71 {
72 m_isActivated = true;
73 } 41 }
74 42
75 namespace 43 namespace
76 { 44 {
77 // Entry Point 45 // Entry Point
78 void FilterLoader(CPluginTabBase* tabBase) 46 void FilterLoader(CPluginTabBase* tabBase)
79 { 47 {
80 try 48 try
81 { 49 {
82 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElemen tHidingSelectors(tabBase->GetDocumentDomain())); 50 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElemen tHidingSelectors(tabBase->GetDocumentDomain()));
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 { 297 {
330 if (domain.empty() || domain != m_cacheDomain) 298 if (domain.empty() || domain != m_cacheDomain)
331 { 299 {
332 m_cacheFrames.clear(); 300 m_cacheFrames.clear();
333 m_cacheDomain = domain; 301 m_cacheDomain = domain;
334 } 302 }
335 } 303 }
336 m_criticalSectionCache.Unlock(); 304 m_criticalSectionCache.Unlock();
337 } 305 }
338 306
339 void CPluginTabBase::ThreadProc()
340 {
341 // Force loading/creation of settings
342 CPluginSettings::GetInstance();
343
344 std::string message =
345 "=========================================================================== =====\n"
346 "TAB THREAD process=";
347 message += std::to_string(::GetCurrentProcessId());
348 message + " thread=";
349 message += std::to_string(::GetCurrentThreadId());
350 message +=
351 "\n"
352 "=========================================================================== =====";
353 DEBUG_GENERAL(message);
354
355 // --------------------------------------------------------------------
356 // Tab loop
357 // --------------------------------------------------------------------
358
359 DWORD loopCount = 0;
360 DWORD tabLoopIteration = 1;
361
362 while (this->m_continueThreadRunning)
363 {
364 #ifdef ENABLE_DEBUG_THREAD
365 CStringA sTabLoopIteration;
366 sTabLoopIteration.Format("%u", tabLoopIteration);
367
368 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
369 DEBUG_THREAD("Loop iteration " + sTabLoopIteration);
370 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
371 #endif
372 this->m_isActivated = false;
373
374 // --------------------------------------------------------------------
375 // End loop
376 // --------------------------------------------------------------------
377
378 // Sleep loop
379 while (this->m_continueThreadRunning && !this->m_isActivated && (++loopCou nt % (TIMER_THREAD_SLEEP_TAB_LOOP / 50)) != 0)
380 {
381 // Post async plugin error
382 CPluginError pluginError;
383 if (LogQueue::PopFirstPluginError(pluginError))
384 {
385 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
386 }
387
388 // Non-hanging sleep
389 Sleep(50);
390 }
391
392 tabLoopIteration++;
393 }
394 }
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