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

Side by Side Diff: src/FilterEngine.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Updated patch after review. Created June 16, 2017, 9:52 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 bool Subscription::IsAA() const 173 bool Subscription::IsAA() const
174 { 174 {
175 return jsEngine->Evaluate("API.isAASubscription").Call(*this).AsBool(); 175 return jsEngine->Evaluate("API.isAASubscription").Call(*this).AsBool();
176 } 176 }
177 177
178 bool Subscription::operator==(const Subscription& subscription) const 178 bool Subscription::operator==(const Subscription& subscription) const
179 { 179 {
180 return GetProperty("url").AsString() == subscription.GetProperty("url").AsStri ng(); 180 return GetProperty("url").AsString() == subscription.GetProperty("url").AsStri ng();
181 } 181 }
182 182
183 namespace
184 {
185 class Sync
186 {
187 public:
188 Sync()
189 :initialized(false)
190 {
191
192 }
193 void Wait()
194 {
195 std::unique_lock<std::mutex> lock(mutex);
196 while (!initialized)
197 cv.wait(lock);
198 }
199 void Set()
200 {
201 {
202 std::unique_lock<std::mutex> lock(mutex);
203 initialized = true;
204 }
205 cv.notify_all();
206 }
207 private:
208 std::mutex mutex;
209 std::condition_variable cv;
210 bool initialized;
211 };
212 }
213
214 FilterEngine::FilterEngine(const JsEnginePtr& jsEngine) 183 FilterEngine::FilterEngine(const JsEnginePtr& jsEngine)
215 : jsEngine(jsEngine), firstRun(false), updateCheckId(0) 184 : jsEngine(jsEngine), firstRun(false), updateCheckId(0)
216 { 185 {
217 } 186 }
218 187
219 void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine, 188 void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
220 const FilterEngine::OnCreatedCallback& onCreated, 189 const FilterEngine::OnCreatedCallback& onCreated,
221 const FilterEngine::CreationParameters& params) 190 const FilterEngine::CreationParameters& params)
222 { 191 {
223 FilterEnginePtr filterEngine(new FilterEngine(jsEngine)); 192 FilterEnginePtr filterEngine(new FilterEngine(jsEngine));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine, 262 FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine,
294 const FilterEngine::CreationParameters& params) 263 const FilterEngine::CreationParameters& params)
295 { 264 {
296 FilterEnginePtr retValue; 265 FilterEnginePtr retValue;
297 Sync sync; 266 Sync sync;
298 CreateAsync(jsEngine, [&retValue, &sync](const FilterEnginePtr& filterEngine) 267 CreateAsync(jsEngine, [&retValue, &sync](const FilterEnginePtr& filterEngine)
299 { 268 {
300 retValue = filterEngine; 269 retValue = filterEngine;
301 sync.Set(); 270 sync.Set();
302 }, params); 271 }, params);
303 sync.Wait(); 272 sync.Wait(std::chrono::milliseconds::zero());
304 return retValue; 273 return retValue;
305 } 274 }
306 275
307 namespace 276 namespace
308 { 277 {
309 typedef std::map<FilterEngine::ContentType, std::string> ContentTypeMap; 278 typedef std::map<FilterEngine::ContentType, std::string> ContentTypeMap;
310 279
311 ContentTypeMap CreateContentTypeMap() 280 ContentTypeMap CreateContentTypeMap()
312 { 281 {
313 ContentTypeMap contentTypes; 282 ContentTypeMap contentTypes;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 605 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
637 if (filter) 606 if (filter)
638 { 607 {
639 return filter; 608 return filter;
640 } 609 }
641 currentUrl = parentUrl; 610 currentUrl = parentUrl;
642 } 611 }
643 while (urlIterator != documentUrls.end()); 612 while (urlIterator != documentUrls.end());
644 return FilterPtr(); 613 return FilterPtr();
645 } 614 }
OLDNEW

Powered by Google App Engine
This is Rietveld