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

Side by Side 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.
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 | « include/AdblockPlus/Notification.h ('k') | include/AdblockPlus/ReferrerMapping.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef ADBLOCK_PLUS_PLATFORM_H
19 #define ADBLOCK_PLUS_PLATFORM_H
20
21 #include "LogSystem.h"
22 #include "ITimer.h"
23 #include "IFileSystem.h"
24 #include "IWebRequest.h"
25 #include "AppInfo.h"
26 #include "Scheduler.h"
27 #include "FilterEngine.h"
28 #include <mutex>
29 #include <future>
30
31 namespace AdblockPlus
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);
42
43 /**
44 * A factory to construct DefaultWebRequest.
45 */
46 WebRequestPtr CreateDefaultWebRequest(const Scheduler& scheduler);
47
48 /**
49 * A factory to construct LogSystem.
50 */
51 LogSystemPtr CreateDefaultLogSystem();
52
53 class JsEngine;
54
55 /**
56 * AdblockPlus platform is the main component providing access to other
57 * modules.
58 *
59 * It manages the functionality modules, e.g. JsEngine and FilterEngine as
60 * well as allows to correctly work with asynchronous functionality.
61 */
62 class Platform
63 {
64 public:
65 /**
66 * Platform creation parameters.
67 *
68 * @param logSystem Implementation of log system.
69 * @param timer Implementation of timer.
70 * @param webRequest Implementation of web request.
71 * @param fileSystem Implementation of filesystem.
72 */
73 struct CreationParameters
74 {
75 LogSystemPtr logSystem;
76 TimerPtr timer;
77 WebRequestPtr webRequest;
78 FileSystemPtr fileSystem;
79 };
80
81 /**
82 * Callback type invoked when FilterEngine is created.
83 */
84 typedef std::function<void(const FilterEngine&)> OnFilterEngineCreatedCallba ck;
85
86 /**
87 * Platform constructor.
88 *
89 * When a parameter value is nullptr the corresponding default
90 * implementation is chosen.
91 */
92 explicit Platform(CreationParameters&& creationParameters = CreationParamete rs());
93 ~Platform();
94
95 /**
96 * Ensures that JsEngine is constructed.
97 *
98 * @param appInfo Information about the app, if jsEngine is already present
99 * then the value is ignored.
100 */
101 void SetUpJsEngine(const AppInfo& appInfo = AppInfo());
102
103 /**
104 * Retrieves the `JsEngine` instance. It calls SetUpJsEngine if JsEngine is
105 * not initialized yet.
106 */
107 JsEngine& GetJsEngine();
108
109 /**
110 * Ensures that FilterEngine is constructed. Only the first call is effectiv e.
111 *
112 * @param parameters optional creation parameters.
113 * @param onCreated A callback which is called when FilterEngine is ready
114 * for use.
115 */
116 void CreateFilterEngineAsync(const FilterEngine::CreationParameters& paramet ers = FilterEngine::CreationParameters(),
117 const OnFilterEngineCreatedCallback& onCreated = OnFilterEngineCreatedCall back());
118
119 /**
120 * Synchronous equivalent of `CreateFilterEngineAsync`.
121 * Internally it blocks and waits for finishing of certain asynchronous
122 * operations, please ensure that provided implementation does not lead to
123 * a dead lock.
124 */
125 FilterEngine& GetFilterEngine();
126
127 /**
128 * @return The asynchronous ITimer implementation.
129 */
130 ITimer& GetTimer();
131
132 /**
133 * @return The asynchronous IFileSystem implementation.
134 */
135 IFileSystem& GetFileSystem();
136
137 /**
138 * @return The asynchronous IWebRequest implementation.
139 */
140 IWebRequest& GetWebRequest();
141
142 /**
143 * @see `SetLogSystem()`.
144 */
145 LogSystem& GetLogSystem();
146
147 private:
148 LogSystemPtr logSystem;
149 TimerPtr timer;
150 FileSystemPtr fileSystem;
151 WebRequestPtr webRequest;
152 // used for creation and deletion of modules.
153 std::mutex modulesMutex;
154 std::shared_ptr<JsEngine> jsEngine;
155 std::shared_future<FilterEnginePtr> filterEngine;
156 };
157 }
158
159 #endif // ADBLOCK_PLUS_PLATFORM_H
OLDNEW
« 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