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

Side by Side Diff: include/AdblockPlus/FilterEngine.h

Issue 29377064: Issue 4944 - Make creation of FilterEngine asynchronous. (Closed)
Patch Set: Created Feb. 28, 2017, 2:21 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
« no previous file with comments | « README.md ('k') | shell/src/Main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2016 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
(...skipping 11 matching lines...) Expand all
22 #include <map> 22 #include <map>
23 #include <string> 23 #include <string>
24 #include <vector> 24 #include <vector>
25 #include <AdblockPlus/JsEngine.h> 25 #include <AdblockPlus/JsEngine.h>
26 #include <AdblockPlus/JsValue.h> 26 #include <AdblockPlus/JsValue.h>
27 #include <AdblockPlus/Notification.h> 27 #include <AdblockPlus/Notification.h>
28 28
29 namespace AdblockPlus 29 namespace AdblockPlus
30 { 30 {
31 class FilterEngine; 31 class FilterEngine;
32 typedef std::shared_ptr<FilterEngine> FilterEnginePtr;
32 33
33 /** 34 /**
34 * Wrapper for an Adblock Plus filter object. 35 * Wrapper for an Adblock Plus filter object.
35 * There are no accessors for most 36 * There are no accessors for most
36 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml), 37 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml),
37 * use `GetProperty()` to retrieve them by name. 38 * use `GetProperty()` to retrieve them by name.
38 */ 39 */
39 class Filter : public JsValue, 40 class Filter : public JsValue,
40 public std::enable_shared_from_this<Filter> 41 public std::enable_shared_from_this<Filter>
41 { 42 {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 */ 207 */
207 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; 208 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs;
208 209
209 /** 210 /**
210 * Callback type invoked when a new notification should be shown. 211 * Callback type invoked when a new notification should be shown.
211 * The parameter is the Notification object to be shown. 212 * The parameter is the Notification object to be shown.
212 */ 213 */
213 typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback ; 214 typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback ;
214 215
215 /** 216 /**
216 * Constructor. 217 * FilterEngine creation parameters.
218 */
219 struct CreateParameters
Oleksandr 2017/03/16 15:05:25 Nit: How about CreationParameters. One might assum
sergei 2017/03/16 15:50:03 Agree, done.
220 {
221 /**
222 * `AdblockPlus::FilterEngine::Prefs` name - value list of preconfigured
223 * prefs.
224 */
225 Prefs preconfiguredPrefs;
226 };
227
228 /**
229 * Callback type invoked when FilterEngine is created.
230 */
231 typedef std::function<void(const FilterEnginePtr&)> OnCreatedCallback;
232
233 /**
234 * Asynchronously constructs FilterEngine.
217 * @param jsEngine `JsEngine` instance used to run JavaScript code 235 * @param jsEngine `JsEngine` instance used to run JavaScript code
218 * internally. 236 * internally.
219 * @param preconfiguredPrefs `AdblockPlus::FilterEngine::Prefs` 237 * @param onCreated A callback which is called when FilterEngine is ready
220 * name-value list of preconfigured prefs. 238 * for use.
239 * @param parameters optional creation parameters.
221 */ 240 */
222 explicit FilterEngine(JsEnginePtr jsEngine, 241 static void CreateAsync(const JsEnginePtr& jsEngine,
Eric 2017/02/28 17:04:50 (1) C++ has <future>. (2) This is new code. This
sergei 2017/02/28 22:18:27 Sorry, but what is the aim of this message? We cur
Oleksandr 2017/03/16 15:05:25 It does not look like we'll be able to move to a n
223 const Prefs& preconfiguredPrefs = Prefs() 242 const OnCreatedCallback& onCreated,
224 ); 243 const CreateParameters& parameters = CreateParameters());
244
245 /**
246 * Synchronous interface to construct FilterEngine. For details see
247 * asynchronous version CreateAsync.
248 */
249 static FilterEnginePtr Create(const JsEnginePtr& jsEngine,
250 const CreateParameters& params = CreateParameters());
225 251
226 /** 252 /**
227 * Retrieves the `JsEngine` instance associated with this `FilterEngine` 253 * Retrieves the `JsEngine` instance associated with this `FilterEngine`
228 * instance. 254 * instance.
229 */ 255 */
230 JsEnginePtr GetJsEngine() const { return jsEngine; } 256 JsEnginePtr GetJsEngine() const { return jsEngine; }
231 257
232 /** 258 /**
233 * Checks if this is the first run of the application. 259 * Checks if this is the first run of the application.
234 * @return `true` if the application is running for the first time. 260 * @return `true` if the application is running for the first time.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 /** 461 /**
436 * Retrieves the string representation of the supplied `ContentType`. 462 * Retrieves the string representation of the supplied `ContentType`.
437 * @param contentType `ContentType` value. 463 * @param contentType `ContentType` value.
438 * @return The string representation of `contentType`. 464 * @return The string representation of `contentType`.
439 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. 465 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied.
440 */ 466 */
441 static std::string ContentTypeToString(ContentType contentType); 467 static std::string ContentTypeToString(ContentType contentType);
442 468
443 private: 469 private:
444 JsEnginePtr jsEngine; 470 JsEnginePtr jsEngine;
445 bool initialized;
446 bool firstRun; 471 bool firstRun;
447 int updateCheckId; 472 int updateCheckId;
448 static const std::map<ContentType, std::string> contentTypes; 473 static const std::map<ContentType, std::string> contentTypes;
449 474
450 void InitDone(JsValueList& params); 475 explicit FilterEngine(const JsEnginePtr& jsEngine);
476
451 FilterPtr CheckFilterMatch(const std::string& url, 477 FilterPtr CheckFilterMatch(const std::string& url,
452 ContentTypeMask contentTypeMask, 478 ContentTypeMask contentTypeMask,
453 const std::string& documentUrl) const; 479 const std::string& documentUrl) const;
454 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); 480 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params);
455 void UpdateCheckDone(const std::string& eventName, 481 void UpdateCheckDone(const std::string& eventName,
456 UpdateCheckDoneCallback callback, JsValueList& params); 482 UpdateCheckDoneCallback callback, JsValueList& params);
457 void FilterChanged(FilterChangeCallback callback, JsValueList& params); 483 void FilterChanged(FilterChangeCallback callback, JsValueList& params);
458 void ShowNotification(const ShowNotificationCallback& callback, 484 void ShowNotification(const ShowNotificationCallback& callback,
459 const JsValueList& params); 485 const JsValueList& params);
460 FilterPtr GetWhitelistingFilter(const std::string& url, 486 FilterPtr GetWhitelistingFilter(const std::string& url,
461 ContentTypeMask contentTypeMask, const std::string& documentUrl) const; 487 ContentTypeMask contentTypeMask, const std::string& documentUrl) const;
462 FilterPtr GetWhitelistingFilter(const std::string& url, 488 FilterPtr GetWhitelistingFilter(const std::string& url,
463 ContentTypeMask contentTypeMask, 489 ContentTypeMask contentTypeMask,
464 const std::vector<std::string>& documentUrls) const; 490 const std::vector<std::string>& documentUrls) const;
465 }; 491 };
466 } 492 }
467 493
468 #endif 494 #endif
OLDNEW
« no previous file with comments | « README.md ('k') | shell/src/Main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld