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

Unified Diff: include/AdblockPlus/FilterEngine.h

Issue 29377064: Issue 4944 - Make creation of FilterEngine asynchronous. (Closed)
Patch Set: rebase and address comments Created March 16, 2017, 3:47 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | shell/src/Main.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/FilterEngine.h
diff --git a/include/AdblockPlus/FilterEngine.h b/include/AdblockPlus/FilterEngine.h
index 94b376eb8caadee35db2d4b96893ee5b0702b16d..ab35fa2e10530fe6cc64e46166536bc86f1d5d26 100644
--- a/include/AdblockPlus/FilterEngine.h
+++ b/include/AdblockPlus/FilterEngine.h
@@ -29,6 +29,7 @@
namespace AdblockPlus
{
class FilterEngine;
+ typedef std::shared_ptr<FilterEngine> FilterEnginePtr;
/**
* Wrapper for an Adblock Plus filter object.
@@ -213,15 +214,40 @@ namespace AdblockPlus
typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback;
/**
- * Constructor.
+ * FilterEngine creation parameters.
+ */
+ struct CreationParameters
+ {
+ /**
+ * `AdblockPlus::FilterEngine::Prefs` name - value list of preconfigured
+ * prefs.
+ */
+ Prefs preconfiguredPrefs;
+ };
+
+ /**
+ * Callback type invoked when FilterEngine is created.
+ */
+ typedef std::function<void(const FilterEnginePtr&)> OnCreatedCallback;
+
+ /**
+ * Asynchronously constructs FilterEngine.
* @param jsEngine `JsEngine` instance used to run JavaScript code
* internally.
- * @param preconfiguredPrefs `AdblockPlus::FilterEngine::Prefs`
- * name-value list of preconfigured prefs.
+ * @param onCreated A callback which is called when FilterEngine is ready
+ * for use.
+ * @param parameters optional creation parameters.
*/
- explicit FilterEngine(JsEnginePtr jsEngine,
- const Prefs& preconfiguredPrefs = Prefs()
- );
+ static void CreateAsync(const JsEnginePtr& jsEngine,
+ const OnCreatedCallback& onCreated,
+ const CreationParameters& parameters = CreationParameters());
+
+ /**
+ * Synchronous interface to construct FilterEngine. For details see
+ * asynchronous version CreateAsync.
+ */
+ static FilterEnginePtr Create(const JsEnginePtr& jsEngine,
+ const CreationParameters& params = CreationParameters());
/**
* Retrieves the `JsEngine` instance associated with this `FilterEngine`
@@ -442,12 +468,12 @@ namespace AdblockPlus
private:
JsEnginePtr jsEngine;
- bool initialized;
bool firstRun;
int updateCheckId;
static const std::map<ContentType, std::string> contentTypes;
- void InitDone(JsValueList& params);
+ explicit FilterEngine(const JsEnginePtr& jsEngine);
+
FilterPtr CheckFilterMatch(const std::string& url,
ContentTypeMask contentTypeMask,
const std::string& documentUrl) const;
« 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