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

Unified Diff: src/WebRequestJsObject.cpp

Issue 29367003: Issue #4711 - Rewrite legacy thread facilities
Patch Set: Created Dec. 7, 2016, 4:44 p.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
« src/Thread.h ('K') | « src/Thread.cpp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/WebRequestJsObject.cpp
===================================================================
--- a/src/WebRequestJsObject.cpp
+++ b/src/WebRequestJsObject.cpp
@@ -20,17 +20,17 @@
#include <AdblockPlus/WebRequest.h>
#include "JsContext.h"
-#include "Thread.h"
#include "Utils.h"
+#include "Scheduler.h"
#include "WebRequestJsObject.h"
namespace
{
- class WebRequestThread : public AdblockPlus::Thread
+ class WebRequestTask
{
public:
- WebRequestThread(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList& arguments)
- : Thread(true), jsEngine(jsEngine), url(arguments[0]->AsString())
+ WebRequestTask(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList& arguments)
+ : jsEngine(jsEngine), url(arguments[0]->AsString())
{
if (!url.length())
throw std::runtime_error("Invalid string passed as first argument to GET");
@@ -56,7 +56,7 @@
throw std::runtime_error("Third argument to GET must be a function");
}
- void Run()
+ void operator()()
{
AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, headers);
@@ -89,14 +89,14 @@
v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments)
{
- WebRequestThread* thread;
+ std::shared_ptr<WebRequestTask> thread;
try
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
if (converted.size() != 3u)
throw std::runtime_error("GET requires exactly 3 arguments");
- thread = new WebRequestThread(jsEngine, converted);
+ thread = std::make_shared<WebRequestTask>(jsEngine, converted);
}
catch (const std::exception& e)
{
@@ -104,7 +104,7 @@
v8::Isolate* isolate = arguments.GetIsolate();
return v8::ThrowException(ToV8String(isolate, e.what()));
}
- thread->Start();
+ AdblockPlus::Scheduler::StartImmediatelyInSingleUseThread(AdblockPlus::MakeHeapFunction(thread));
return v8::Undefined();
}
}
« src/Thread.h ('K') | « src/Thread.cpp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld