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 to current tip Created Jan. 5, 2016, 2:52 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 "../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 void CPluginTab::OnActivate()
64 {
65 m_isActivated = true;
66 }
67
68
69 void CPluginTab::OnUpdate()
70 {
71 m_isActivated = true;
72 } 39 }
73 40
74 namespace 41 namespace
75 { 42 {
76 // Entry Point 43 // Entry Point
77 void FilterLoader(CPluginFilter* filter, const std::wstring& domain) 44 void FilterLoader(CPluginFilter* filter, const std::wstring& domain)
78 { 45 {
79 try 46 try
80 { 47 {
81 filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSele ctors(domain)); 48 filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSele ctors(domain));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 { 343 {
377 if (domain.empty() || domain != m_cacheDomain) 344 if (domain.empty() || domain != m_cacheDomain)
378 { 345 {
379 m_cacheFrames.clear(); 346 m_cacheFrames.clear();
380 m_cacheDomain = domain; 347 m_cacheDomain = domain;
381 } 348 }
382 } 349 }
383 m_criticalSectionCache.Unlock(); 350 m_criticalSectionCache.Unlock();
384 } 351 }
385 352
386 void CPluginTab::ThreadProc()
387 {
388 // Force loading/creation of settings
389 CPluginSettings::GetInstance();
390
391 std::string message =
392 "=========================================================================== =====\n"
393 "TAB THREAD process=";
394 message += std::to_string(::GetCurrentProcessId());
395 message + " thread=";
396 message += std::to_string(::GetCurrentThreadId());
397 message +=
398 "\n"
399 "=========================================================================== =====";
400 DEBUG_GENERAL(message);
401
402 // --------------------------------------------------------------------
403 // Tab loop
404 // --------------------------------------------------------------------
405
406 DWORD loopCount = 0;
407 DWORD tabLoopIteration = 1;
408
409 while (this->m_continueThreadRunning)
410 {
411 #ifdef ENABLE_DEBUG_THREAD
412 CStringA sTabLoopIteration;
413 sTabLoopIteration.Format("%u", tabLoopIteration);
414
415 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
416 DEBUG_THREAD("Loop iteration " + sTabLoopIteration);
417 DEBUG_THREAD("-------------------------------------------------------------- ------------------")
418 #endif
419 this->m_isActivated = false;
420
421 // --------------------------------------------------------------------
422 // End loop
423 // --------------------------------------------------------------------
424
425 // Sleep loop
426 while (this->m_continueThreadRunning && !this->m_isActivated && (++loopCou nt % (TIMER_THREAD_SLEEP_TAB_LOOP / 50)) != 0)
427 {
428 // Post async plugin error
429 CPluginError pluginError;
430 if (LogQueue::PopFirstPluginError(pluginError))
431 {
432 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
433 }
434
435 // Non-hanging sleep
436 Sleep(50);
437 }
438
439 tabLoopIteration++;
440 }
441 }
OLDNEW

Powered by Google App Engine
This is Rietveld