LEFT | RIGHT |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 12 matching lines...) Expand all Loading... |
23 #include "IFileSystem.h" | 23 #include "IFileSystem.h" |
24 #include "IWebRequest.h" | 24 #include "IWebRequest.h" |
25 #include "AppInfo.h" | 25 #include "AppInfo.h" |
26 #include "Scheduler.h" | 26 #include "Scheduler.h" |
27 #include "FilterEngine.h" | 27 #include "FilterEngine.h" |
28 #include <mutex> | 28 #include <mutex> |
29 #include <future> | 29 #include <future> |
30 | 30 |
31 namespace AdblockPlus | 31 namespace AdblockPlus |
32 { | 32 { |
33 /** | |
34 * A factory to construct DefaultTimer. | |
35 */ | |
36 TimerPtr CreateDefaultTimer(); | |
37 | |
38 /** | |
39 * A factory to construct DefaultFileSystem. | |
40 */ | |
41 FileSystemPtr CreateDefaultFileSystem(const Scheduler& scheduler, const std::s
tring& basePath = std::string()); | |
42 | |
43 /** | |
44 * A factory to construct DefaultWebRequest. | |
45 */ | |
46 WebRequestPtr CreateDefaultWebRequest(const Scheduler& scheduler, WebRequestSy
ncPtr syncImpl = nullptr); | |
47 | |
48 /** | |
49 * A factory to construct LogSystem. | |
50 */ | |
51 LogSystemPtr CreateDefaultLogSystem(); | |
52 | |
53 struct IV8IsolateProvider; | 33 struct IV8IsolateProvider; |
54 class JsEngine; | 34 class JsEngine; |
55 | 35 |
56 /** | 36 /** |
57 * AdblockPlus platform is the main component providing access to other | 37 * AdblockPlus platform is the main component providing access to other |
58 * modules. | 38 * modules. |
59 * | 39 * |
60 * It manages the functionality modules, e.g. JsEngine and FilterEngine as | 40 * It manages the functionality modules, e.g. JsEngine and FilterEngine as |
61 * well as allows to correctly work with asynchronous functionality. | 41 * well as allows to correctly work with asynchronous functionality. |
62 */ | 42 */ |
63 class Platform | 43 class Platform |
(...skipping 20 matching lines...) Expand all Loading... |
84 */ | 64 */ |
85 typedef std::function<void(const FilterEngine&)> OnFilterEngineCreatedCallba
ck; | 65 typedef std::function<void(const FilterEngine&)> OnFilterEngineCreatedCallba
ck; |
86 | 66 |
87 /** | 67 /** |
88 * Platform constructor. | 68 * Platform constructor. |
89 * | 69 * |
90 * When a parameter value is nullptr the corresponding default | 70 * When a parameter value is nullptr the corresponding default |
91 * implementation is chosen. | 71 * implementation is chosen. |
92 */ | 72 */ |
93 explicit Platform(CreationParameters&& creationParameters = CreationParamete
rs()); | 73 explicit Platform(CreationParameters&& creationParameters = CreationParamete
rs()); |
94 ~Platform(); | 74 virtual ~Platform(); |
95 | 75 |
96 /** | 76 /** |
97 * Ensures that JsEngine is constructed. If JsEngine is already present | 77 * Ensures that JsEngine is constructed. If JsEngine is already present |
98 * then the parameters are ignored. | 78 * then the parameters are ignored. |
99 * | 79 * |
100 * @param appInfo Information about the app, | 80 * @param appInfo Information about the app, |
101 * @param isolate A provider of v8::Isolate, if the value is nullptr then | 81 * @param isolate A provider of v8::Isolate, if the value is nullptr then |
102 * a default implementation is used. | 82 * a default implementation is used. |
103 */ | 83 */ |
104 void SetUpJsEngine(const AppInfo& appInfo = AppInfo(), std::unique_ptr<IV8Is
olateProvider> isolate = nullptr); | 84 void SetUpJsEngine(const AppInfo& appInfo = AppInfo(), std::unique_ptr<IV8Is
olateProvider> isolate = nullptr); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 private: | 130 private: |
151 LogSystemPtr logSystem; | 131 LogSystemPtr logSystem; |
152 TimerPtr timer; | 132 TimerPtr timer; |
153 FileSystemPtr fileSystem; | 133 FileSystemPtr fileSystem; |
154 WebRequestPtr webRequest; | 134 WebRequestPtr webRequest; |
155 // used for creation and deletion of modules. | 135 // used for creation and deletion of modules. |
156 std::mutex modulesMutex; | 136 std::mutex modulesMutex; |
157 std::shared_ptr<JsEngine> jsEngine; | 137 std::shared_ptr<JsEngine> jsEngine; |
158 std::shared_future<FilterEnginePtr> filterEngine; | 138 std::shared_future<FilterEnginePtr> filterEngine; |
159 }; | 139 }; |
| 140 |
| 141 /** |
| 142 * A helper class allowing to construct a default Platform and to obtain |
| 143 * the Scheduler used by Platform before the latter is constructed. |
| 144 */ |
| 145 class DefaultPlatformBuilder : public Platform::CreationParameters |
| 146 { |
| 147 public: |
| 148 /** |
| 149 * Constructs a default executor for asynchronous tasks. When Platform |
| 150 * is being destroyed it starts to ignore new tasks and waits for finishing |
| 151 * of already running tasks. |
| 152 * @return Scheduler allowing to execute tasks asynchronously. |
| 153 */ |
| 154 Scheduler GetDefaultAsyncExecutor(); |
| 155 |
| 156 /** |
| 157 * Constructs default implementation of `ITimer`. |
| 158 */ |
| 159 void CreateDefaultTimer(); |
| 160 |
| 161 /** |
| 162 * Constructs default implementation of `IFileSystem`. |
| 163 * @param basePath A working directory for file system operations. |
| 164 */ |
| 165 void CreateDefaultFileSystem(const std::string& basePath = std::string()); |
| 166 |
| 167 /** |
| 168 * Constructs default implementation of `IWebRequest`. |
| 169 */ |
| 170 void CreateDefaultWebRequest(WebRequestSyncPtr webRequest = nullptr); |
| 171 |
| 172 /** |
| 173 * Constructs default implementation of `LogSystem`. |
| 174 */ |
| 175 void CreateDefaultLogSystem(); |
| 176 |
| 177 /** |
| 178 * Constructs Platform with default implementations of platform interfaces |
| 179 * when a corresponding field is nullptr and with a default Scheduler. |
| 180 */ |
| 181 std::unique_ptr<Platform> CreatePlatform(); |
| 182 private: |
| 183 std::shared_ptr<Scheduler> asyncExecutor; |
| 184 Scheduler defaultScheduler; |
| 185 }; |
160 } | 186 } |
161 | 187 |
162 #endif // ADBLOCK_PLUS_PLATFORM_H | 188 #endif // ADBLOCK_PLUS_PLATFORM_H |
LEFT | RIGHT |