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 accoring to comments Created Jan. 13, 2015, 12:59 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 #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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 280
281 Communication::InputBuffer response; 281 Communication::InputBuffer response;
282 if (!CallEngine(request, response)) 282 if (!CallEngine(request, response))
283 return false; 283 return false;
284 284
285 bool isWhitelisted; 285 bool isWhitelisted;
286 response >> isWhitelisted; 286 response >> isWhitelisted;
287 return isWhitelisted; 287 return isWhitelisted;
288 } 288 }
289 289
290 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain) 290 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain)
291 { 291 {
292 Communication::OutputBuffer request; 292 Communication::OutputBuffer request;
293 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 293 request << Communication::PROC_MATCHES << ToUtf8String(url) << static_cast<int 32_t>(contentType) << ToUtf8String(domain);
Eric 2015/01/13 17:29:36 I still think it would be good to define operator<
sergei 2015/01/28 13:44:45 done.
294 294
295 Communication::InputBuffer response; 295 Communication::InputBuffer response;
296 if (!CallEngine(request, response)) 296 if (!CallEngine(request, response))
297 return false; 297 return false;
298 298
299 bool match; 299 bool match;
300 response >> match; 300 response >> match;
301 return match; 301 return match;
302 } 302 }
303 303
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 DEBUG_GENERAL("CompareVersions"); 549 DEBUG_GENERAL("CompareVersions");
550 Communication::OutputBuffer request; 550 Communication::OutputBuffer request;
551 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2); 551 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2);
552 Communication::InputBuffer response; 552 Communication::InputBuffer response;
553 if (!CallEngine(request, response)) 553 if (!CallEngine(request, response))
554 return 0; 554 return 0;
555 int result; 555 int result;
556 response >> result; 556 response >> result;
557 return result; 557 return result;
558 } 558 }
OLDNEW

Powered by Google App Engine
This is Rietveld