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

Delta Between Two Patch Sets: include/AdblockPlus/JsEngine.h

Issue 29393573: Issue 4692 - Dont' keep a strong reference from timer thread (Closed)
Left Patch Set: Created March 23, 2017, 5:24 p.m.
Right Patch Set: address comments Created March 24, 2017, 12:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/GlobalJsObject.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 */ 75 */
76 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; 76 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
77 77
78 /** 78 /**
79 * JavaScript engine used by `FilterEngine`, wraps v8. 79 * JavaScript engine used by `FilterEngine`, wraps v8.
80 */ 80 */
81 class JsEngine : public std::enable_shared_from_this<JsEngine> 81 class JsEngine : public std::enable_shared_from_this<JsEngine>
82 { 82 {
83 friend class JsValue; 83 friend class JsValue;
84 friend class JsContext; 84 friend class JsContext;
85
85 public: 86 public:
86 /** 87 /**
87 * Event callback function. 88 * Event callback function.
88 */ 89 */
89 typedef std::function<void(JsValueList& params)> EventCallback; 90 typedef std::function<void(JsValueList& params)> EventCallback;
90 91
91 /** 92 /**
92 * Callback function returning false when current connection is not allowed 93 * Callback function returning false when current connection is not allowed
93 * e.g. because it is a metered connection. 94 * e.g. because it is a metered connection.
94 */ 95 */
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 v8::Isolate* GetIsolate() 269 v8::Isolate* GetIsolate()
269 { 270 {
270 return isolate->Get(); 271 return isolate->Get();
271 } 272 }
272 273
273 // Private functionality required to implement timers. 274 // Private functionality required to implement timers.
274 struct TimerTaskInfo 275 struct TimerTaskInfo
275 { 276 {
276 ~TimerTaskInfo(); 277 ~TimerTaskInfo();
277 int delay; 278 int delay;
278 std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> arguments; 279 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 };
280 typedef std::list<TimerTaskInfo> TimerTaskInfos; 281 typedef std::list<TimerTaskInfo> TimerTaskInfos;
281 struct TimerTask 282 struct TimerTask
282 { 283 {
283 std::weak_ptr<JsEngine> weakJsEngine; 284 std::weak_ptr<JsEngine> weakJsEngine;
284 TimerTaskInfos::const_iterator ii_taskInfo; 285 TimerTaskInfos::const_iterator taskInfoIterator;
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 };
286 TimerTask CreateTimerTask(const v8::Arguments& arguments); 287 TimerTask CreateTimerTask(const v8::Arguments& arguments);
287 void CallTimerTask(TimerTaskInfos::const_iterator ii_taskInfo); 288 void CallTimerTask(TimerTaskInfos::const_iterator taskInfoIterator);
288 private: 289 private:
289 explicit JsEngine(const ScopedV8IsolatePtr& isolate); 290 explicit JsEngine(const ScopedV8IsolatePtr& isolate);
290 291
291 JsValuePtr GetGlobalObject(); 292 JsValuePtr GetGlobalObject();
292 293
293 /// Isolate must be disposed only after disposing of all objects which are 294 /// Isolate must be disposed only after disposing of all objects which are
294 /// using it. 295 /// using it.
295 ScopedV8IsolatePtr isolate; 296 ScopedV8IsolatePtr isolate;
296 297
297 FileSystemPtr fileSystem; 298 FileSystemPtr fileSystem;
298 WebRequestPtr webRequest; 299 WebRequestPtr webRequest;
299 LogSystemPtr logSystem; 300 LogSystemPtr logSystem;
300 std::unique_ptr<v8::Persistent<v8::Context>> context; 301 std::unique_ptr<v8::Persistent<v8::Context>> context;
301 EventMap eventCallbacks; 302 EventMap eventCallbacks;
302 std::mutex eventCallbacksMutex; 303 std::mutex eventCallbacksMutex;
303 std::mutex isConnectionAllowedMutex; 304 std::mutex isConnectionAllowedMutex;
304 IsConnectionAllowedCallback isConnectionAllowed; 305 IsConnectionAllowedCallback isConnectionAllowed;
305 TimerTaskInfos timerTaskInfos; 306 TimerTaskInfos timerTaskInfos;
306 }; 307 };
307 } 308 }
308 309
309 #endif 310 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld