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

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

Issue 29323611: Issue #1234, #2058 - Rewrite log facility, improving thread implementation
Left Patch Set: Created Aug. 19, 2015, 5:42 p.m.
Right Patch Set: rebase only Created July 27, 2016, 9:11 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
« no previous file with change/comment | « src/plugin/PluginSettings.h ('k') | src/plugin/PluginSystem.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2015 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 19
20 #include "PluginSettings.h" 20 #include "PluginSettings.h"
21 #include "AdblockPlusClient.h" 21 #include "AdblockPlusClient.h"
22 #include "PluginSystem.h" 22 #include "PluginSystem.h"
23 #include "PluginMutex.h" 23 #include "PluginMutex.h"
24 #include "../shared/Utils.h" 24 #include "../shared/Utils.h"
25 25
26 namespace 26 namespace
27 { 27 {
28 std::wstring CreateDomainWhitelistingFilter(const CString& domain) 28 std::wstring CreateDomainWhitelistingFilter(const std::wstring& domain)
29 { 29 {
30 return L"@@||" + ToWstring(domain) + L"^$document"; 30 return L"@@||" + domain + L"^$document";
31 } 31 }
32 } 32 }
33 33
34 class CPluginSettingsWhitelistLock : public CPluginMutex 34 class CPluginSettingsWhitelistLock : public CPluginMutex
35 { 35 {
36 public: 36 public:
37 CPluginSettingsWhitelistLock() : CPluginMutex(L"SettingsFileWhitelist", PLUGIN _ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} 37 CPluginSettingsWhitelistLock() : CPluginMutex(L"SettingsFileWhitelist", PLUGIN _ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {}
38 ~CPluginSettingsWhitelistLock() {} 38 ~CPluginSettingsWhitelistLock() {}
39 }; 39 };
40 40
41 CPluginSettings* CPluginSettings::s_instance = NULL; 41 CPluginSettings* CPluginSettings::s_instance = NULL;
42 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; 42 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal;
43 43
44 CPluginSettings::CPluginSettings() 44 CPluginSettings::CPluginSettings()
45 { 45 {
46 s_instance = NULL; 46 s_instance = NULL;
47 m_WindowsBuildNumber = 0;
48 ClearWhitelist(); 47 ClearWhitelist();
49 } 48 }
50 49
51 CPluginSettings::~CPluginSettings() 50 CPluginSettings::~CPluginSettings()
52 { 51 {
53 s_instance = NULL; 52 s_instance = NULL;
54 } 53 }
55 54
56 CPluginSettings* CPluginSettings::GetInstance() 55 CPluginSettings* CPluginSettings::GetInstance()
57 { 56 {
(...skipping 12 matching lines...) Expand all
70 69
71 return instance; 70 return instance;
72 } 71 }
73 72
74 73
75 bool CPluginSettings::IsPluginEnabled() const 74 bool CPluginSettings::IsPluginEnabled() const
76 { 75 {
77 return GetPluginEnabled(); 76 return GetPluginEnabled();
78 } 77 }
79 78
80 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const 79 std::map<std::wstring, std::wstring> CPluginSettings::GetFilterLanguageTitleList () const
81 { 80 {
82 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->FetchAvailableSubscriptions(); 81 auto subscriptions = CPluginClient::GetInstance()->FetchAvailableSubscriptions ();
83 82
84 std::map<CString, CString> filterList; 83 std::map<std::wstring, std::wstring> filterList;
85 for (size_t i = 0; i < subscriptions.size(); i ++) 84 for (size_t i = 0; i < subscriptions.size(); i ++)
86 { 85 {
87 SubscriptionDescription it = subscriptions[i]; 86 auto it = subscriptions[i];
88 filterList.insert(std::make_pair(CString(it.url.c_str()), CString(it.title.c _str()))); 87 filterList.insert(std::make_pair(it.url, it.title));
89 } 88 }
90 return filterList; 89 return filterList;
91 } 90 }
92 91
93 void CPluginSettings::TogglePluginEnabled() 92 void CPluginSettings::TogglePluginEnabled()
94 { 93 {
95 CPluginClient::GetInstance()->TogglePluginEnabled(); 94 CPluginClient::GetInstance()->TogglePluginEnabled();
96 } 95 }
97 bool CPluginSettings::GetPluginEnabled() const 96 bool CPluginSettings::GetPluginEnabled() const
98 { 97 {
99 return CPluginClient::GetInstance()->GetPref(L"enabled", true); 98 return CPluginClient::GetInstance()->GetPref(L"enabled", true);
100 } 99 }
101
102 100
103 // ============================================================================ 101 // ============================================================================
104 // Whitelist settings 102 // Whitelist settings
105 // ============================================================================ 103 // ============================================================================
106 104
107 void CPluginSettings::ClearWhitelist() 105 void CPluginSettings::ClearWhitelist()
108 { 106 {
109 s_criticalSectionLocal.Lock(); 107 s_criticalSectionLocal.Lock();
110 { 108 {
111 m_whitelistedDomains.clear(); 109 m_whitelistedDomains.clear();
(...skipping 22 matching lines...) Expand all
134 s_criticalSectionLocal.Unlock(); 132 s_criticalSectionLocal.Unlock();
135 } 133 }
136 else 134 else
137 { 135 {
138 isRead = false; 136 isRead = false;
139 } 137 }
140 138
141 return isRead; 139 return isRead;
142 } 140 }
143 141
144 void CPluginSettings::AddWhiteListedDomain(const CString& domain) 142 void CPluginSettings::AddWhiteListedDomain(const std::wstring& domain)
145 { 143 {
146 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) 144 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain)
147 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) ); 145 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) );
148 } 146 }
149 147
150 void CPluginSettings::RemoveWhiteListedDomain(const CString& domain) 148 void CPluginSettings::RemoveWhiteListedDomain(const std::wstring& domain)
151 { 149 {
152 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain) 150 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain)
153 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in)); 151 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in));
154 } 152 }
155 153
156 int CPluginSettings::GetWhiteListedDomainCount() const 154 int CPluginSettings::GetWhiteListedDomainCount() const
157 { 155 {
158 int count = 0; 156 int count = 0;
159 157
160 s_criticalSectionLocal.Lock(); 158 s_criticalSectionLocal.Lock();
(...skipping 16 matching lines...) Expand all
177 { 175 {
178 CPluginSettingsWhitelistLock lock; 176 CPluginSettingsWhitelistLock lock;
179 if (lock.IsLocked()) 177 if (lock.IsLocked())
180 { 178 {
181 ReadWhitelist(true); 179 ReadWhitelist(true);
182 } 180 }
183 181
184 return true; 182 return true;
185 } 183 }
186 184
187 DWORD CPluginSettings::GetWindowsBuildNumber()
188 {
189 if (m_WindowsBuildNumber == 0)
190 {
191 OSVERSIONINFOEX osvi = {};
192 osvi.dwOSVersionInfoSize = sizeof(osvi);
193 if (GetVersionExW(reinterpret_cast<OSVERSIONINFO*>(&osvi)) != 0)
194 {
195 m_WindowsBuildNumber = osvi.dwBuildNumber;
196 }
197 }
198
199 return m_WindowsBuildNumber;
200 }
201
202 void CPluginSettings::SetSubscription(const std::wstring& url) 185 void CPluginSettings::SetSubscription(const std::wstring& url)
203 { 186 {
204 CPluginClient::GetInstance()->SetSubscription(url); 187 CPluginClient::GetInstance()->SetSubscription(url);
205 RefreshWhitelist(); 188 RefreshWhitelist();
206 } 189 }
207 190
208 CString CPluginSettings::GetSubscription() 191 std::wstring CPluginSettings::GetSubscription()
209 { 192 {
210 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->GetListedSubscriptions(); 193 auto subscriptions = CPluginClient::GetInstance()->GetListedSubscriptions();
211 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_exc eptionsurl", L""); 194 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_exc eptionsurl", L"");
212 195
213 for (std::vector<SubscriptionDescription>::iterator subscription = subscriptio ns.begin(); subscription != subscriptions.end(); subscription++) 196 for (auto subscription = subscriptions.begin(); subscription != subscriptions. end(); subscription++)
214 { 197 {
215 if (subscription->url != aaUrl) 198 if (subscription->url != aaUrl)
216 { 199 {
217 return CString(subscription->url.c_str()); 200 return subscription->url;
218 } 201 }
219 } 202 }
220 return CString(L""); 203 return std::wstring();
221 } 204 }
222
223 CString CPluginSettings::GetAppLocale()
224 {
225 return ToCString(GetBrowserLanguage());
226 }
227
228 CString CPluginSettings::GetDocumentationLink()
229 {
230 return CString(CPluginClient::GetInstance()->GetDocumentationLink().c_str());
231 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld