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: Created Aug. 19, 2015, 5:42 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
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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 { 268 {
301 if (domain.empty() || domain != m_cacheDomain) 269 if (domain.empty() || domain != m_cacheDomain)
302 { 270 {
303 m_cacheFrames.clear(); 271 m_cacheFrames.clear();
304 m_cacheDomain = domain; 272 m_cacheDomain = domain;
305 } 273 }
306 } 274 }
307 m_criticalSectionCache.Unlock(); 275 m_criticalSectionCache.Unlock();
308 } 276 }
309 277
310 void CPluginTabBase::ThreadProc()
311 {
312 // Force loading/creation of settings
313 CPluginSettings::GetInstance();
314
315 std::string message =
316 "=========================================================================== =====\n"
317 "TAB THREAD process=";
318 message += std::to_string(::GetCurrentProcessId());
319 message + " thread=";
320 message += std::to_string(::GetCurrentThreadId());
321 message +=
322 "\n"
323 "=========================================================================== =====";
324 DEBUG_GENERAL(message);
325
326 // --------------------------------------------------------------------
327 // Tab loop
328 // --------------------------------------------------------------------
329
330 DWORD loopCount = 0;
331 DWORD tabLoopIteration = 1;
332
333 while (this->m_continueThreadRunning)
334 {
335 #ifdef ENABLE_DEBUG_THREAD
336 CStringA sTabLoopIteration;
337 sTabLoopIteration.Format("%u", tabLoopIteration);
338
339 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
340 DEBUG_THREAD("Loop iteration " + sTabLoopIteration);
341 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
342 #endif
343 this->m_isActivated = false;
344
345 // --------------------------------------------------------------------
346 // End loop
347 // --------------------------------------------------------------------
348
349 // Sleep loop
350 while (this->m_continueThreadRunning && !this->m_isActivated && (++loopCou nt % (TIMER_THREAD_SLEEP_TAB_LOOP / 50)) != 0)
351 {
352 // Post async plugin error
353 CPluginError pluginError;
354 if (LogQueue::PopFirstPluginError(pluginError))
355 {
356 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
357 }
358
359 // Non-hanging sleep
360 Sleep(50);
361 }
362
363 tabLoopIteration++;
364 }
365 }
OLDNEW

Powered by Google App Engine
This is Rietveld