OLD | NEW |
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(); |
55 } | 60 } |
56 | 61 |
57 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP
rovider> isolate) | 62 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP
rovider> isolate) |
58 { | 63 { |
59 std::lock_guard<std::mutex> lock(modulesMutex); | 64 std::lock_guard<std::mutex> lock(modulesMutex); |
60 if (jsEngine) | 65 if (jsEngine) |
61 return; | 66 return; |
62 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); | 67 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); |
63 } | 68 } |
64 | 69 |
(...skipping 23 matching lines...) Expand all Loading... |
88 onCreated(*filterEngine); | 93 onCreated(*filterEngine); |
89 }, parameters); | 94 }, parameters); |
90 } | 95 } |
91 | 96 |
92 FilterEngine& Platform::GetFilterEngine() | 97 FilterEngine& Platform::GetFilterEngine() |
93 { | 98 { |
94 CreateFilterEngineAsync(); | 99 CreateFilterEngineAsync(); |
95 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); | 100 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); |
96 } | 101 } |
97 | 102 |
98 ITimer& Platform::GetTimer() | 103 void Platform::WithTimer(const WithTimerCallback& callback) |
99 { | 104 { |
100 return *timer; | 105 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 106 if (timer && callback) |
| 107 callback(*timer); |
101 } | 108 } |
102 | 109 |
103 IFileSystem& Platform::GetFileSystem() | 110 void Platform::WithFileSystem(const WithFileSystemCallback& callback) |
104 { | 111 { |
105 return *fileSystem; | 112 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 113 if (fileSystem && callback) |
| 114 callback(*fileSystem); |
106 } | 115 } |
107 | 116 |
108 IWebRequest& Platform::GetWebRequest() | 117 void Platform::WithWebRequest(const WithWebRequestCallback& callback) |
109 { | 118 { |
110 return *webRequest; | 119 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
| 120 if (webRequest && callback) |
| 121 callback(*webRequest); |
111 } | 122 } |
112 | 123 |
113 LogSystem& Platform::GetLogSystem() | 124 LogSystem& Platform::GetLogSystem() |
114 { | 125 { |
115 return *logSystem; | 126 return *logSystem; |
116 } | 127 } |
117 | 128 |
118 namespace | 129 namespace |
119 { | 130 { |
120 class DefaultPlatform : public Platform | 131 class DefaultPlatform : public Platform |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (!timer) | 191 if (!timer) |
181 CreateDefaultTimer(); | 192 CreateDefaultTimer(); |
182 if (!fileSystem) | 193 if (!fileSystem) |
183 CreateDefaultFileSystem(); | 194 CreateDefaultFileSystem(); |
184 if (!webRequest) | 195 if (!webRequest) |
185 CreateDefaultWebRequest(); | 196 CreateDefaultWebRequest(); |
186 | 197 |
187 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov
e(*this))); | 198 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov
e(*this))); |
188 asyncExecutor.reset(); | 199 asyncExecutor.reset(); |
189 return platform; | 200 return platform; |
190 } | 201 } |
OLD | NEW |