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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 29395640: Issue 3595 - Get rid of detached threads for setTimeout (Closed)
Patch Set: address comments Created March 28, 2017, 11:06 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/ITimer.h ('k') | libadblockplus.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsEngine.h
diff --git a/include/AdblockPlus/JsEngine.h b/include/AdblockPlus/JsEngine.h
index f8062b657d5312a2204d540b156d5b268e22b259..ea6616e93082d3c8c33fe053ebbd5befd71544a9 100644
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -30,6 +30,7 @@
#include <AdblockPlus/FileSystem.h>
#include <AdblockPlus/JsValue.h>
#include <AdblockPlus/WebRequest.h>
+#include <AdblockPlus/ITimer.h>
namespace v8
{
@@ -51,6 +52,11 @@ namespace AdblockPlus
typedef std::shared_ptr<JsEngine> JsEnginePtr;
/**
+ * A factory to construct DefaultTimer.
+ */
+ TimerPtr CreateDefaultTimer();
+
+ /**
* Scope based isolate manager. Creates a new isolate instance on
* constructing and disposes it on destructing.
*/
@@ -103,11 +109,14 @@ namespace AdblockPlus
/**
* Creates a new JavaScript engine instance.
* @param appInfo Information about the app.
+ * @param timer Implementation of timer.
* @param isolate v8::Isolate wrapper. This parameter should be considered
* as a temporary hack for tests, it will go away. Issue #3593.
* @return New `JsEngine` instance.
*/
- static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate()));
+ static JsEnginePtr New(const AppInfo& appInfo = AppInfo(),
+ TimerPtr timer = CreateDefaultTimer(),
+ const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate()));
/**
* Registers the callback function for an event.
@@ -195,6 +204,13 @@ namespace AdblockPlus
*/
static JsEnginePtr FromArguments(const v8::Arguments& arguments);
+ /*
+ * Private functionality required to implement timers.
+ * @param arguments `v8::Arguments` is the arguments received in C++
+ * callback associated for global setTimeout method.
+ */
+ static void ScheduleTimer(const v8::Arguments& arguments);
+
/**
* Converts v8 arguments to `JsValue` objects.
* @param arguments `v8::Arguments` object containing the arguments to
@@ -271,23 +287,16 @@ namespace AdblockPlus
return isolate->Get();
}
- // Private functionality required to implement timers.
- struct TimerTaskInfo
- {
- ~TimerTaskInfo();
- int delay;
- std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> arguments;
- };
- typedef std::list<TimerTaskInfo> TimerTaskInfos;
+ private:
struct TimerTask
{
- std::weak_ptr<JsEngine> weakJsEngine;
- TimerTaskInfos::const_iterator taskInfoIterator;
+ ~TimerTask();
+ std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> arguments;
};
- TimerTask CreateTimerTask(const v8::Arguments& arguments);
- void CallTimerTask(TimerTaskInfos::const_iterator taskInfoIterator);
- private:
- explicit JsEngine(const ScopedV8IsolatePtr& isolate);
+ typedef std::list<TimerTask> TimerTasks;
+ void CallTimerTask(TimerTasks::const_iterator timerTaskIterator);
+
+ explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer);
JsValuePtr GetGlobalObject();
@@ -303,7 +312,8 @@ namespace AdblockPlus
std::mutex eventCallbacksMutex;
std::mutex isConnectionAllowedMutex;
IsConnectionAllowedCallback isConnectionAllowed;
- TimerTaskInfos timerTaskInfos;
+ TimerTasks timerTasks;
+ TimerPtr timer;
};
}
« no previous file with comments | « include/AdblockPlus/ITimer.h ('k') | libadblockplus.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld