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

Delta Between Two Patch Sets: src/plugin/PluginClass.cpp

Issue 29330403: Issue #1467, #3397 - Rewrite the map from threads to tabs (Closed)
Left Patch Set: rebase to current tip / address comments Created Feb. 3, 2016, 5:22 p.m.
Right Patch Set: add comment; new function body Created July 17, 2016, 4:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base; 75 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base;
76 76
77 public: 77 public:
78 bool AddIfAbsent(CPluginClass* p) 78 bool AddIfAbsent(CPluginClass* p)
79 { 79 {
80 return Base::AddIfAbsent(::GetCurrentThreadId(), p); 80 return Base::AddIfAbsent(::GetCurrentThreadId(), p);
81 } 81 }
82 82
83 bool RemoveAndCheck() 83 bool RemoveAndCheck()
84 { 84 {
85 return Base::RemoveAndCheck(::GetCurrentThreadId()); 85 return Base::RemoveIfPresent(::GetCurrentThreadId());
86 } 86 }
87 87
88 CPluginClass* Locate() 88 CPluginClass* Locate()
89 { 89 {
90 return Base::Locate(::GetCurrentThreadId()); 90 return Base::Locate(::GetCurrentThreadId());
91 } 91 }
92 }; 92 };
93 93
94 /** 94 /**
95 * Map from thread ID's to CPluginClass instances 95 * Map from thread ID's to CPluginClass instances
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); 274 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
275 ss << L", browser = " << ToHexLiteral(m_webBrowser2); 275 ss << L", browser = " << ToHexLiteral(m_webBrowser2);
276 return ss.str(); 276 return ss.str();
277 }()); 277 }());
278 278
279 /* 279 /*
280 * Add ourselves to the thread map. 280 * Add ourselves to the thread map.
281 */ 281 */
282 if (!threadMap.AddIfAbsent(this)) 282 if (!threadMap.AddIfAbsent(this))
283 { 283 {
284 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi ng entry in thread map"); 284 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi ng entry in thread map");
sergei 2016/02/08 13:35:37 I would also like to have asserts here and for Rem
Eric 2016/02/08 18:45:31 No. We have error handling already. Doubling it up
Oleksandr 2016/02/10 10:58:48 I don't think we need asserts here as well.
285 } 285 }
286 286
287 //register the mimefilter 287 //register the mimefilter
288 //and only mimefilter 288 //and only mimefilter
289 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 289 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
290 s_criticalSectionLocal.Lock(); 290 s_criticalSectionLocal.Lock();
291 { 291 {
292 // Always register on startup, then check if we need to unregister in a separate thread 292 // Always register on startup, then check if we need to unregister in a separate thread
293 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 293 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
294 s_asyncWebBrowser2 = unknownSite; 294 s_asyncWebBrowser2 = unknownSite;
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 s_criticalSectionLocal.Unlock(); 1017 s_criticalSectionLocal.Unlock();
1018 1018
1019 return result; 1019 return result;
1020 } 1020 }
1021 1021
1022 CPluginTab* CPluginClass::GetTab() 1022 CPluginTab* CPluginClass::GetTab()
1023 { 1023 {
1024 return m_tab; 1024 return m_tab;
1025 } 1025 }
1026 1026
1027 CPluginTab* CPluginClass::GetTabCurrentThread() 1027 CPluginTab* CPluginClass::GetTabForCurrentThread()
1028 { 1028 {
1029 auto p = threadMap.Locate(); 1029 auto p = threadMap.Locate();
1030 return p ? p->m_tab : nullptr; 1030 return p ? p->m_tab : nullptr;
1031 } 1031 }
1032 1032
1033 // Entry point 1033 // Entry point
1034 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 1034 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
1035 { 1035 {
1036 try 1036 try
1037 { 1037 {
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 } 1431 }
1432 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m); 1432 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m);
1433 } 1433 }
1434 1434
1435 1435
1436 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) 1436 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1437 { 1437 {
1438 // use the disable icon as defualt, if the client doesn't exists 1438 // use the disable icon as defualt, if the client doesn't exists
1439 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1439 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1440 1440
1441 CPluginTab* tab = GetTabCurrentThread(); 1441 CPluginTab* tab = GetTabForCurrentThread();
1442 if (tab) 1442 if (tab)
1443 { 1443 {
1444 CPluginClient* client = CPluginClient::GetInstance(); 1444 CPluginClient* client = CPluginClient::GetInstance();
1445 if (CPluginSettings::GetInstance()->IsPluginEnabled()) 1445 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1446 { 1446 {
1447 if (client->IsWhitelistedUrl(url)) 1447 if (client->IsWhitelistedUrl(url))
1448 { 1448 {
1449 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1449 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1450 } 1450 }
1451 else 1451 else
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN ); 1595 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN );
1596 break; 1596 break;
1597 } 1597 }
1598 case WM_DESTROY: 1598 case WM_DESTROY:
1599 break; 1599 break;
1600 case SC_CLOSE: 1600 case SC_CLOSE:
1601 break; 1601 break;
1602 1602
1603 case WM_UPDATEUISTATE: 1603 case WM_UPDATEUISTATE:
1604 { 1604 {
1605 CPluginTab* tab = GetTabCurrentThread(); 1605 CPluginTab* tab = GetTabForCurrentThread();
1606 if (tab) 1606 if (tab)
1607 { 1607 {
1608 tab->OnActivate(); 1608 tab->OnActivate();
1609 RECT rect; 1609 RECT rect;
1610 GetWindowRect(pClass->m_hPaneWnd, &rect); 1610 GetWindowRect(pClass->m_hPaneWnd, &rect);
1611 pClass->notificationMessage.MoveToCenter(rect); 1611 pClass->notificationMessage.MoveToCenter(rect);
1612 } 1612 }
1613 if (LOWORD(wParam) == UIS_CLEAR) 1613 if (LOWORD(wParam) == UIS_CLEAR)
1614 { 1614 {
1615 pClass->notificationMessage.Hide(); 1615 pClass->notificationMessage.Hide();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 s_criticalSectionLocal.Unlock(); 1728 s_criticalSectionLocal.Unlock();
1729 1729
1730 return icon; 1730 return icon;
1731 } 1731 }
1732 1732
1733 ATOM CPluginClass::GetAtomPaneClass() 1733 ATOM CPluginClass::GetAtomPaneClass()
1734 { 1734 {
1735 return s_atomPaneClass; 1735 return s_atomPaneClass;
1736 } 1736 }
1737 1737
LEFTRIGHT

Powered by Google App Engine
This is Rietveld