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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 void Platform::SetUpJsEngine(const AppInfo& appInfo) | 67 void Platform::SetUpJsEngine(const AppInfo& appInfo) |
68 { | 68 { |
69 std::lock_guard<std::mutex> lock(modulesMutex); | 69 std::lock_guard<std::mutex> lock(modulesMutex); |
70 if (jsEngine) | 70 if (jsEngine) |
71 return; | 71 return; |
72 jsEngine = JsEngine::New(appInfo, *this); | 72 jsEngine = JsEngine::New(appInfo, *this); |
73 } | 73 } |
74 | 74 |
75 std::shared_ptr<JsEngine> Platform::GetJsEngine() | 75 JsEngine& Platform::GetJsEngine() |
76 { | 76 { |
77 SetUpJsEngine(); | 77 SetUpJsEngine(); |
78 return jsEngine; | 78 return *jsEngine; |
79 } | 79 } |
80 | 80 |
81 void Platform::CreateFilterEngineAsync(const FilterEngine::CreationParameters& p
arameters, | 81 void Platform::CreateFilterEngineAsync(const FilterEngine::CreationParameters& p
arameters, |
82 const OnFilterEngineCreatedCallback& onCreated) | 82 const OnFilterEngineCreatedCallback& onCreated) |
83 { | 83 { |
84 std::shared_ptr<std::promise<FilterEnginePtr>> filterEnginePromise; | 84 std::shared_ptr<std::promise<FilterEnginePtr>> filterEnginePromise; |
85 { | 85 { |
86 std::lock_guard<std::mutex> lock(modulesMutex); | 86 std::lock_guard<std::mutex> lock(modulesMutex); |
87 if (filterEngine.valid()) | 87 if (filterEngine.valid()) |
88 return; | 88 return; |
89 filterEnginePromise = std::make_shared<std::promise<FilterEnginePtr>>(); | 89 filterEnginePromise = std::make_shared<std::promise<FilterEnginePtr>>(); |
90 filterEngine = filterEnginePromise->get_future(); | 90 filterEngine = filterEnginePromise->get_future(); |
91 } | 91 } |
92 | 92 |
93 FilterEngine::CreateAsync(GetJsEngine(), [this, onCreated, filterEnginePromise
](const FilterEnginePtr& filterEngine) | 93 GetJsEngine(); // ensures that JsEngine is instantiated |
| 94 FilterEngine::CreateAsync(jsEngine, [this, onCreated, filterEnginePromise](con
st FilterEnginePtr& filterEngine) |
94 { | 95 { |
95 filterEnginePromise->set_value(filterEngine); | 96 filterEnginePromise->set_value(filterEngine); |
96 if (onCreated) | 97 if (onCreated) |
97 onCreated(filterEngine); | 98 onCreated(filterEngine); |
98 }, parameters); | 99 }, parameters); |
99 } | 100 } |
100 | 101 |
101 FilterEnginePtr Platform::GetFilterEngine() | 102 FilterEnginePtr Platform::GetFilterEngine() |
102 { | 103 { |
103 CreateFilterEngineAsync(); | 104 CreateFilterEngineAsync(); |
(...skipping 12 matching lines...) Expand all Loading... |
116 | 117 |
117 IWebRequest& Platform::GetWebRequest() | 118 IWebRequest& Platform::GetWebRequest() |
118 { | 119 { |
119 return *webRequest; | 120 return *webRequest; |
120 } | 121 } |
121 | 122 |
122 LogSystem& Platform::GetLogSystem() | 123 LogSystem& Platform::GetLogSystem() |
123 { | 124 { |
124 return *logSystem; | 125 return *logSystem; |
125 } | 126 } |
OLD | NEW |