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

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

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 28, 2017, 12:40 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
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 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 <mutex>
28
29 namespace AdblockPlus
30 {
31 /**
32 * A factory to construct DefaultTimer.
33 */
34 TimerPtr CreateDefaultTimer();
35
36 /**
37 * A factory to construct DefaultFileSystem.
38 */
39 FileSystemPtr CreateDefaultFileSystem(const Scheduler& scheduler);
40
41 /**
42 * A factory to construct DefaultWebRequest.
43 */
44 WebRequestPtr CreateDefaultWebRequest(const Scheduler& scheduler);
45
46 /**
47 * A factory to construct LogSystem.
48 */
49 LogSystemPtr CreateDefaultLogSystem();
50
51 class JsEngine;
52
53 /**
54 * AdblockPlus platform is the main component providing access to other
55 * modules.
56 *
57 * It manages the functionality modules, e.g. JsEngine and FilterEngine as
58 * well as allows to correctly work with asynchronous functionality.
59 */
60 class Platform
61 {
62 public:
63 /**
64 * Platform creation parameters.
65 *
66 * @param logSystem Implementation of log system.
67 * @param timer Implementation of timer.
68 * @param webRequest Implementation of web request.
69 * @param fileSystem Implementation of filesystem.
70 */
71 struct CreationParameters
72 {
73 LogSystemPtr logSystem;
74 TimerPtr timer;
75 WebRequestPtr webRequest;
76 FileSystemPtr fileSystem;
77 };
78
79 /**
80 * Platform constructor.
81 *
82 * When a parameter value is nullptr the corresponding default
83 * implementation is chosen.
84 */
85 explicit Platform(CreationParameters&& creationParameters = CreationParamete rs());
86 ~Platform();
87
88 /**
89 * Ensures that JsEngine is constructed.
90 *
91 * @param appInfo Information about the app, if jsEngine is already present
92 * then the value is ignored.
93 */
94 void SetUpJsEngine(const AppInfo& appInfo = AppInfo());
95
96 /**
97 * Retrieves the `JsEngine` instance. It calls SetUpJsEngine if JsEngine is
98 * not initialized yet.
99 */
100 std::shared_ptr<JsEngine> GetJsEngine();
101
102 /**
103 * @return The asynchronous ITimer implementation.
104 */
105 ITimer& GetTimer();
106
107 /**
108 * @return The asynchronous IFileSystem implementation.
109 */
110 IFileSystem& GetFileSystem();
111
112 /**
113 * @return The asynchronous IWebRequest implementation.
114 */
115 IWebRequest& GetWebRequest();
116
117 /**
118 * @see `SetLogSystem()`.
119 */
120 LogSystem& GetLogSystem();
121
122 private:
123 LogSystemPtr logSystem;
124 TimerPtr timer;
125 FileSystemPtr fileSystem;
126 WebRequestPtr webRequest;
127 // used for creation and deletion of modules.
128 std::mutex modulesMutex;
129 std::shared_ptr<JsEngine> jsEngine;
130 };
131 }
132
133 #endif // ADBLOCK_PLUS_PLATFORM_H
OLDNEW

Powered by Google App Engine
This is Rietveld