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

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

Issue 29393573: Issue 4692 - Dont' keep a strong reference from timer thread (Closed)
Patch Set: Created March 23, 2017, 5:24 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 | « no previous file | src/GlobalJsObject.cpp » ('j') | src/GlobalJsObject.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef ADBLOCK_PLUS_JS_ENGINE_H 18 #ifndef ADBLOCK_PLUS_JS_ENGINE_H
19 #define ADBLOCK_PLUS_JS_ENGINE_H 19 #define ADBLOCK_PLUS_JS_ENGINE_H
20 20
21 #include <functional> 21 #include <functional>
22 #include <map> 22 #include <map>
23 #include <list>
23 #include <stdexcept> 24 #include <stdexcept>
24 #include <stdint.h> 25 #include <stdint.h>
25 #include <string> 26 #include <string>
26 #include <mutex> 27 #include <mutex>
27 #include <AdblockPlus/AppInfo.h> 28 #include <AdblockPlus/AppInfo.h>
28 #include <AdblockPlus/LogSystem.h> 29 #include <AdblockPlus/LogSystem.h>
29 #include <AdblockPlus/FileSystem.h> 30 #include <AdblockPlus/FileSystem.h>
30 #include <AdblockPlus/JsValue.h> 31 #include <AdblockPlus/JsValue.h>
31 #include <AdblockPlus/WebRequest.h> 32 #include <AdblockPlus/WebRequest.h>
32 33
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 */ 75 */
75 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; 76 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
76 77
77 /** 78 /**
78 * JavaScript engine used by `FilterEngine`, wraps v8. 79 * JavaScript engine used by `FilterEngine`, wraps v8.
79 */ 80 */
80 class JsEngine : public std::enable_shared_from_this<JsEngine> 81 class JsEngine : public std::enable_shared_from_this<JsEngine>
81 { 82 {
82 friend class JsValue; 83 friend class JsValue;
83 friend class JsContext; 84 friend class JsContext;
84
Oleksandr 2017/03/24 12:15:25 Nit: I'm sure you can guess :). Unrelated?
sergei 2017/03/24 12:34:39 Done.
85 public: 85 public:
86 /** 86 /**
87 * Event callback function. 87 * Event callback function.
88 */ 88 */
89 typedef std::function<void(JsValueList& params)> EventCallback; 89 typedef std::function<void(JsValueList& params)> EventCallback;
90 90
91 /** 91 /**
92 * Callback function returning false when current connection is not allowed 92 * Callback function returning false when current connection is not allowed
93 * e.g. because it is a metered connection. 93 * e.g. because it is a metered connection.
94 */ 94 */
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr valu e); 263 void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr valu e);
264 264
265 /** 265 /**
266 * Returns a pointer to associated v8::Isolate. 266 * Returns a pointer to associated v8::Isolate.
267 */ 267 */
268 v8::Isolate* GetIsolate() 268 v8::Isolate* GetIsolate()
269 { 269 {
270 return isolate->Get(); 270 return isolate->Get();
271 } 271 }
272 272
273 // Private functionality required to implement timers.
274 struct TimerTaskInfo
275 {
276 ~TimerTaskInfo();
277 int delay;
278 std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> arguments;
sergei 2017/03/23 17:27:13 We need std::unique_ptr here because v8::Persisten
279 };
280 typedef std::list<TimerTaskInfo> TimerTaskInfos;
281 struct TimerTask
282 {
283 std::weak_ptr<JsEngine> weakJsEngine;
284 TimerTaskInfos::const_iterator ii_taskInfo;
Oleksandr 2017/03/24 12:15:25 Nit: It is not immediately clear to me what ii_ st
sergei 2017/03/24 12:34:39 Done.
285 };
286 TimerTask CreateTimerTask(const v8::Arguments& arguments);
287 void CallTimerTask(TimerTaskInfos::const_iterator ii_taskInfo);
273 private: 288 private:
274 explicit JsEngine(const ScopedV8IsolatePtr& isolate); 289 explicit JsEngine(const ScopedV8IsolatePtr& isolate);
275 290
276 JsValuePtr GetGlobalObject(); 291 JsValuePtr GetGlobalObject();
277 292
278 /// Isolate must be disposed only after disposing of all objects which are 293 /// Isolate must be disposed only after disposing of all objects which are
279 /// using it. 294 /// using it.
280 ScopedV8IsolatePtr isolate; 295 ScopedV8IsolatePtr isolate;
281 296
282 FileSystemPtr fileSystem; 297 FileSystemPtr fileSystem;
283 WebRequestPtr webRequest; 298 WebRequestPtr webRequest;
284 LogSystemPtr logSystem; 299 LogSystemPtr logSystem;
285 std::unique_ptr<v8::Persistent<v8::Context>> context; 300 std::unique_ptr<v8::Persistent<v8::Context>> context;
286 EventMap eventCallbacks; 301 EventMap eventCallbacks;
287 std::mutex eventCallbacksMutex; 302 std::mutex eventCallbacksMutex;
288 std::mutex isConnectionAllowedMutex; 303 std::mutex isConnectionAllowedMutex;
289 IsConnectionAllowedCallback isConnectionAllowed; 304 IsConnectionAllowedCallback isConnectionAllowed;
305 TimerTaskInfos timerTaskInfos;
290 }; 306 };
291 } 307 }
292 308
293 #endif 309 #endif
OLDNEW
« no previous file with comments | « no previous file | src/GlobalJsObject.cpp » ('j') | src/GlobalJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld