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

Side by Side Diff: src/plugin/AdblockPlusClient.cpp

Issue 5316782940225536: Issue 1557 - Update to the recent libadblockplus to reduce additional updates in the logic later. (Closed)
Patch Set: remove debugging code Created Nov. 24, 2014, 11:09 a.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 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include "PluginSettings.h" 2 #include "PluginSettings.h"
3 #include "PluginSystem.h" 3 #include "PluginSystem.h"
4 #include "PluginFilter.h" 4 #include "PluginFilter.h"
5 #include "PluginClientFactory.h" 5 #include "PluginClientFactory.h"
6 #include "PluginMutex.h" 6 #include "PluginMutex.h"
7 #include "PluginClass.h" 7 #include "PluginClass.h"
8 8
9 #include "AdblockPlusClient.h" 9 #include "AdblockPlusClient.h"
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 s_instance = client; 201 s_instance = client;
202 } 202 }
203 203
204 instance = s_instance; 204 instance = s_instance;
205 } 205 }
206 s_criticalSectionLocal.Unlock(); 206 s_criticalSectionLocal.Unlock();
207 207
208 return instance; 208 return instance;
209 } 209 }
210 210
211 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, int contentType, c onst std::wstring& domain, bool addDebug) 211 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, AdblockPlus::Filte rEngine::ContentType contentType, const std::wstring& domain, bool addDebug)
212 { 212 {
213 bool isBlocked = false; 213 bool isBlocked = false;
214 bool isCached = false; 214 bool isCached = false;
215 m_criticalSectionCache.Lock(); 215 m_criticalSectionCache.Lock();
216 { 216 {
217 auto it = m_cacheBlockedSources.find(src); 217 auto it = m_cacheBlockedSources.find(src);
218 218
219 isCached = it != m_cacheBlockedSources.end(); 219 isCached = it != m_cacheBlockedSources.end();
220 if (isCached) 220 if (isCached)
221 { 221 {
222 isBlocked = it->second; 222 isBlocked = it->second;
223 } 223 }
224 } 224 }
225 m_criticalSectionCache.Unlock(); 225 m_criticalSectionCache.Unlock();
226 226
227 if (!isCached) 227 if (!isCached)
228 { 228 {
229 m_criticalSectionFilter.Lock(); 229 m_criticalSectionFilter.Lock();
230 { 230 {
231 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug); 231 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug);
232 } 232 }
233 m_criticalSectionFilter.Unlock(); 233 m_criticalSectionFilter.Unlock();
234 234
235 // Cache result, if content type is defined 235 // Cache result, if content type is defined
236 if (contentType != CFilter::contentTypeAny) 236 if (contentType != AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_OTHE R)
237 { 237 {
238 m_criticalSectionCache.Lock(); 238 m_criticalSectionCache.Lock();
239 { 239 {
240 m_cacheBlockedSources[src] = isBlocked; 240 m_cacheBlockedSources[src] = isBlocked;
241 } 241 }
242 m_criticalSectionCache.Unlock(); 242 m_criticalSectionCache.Unlock();
243 } 243 }
244 } 244 }
245 return isBlocked; 245 return isBlocked;
246 } 246 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 cbData = 50; 301 cbData = 50;
302 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a); 302 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a);
303 if (status != 0) 303 if (status != 0)
304 { 304 {
305 return 0; 305 return 0;
306 } 306 }
307 RegCloseKey(hKey); 307 RegCloseKey(hKey);
308 return (int)(version[0] - 48); 308 return (int)(version[0] - 48);
309 } 309 }
310 310
311 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain) 311 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain)
312 { 312 {
313 Communication::OutputBuffer request; 313 Communication::OutputBuffer request;
314 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 314 request << Communication::PROC_MATCHES << ToUtf8String(url) << static_cast<int 32_t>(contentType) << ToUtf8String(domain);
315 315
316 Communication::InputBuffer response; 316 Communication::InputBuffer response;
317 if (!CallEngine(request, response)) 317 if (!CallEngine(request, response))
318 return false; 318 return false;
319 319
320 bool match; 320 bool match;
321 response >> match; 321 response >> match;
322 return match; 322 return match;
323 } 323 }
324 324
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 DEBUG_GENERAL("CompareVersions"); 570 DEBUG_GENERAL("CompareVersions");
571 Communication::OutputBuffer request; 571 Communication::OutputBuffer request;
572 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2); 572 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2);
573 Communication::InputBuffer response; 573 Communication::InputBuffer response;
574 if (!CallEngine(request, response)) 574 if (!CallEngine(request, response))
575 return 0; 575 return 0;
576 int result; 576 int result;
577 response >> result; 577 response >> result;
578 return result; 578 return result;
579 } 579 }
OLDNEW

Powered by Google App Engine
This is Rietveld