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: fix Created Jan. 30, 2015, 1:17 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
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 s_instance = client; 218 s_instance = client;
219 } 219 }
220 220
221 instance = s_instance; 221 instance = s_instance;
222 } 222 }
223 s_criticalSectionLocal.Unlock(); 223 s_criticalSectionLocal.Unlock();
224 224
225 return instance; 225 return instance;
226 } 226 }
227 227
228 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, int contentType, c onst std::wstring& domain, bool addDebug) 228 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, AdblockPlus::Filte rEngine::ContentType contentType, const std::wstring& domain, bool addDebug)
229 { 229 {
230 bool isBlocked = false; 230 bool isBlocked = false;
231 bool isCached = false; 231 bool isCached = false;
232 m_criticalSectionCache.Lock(); 232 m_criticalSectionCache.Lock();
233 { 233 {
234 auto it = m_cacheBlockedSources.find(src); 234 auto it = m_cacheBlockedSources.find(src);
235 235
236 isCached = it != m_cacheBlockedSources.end(); 236 isCached = it != m_cacheBlockedSources.end();
237 if (isCached) 237 if (isCached)
238 { 238 {
239 isBlocked = it->second; 239 isBlocked = it->second;
240 } 240 }
241 } 241 }
242 m_criticalSectionCache.Unlock(); 242 m_criticalSectionCache.Unlock();
243 243
244 if (!isCached) 244 if (!isCached)
245 { 245 {
246 m_criticalSectionFilter.Lock(); 246 m_criticalSectionFilter.Lock();
247 { 247 {
248 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug); 248 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug);
249 } 249 }
250 m_criticalSectionFilter.Unlock(); 250 m_criticalSectionFilter.Unlock();
251 251
252 // Cache result, if content type is defined 252 // Cache result, if content type is defined
253 if (contentType != CFilter::contentTypeAny) 253 if (contentType != AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_OTHE R)
254 { 254 {
255 m_criticalSectionCache.Lock(); 255 m_criticalSectionCache.Lock();
256 { 256 {
257 m_cacheBlockedSources[src] = isBlocked; 257 m_cacheBlockedSources[src] = isBlocked;
258 } 258 }
259 m_criticalSectionCache.Unlock(); 259 m_criticalSectionCache.Unlock();
260 } 260 }
261 } 261 }
262 return isBlocked; 262 return isBlocked;
263 } 263 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 297
298 Communication::InputBuffer response; 298 Communication::InputBuffer response;
299 if (!CallEngine(request, response)) 299 if (!CallEngine(request, response))
300 return false; 300 return false;
301 301
302 bool isWhitelisted; 302 bool isWhitelisted;
303 response >> isWhitelisted; 303 response >> isWhitelisted;
304 return isWhitelisted; 304 return isWhitelisted;
305 } 305 }
306 306
307 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain) 307 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain)
308 { 308 {
309 Communication::OutputBuffer request; 309 Communication::OutputBuffer request;
310 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 310 request << Communication::PROC_MATCHES << ToUtf8String(url) << static_cast<int 32_t>(contentType) << ToUtf8String(domain);
311 311
312 Communication::InputBuffer response; 312 Communication::InputBuffer response;
313 if (!CallEngine(request, response)) 313 if (!CallEngine(request, response))
314 return false; 314 return false;
315 315
316 bool match; 316 bool match;
317 response >> match; 317 response >> match;
318 return match; 318 return match;
319 } 319 }
320 320
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 DEBUG_GENERAL("CompareVersions"); 566 DEBUG_GENERAL("CompareVersions");
567 Communication::OutputBuffer request; 567 Communication::OutputBuffer request;
568 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2); 568 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2);
569 Communication::InputBuffer response; 569 Communication::InputBuffer response;
570 if (!CallEngine(request, response)) 570 if (!CallEngine(request, response))
571 return 0; 571 return 0;
572 int result; 572 int result;
573 response >> result; 573 response >> result;
574 return result; 574 return result;
575 } 575 }
OLDNEW

Powered by Google App Engine
This is Rietveld