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

Unified Diff: include/AdblockPlus/Platform.h

Issue 29527821: Issue 5556 - Update to use libadblockplus revision hg:36e9993fa36c (Closed)
Patch Set: Created Aug. 25, 2017, 6:12 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 | « include/AdblockPlus/Notification.h ('k') | include/AdblockPlus/ReferrerMapping.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/Platform.h
diff --git a/include/AdblockPlus/Platform.h b/include/AdblockPlus/Platform.h
new file mode 100644
index 0000000000000000000000000000000000000000..c95204350c3af72af0eee70970636fcbd0101693
--- /dev/null
+++ b/include/AdblockPlus/Platform.h
@@ -0,0 +1,159 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ADBLOCK_PLUS_PLATFORM_H
+#define ADBLOCK_PLUS_PLATFORM_H
+
+#include "LogSystem.h"
+#include "ITimer.h"
+#include "IFileSystem.h"
+#include "IWebRequest.h"
+#include "AppInfo.h"
+#include "Scheduler.h"
+#include "FilterEngine.h"
+#include <mutex>
+#include <future>
+
+namespace AdblockPlus
+{
+ /**
+ * A factory to construct DefaultTimer.
+ */
+ TimerPtr CreateDefaultTimer();
+
+ /**
+ * A factory to construct DefaultFileSystem.
+ */
+ FileSystemPtr CreateDefaultFileSystem(const Scheduler& scheduler);
+
+ /**
+ * A factory to construct DefaultWebRequest.
+ */
+ WebRequestPtr CreateDefaultWebRequest(const Scheduler& scheduler);
+
+ /**
+ * A factory to construct LogSystem.
+ */
+ LogSystemPtr CreateDefaultLogSystem();
+
+ class JsEngine;
+
+ /**
+ * AdblockPlus platform is the main component providing access to other
+ * modules.
+ *
+ * It manages the functionality modules, e.g. JsEngine and FilterEngine as
+ * well as allows to correctly work with asynchronous functionality.
+ */
+ class Platform
+ {
+ public:
+ /**
+ * Platform creation parameters.
+ *
+ * @param logSystem Implementation of log system.
+ * @param timer Implementation of timer.
+ * @param webRequest Implementation of web request.
+ * @param fileSystem Implementation of filesystem.
+ */
+ struct CreationParameters
+ {
+ LogSystemPtr logSystem;
+ TimerPtr timer;
+ WebRequestPtr webRequest;
+ FileSystemPtr fileSystem;
+ };
+
+ /**
+ * Callback type invoked when FilterEngine is created.
+ */
+ typedef std::function<void(const FilterEngine&)> OnFilterEngineCreatedCallback;
+
+ /**
+ * Platform constructor.
+ *
+ * When a parameter value is nullptr the corresponding default
+ * implementation is chosen.
+ */
+ explicit Platform(CreationParameters&& creationParameters = CreationParameters());
+ ~Platform();
+
+ /**
+ * Ensures that JsEngine is constructed.
+ *
+ * @param appInfo Information about the app, if jsEngine is already present
+ * then the value is ignored.
+ */
+ void SetUpJsEngine(const AppInfo& appInfo = AppInfo());
+
+ /**
+ * Retrieves the `JsEngine` instance. It calls SetUpJsEngine if JsEngine is
+ * not initialized yet.
+ */
+ JsEngine& GetJsEngine();
+
+ /**
+ * Ensures that FilterEngine is constructed. Only the first call is effective.
+ *
+ * @param parameters optional creation parameters.
+ * @param onCreated A callback which is called when FilterEngine is ready
+ * for use.
+ */
+ void CreateFilterEngineAsync(const FilterEngine::CreationParameters& parameters = FilterEngine::CreationParameters(),
+ const OnFilterEngineCreatedCallback& onCreated = OnFilterEngineCreatedCallback());
+
+ /**
+ * Synchronous equivalent of `CreateFilterEngineAsync`.
+ * Internally it blocks and waits for finishing of certain asynchronous
+ * operations, please ensure that provided implementation does not lead to
+ * a dead lock.
+ */
+ FilterEngine& GetFilterEngine();
+
+ /**
+ * @return The asynchronous ITimer implementation.
+ */
+ ITimer& GetTimer();
+
+ /**
+ * @return The asynchronous IFileSystem implementation.
+ */
+ IFileSystem& GetFileSystem();
+
+ /**
+ * @return The asynchronous IWebRequest implementation.
+ */
+ IWebRequest& GetWebRequest();
+
+ /**
+ * @see `SetLogSystem()`.
+ */
+ LogSystem& GetLogSystem();
+
+ private:
+ LogSystemPtr logSystem;
+ TimerPtr timer;
+ FileSystemPtr fileSystem;
+ WebRequestPtr webRequest;
+ // used for creation and deletion of modules.
+ std::mutex modulesMutex;
+ std::shared_ptr<JsEngine> jsEngine;
+ std::shared_future<FilterEnginePtr> filterEngine;
+ };
+}
+
+#endif // ADBLOCK_PLUS_PLATFORM_H
« no previous file with comments | « include/AdblockPlus/Notification.h ('k') | include/AdblockPlus/ReferrerMapping.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld