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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 Platform::Platform(CreationParameters&& creationParameters) | 45 Platform::Platform(CreationParameters&& creationParameters) |
46 { | 46 { |
47 ASSIGN_PLATFORM_PARAM(logSystem); | 47 ASSIGN_PLATFORM_PARAM(logSystem); |
48 ASSIGN_PLATFORM_PARAM(timer); | 48 ASSIGN_PLATFORM_PARAM(timer); |
49 ASSIGN_PLATFORM_PARAM(fileSystem); | 49 ASSIGN_PLATFORM_PARAM(fileSystem); |
50 ASSIGN_PLATFORM_PARAM(webRequest); | 50 ASSIGN_PLATFORM_PARAM(webRequest); |
51 } | 51 } |
52 | 52 |
53 Platform::~Platform() | 53 Platform::~Platform() |
54 { | 54 { |
55 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
56 logSystem.reset(); | |
57 timer.reset(); | |
58 fileSystem.reset(); | |
59 webRequest.reset(); | |
60 } | 55 } |
61 | 56 |
62 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP
rovider> isolate) | 57 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP
rovider> isolate) |
63 { | 58 { |
64 std::lock_guard<std::mutex> lock(modulesMutex); | 59 std::lock_guard<std::mutex> lock(modulesMutex); |
65 if (jsEngine) | 60 if (jsEngine) |
66 return; | 61 return; |
67 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); | 62 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); |
68 } | 63 } |
69 | 64 |
(...skipping 25 matching lines...) Expand all Loading... |
95 } | 90 } |
96 | 91 |
97 FilterEngine& Platform::GetFilterEngine() | 92 FilterEngine& Platform::GetFilterEngine() |
98 { | 93 { |
99 CreateFilterEngineAsync(); | 94 CreateFilterEngineAsync(); |
100 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); | 95 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); |
101 } | 96 } |
102 | 97 |
103 void Platform::WithTimer(const WithTimerCallback& callback) | 98 void Platform::WithTimer(const WithTimerCallback& callback) |
104 { | 99 { |
105 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
106 if (timer && callback) | 100 if (timer && callback) |
107 callback(*timer); | 101 callback(*timer); |
108 } | 102 } |
109 | 103 |
110 void Platform::WithFileSystem(const WithFileSystemCallback& callback) | 104 void Platform::WithFileSystem(const WithFileSystemCallback& callback) |
111 { | 105 { |
112 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
113 if (fileSystem && callback) | 106 if (fileSystem && callback) |
114 callback(*fileSystem); | 107 callback(*fileSystem); |
115 } | 108 } |
116 | 109 |
117 void Platform::WithWebRequest(const WithWebRequestCallback& callback) | 110 void Platform::WithWebRequest(const WithWebRequestCallback& callback) |
118 { | 111 { |
119 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
120 if (webRequest && callback) | 112 if (webRequest && callback) |
121 callback(*webRequest); | 113 callback(*webRequest); |
122 } | 114 } |
123 | 115 |
124 LogSystem& Platform::GetLogSystem() | 116 void Platform::WithLogSystem(const WithLogSystemCallback& callback) |
125 { | 117 { |
126 return *logSystem; | 118 if (logSystem && callback) |
| 119 callback(*logSystem); |
127 } | 120 } |
128 | 121 |
129 namespace | 122 namespace |
130 { | 123 { |
131 class DefaultPlatform : public Platform | 124 class DefaultPlatform : public Platform |
132 { | 125 { |
133 public: | 126 public: |
134 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; | 127 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; |
135 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara
meters&& creationParams) | 128 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara
meters&& creationParams) |
136 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) | 129 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) |
137 { | 130 { |
138 } | 131 } |
139 ~DefaultPlatform() | 132 ~DefaultPlatform(); |
140 { | 133 |
141 asyncExecutor.reset(); | 134 void WithTimer(const WithTimerCallback&) override; |
142 } | 135 void WithFileSystem(const WithFileSystemCallback&) override; |
| 136 void WithWebRequest(const WithWebRequestCallback&) override; |
| 137 void WithLogSystem(const WithLogSystemCallback&) override; |
| 138 |
143 private: | 139 private: |
144 AsyncExecutorPtr asyncExecutor; | 140 AsyncExecutorPtr asyncExecutor; |
| 141 std::recursive_mutex interfacesMutex; |
145 }; | 142 }; |
| 143 |
| 144 DefaultPlatform::~DefaultPlatform() |
| 145 { |
| 146 asyncExecutor.reset(); |
| 147 LogSystemPtr tmpLogSystem; |
| 148 TimerPtr tmpTimer; |
| 149 FileSystemPtr tmpFileSystem; |
| 150 WebRequestPtr tmpWebRequest; |
| 151 { |
| 152 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 153 tmpLogSystem = std::move(logSystem); |
| 154 tmpTimer = std::move(timer); |
| 155 tmpFileSystem = std::move(fileSystem); |
| 156 tmpWebRequest = std::move(webRequest); |
| 157 } |
| 158 } |
| 159 |
| 160 void DefaultPlatform::WithTimer(const WithTimerCallback& callback) |
| 161 { |
| 162 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 163 Platform::WithTimer(callback); |
| 164 } |
| 165 |
| 166 void DefaultPlatform::WithFileSystem(const WithFileSystemCallback& callback) |
| 167 { |
| 168 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 169 Platform::WithFileSystem(callback); |
| 170 } |
| 171 |
| 172 void DefaultPlatform::WithWebRequest(const WithWebRequestCallback& callback) |
| 173 { |
| 174 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 175 Platform::WithWebRequest(callback); |
| 176 } |
| 177 |
| 178 void DefaultPlatform::WithLogSystem(const WithLogSystemCallback& callback) |
| 179 { |
| 180 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 181 Platform::WithLogSystem(callback); |
| 182 } |
146 } | 183 } |
147 | 184 |
148 Scheduler DefaultPlatformBuilder::GetDefaultAsyncExecutor() | 185 Scheduler DefaultPlatformBuilder::GetDefaultAsyncExecutor() |
149 { | 186 { |
150 if (!defaultScheduler) | 187 if (!defaultScheduler) |
151 { | 188 { |
152 asyncExecutor = std::make_shared<Scheduler>(::DummyScheduler); | 189 asyncExecutor = std::make_shared<Scheduler>(::DummyScheduler); |
153 std::weak_ptr<Scheduler> weakExecutor = asyncExecutor; | 190 std::weak_ptr<Scheduler> weakExecutor = asyncExecutor; |
154 defaultScheduler = [weakExecutor](const SchedulerTask& task) | 191 defaultScheduler = [weakExecutor](const SchedulerTask& task) |
155 { | 192 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 CreateDefaultTimer(); | 229 CreateDefaultTimer(); |
193 if (!fileSystem) | 230 if (!fileSystem) |
194 CreateDefaultFileSystem(); | 231 CreateDefaultFileSystem(); |
195 if (!webRequest) | 232 if (!webRequest) |
196 CreateDefaultWebRequest(); | 233 CreateDefaultWebRequest(); |
197 | 234 |
198 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov
e(*this))); | 235 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov
e(*this))); |
199 asyncExecutor.reset(); | 236 asyncExecutor.reset(); |
200 return platform; | 237 return platform; |
201 } | 238 } |
LEFT | RIGHT |