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

Unified Diff: src/JsEngine.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created July 31, 2017, 12:53 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
Index: src/JsEngine.cpp
diff --git a/src/JsEngine.cpp b/src/JsEngine.cpp
index e6396003f3506cdca4b3c005e91c97e47bcc000b..eb497a675d63d27be000d5f86a01eeaf7b3eeae9 100644
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -20,10 +20,8 @@
#include "JsContext.h"
#include "JsError.h"
#include "Utils.h"
-#include "DefaultTimer.h"
-#include "DefaultWebRequest.h"
-#include "DefaultFileSystem.h"
#include <libplatform/libplatform.h>
+#include <AdblockPlus/Platform.h>
namespace
{
@@ -71,35 +69,10 @@ namespace
static V8Initializer initializer;
}
};
-
- void DummyScheduler(const AdblockPlus::SchedulerTask& task)
- {
- std::thread(task).detach();
- }
}
using namespace AdblockPlus;
-TimerPtr AdblockPlus::CreateDefaultTimer()
-{
- return TimerPtr(new DefaultTimer());
-}
-
-FileSystemPtr AdblockPlus::CreateDefaultFileSystem(const Scheduler& scheduler)
-{
- return FileSystemPtr(new DefaultFileSystem(scheduler, std::unique_ptr<DefaultFileSystemSync>(new DefaultFileSystemSync())));
-}
-
-WebRequestPtr AdblockPlus::CreateDefaultWebRequest(const Scheduler& scheduler)
-{
- return WebRequestPtr(new DefaultWebRequest(scheduler, std::unique_ptr<DefaultWebRequestSync>(new DefaultWebRequestSync())));
-}
-
-LogSystemPtr AdblockPlus::CreateDefaultLogSystem()
-{
- return LogSystemPtr(new DefaultLogSystem());
-}
-
AdblockPlus::ScopedV8Isolate::ScopedV8Isolate()
{
V8Initializer::Init();
@@ -137,7 +110,7 @@ void JsEngine::ScheduleTimer(const v8::FunctionCallbackInfo<v8::Value>& argument
auto timerParamsID = jsEngine->StoreJsValues(jsValueArguments);
std::weak_ptr<JsEngine> weakJsEngine = jsEngine;
- jsEngine->timer->SetTimer(std::chrono::milliseconds(arguments[1]->IntegerValue()), [weakJsEngine, timerParamsID]
+ jsEngine->platform.GetTimer().SetTimer(std::chrono::milliseconds(arguments[1]->IntegerValue()), [weakJsEngine, timerParamsID]
{
if (auto jsEngine = weakJsEngine.lock())
jsEngine->CallTimerTask(timerParamsID);
@@ -154,22 +127,15 @@ void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID)
callback.Call(timerParams);
}
-AdblockPlus::JsEngine::JsEngine(TimerPtr timer, FileSystemPtr fileSystem,
- WebRequestPtr webRequest, LogSystemPtr logSystem)
- : fileSystem(std::move(fileSystem))
- , timer(std::move(timer))
- , logSystem(std::move(logSystem))
- , webRequest(std::move(webRequest))
+AdblockPlus::JsEngine::JsEngine(Platform& platform)
+ : platform(platform)
{
}
AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
- TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest, LogSystemPtr logSystem)
+ Platform& platform)
{
- JsEnginePtr result(new JsEngine(timer ? std::move(timer) : CreateDefaultTimer(),
- fileSystem ? std::move(fileSystem) : CreateDefaultFileSystem(::DummyScheduler),
- webRequest ? std::move(webRequest) : CreateDefaultWebRequest(::DummyScheduler),
- logSystem ? std::move(logSystem) : CreateDefaultLogSystem()));
+ JsEnginePtr result(new JsEngine(platform));
const v8::Locker locker(result->GetIsolate());
const v8::Isolate::Scope isolateScope(result->GetIsolate());
@@ -332,16 +298,6 @@ AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Funct
return list;
}
-AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetAsyncFileSystem() const
-{
- return fileSystem;
-}
-
-AdblockPlus::LogSystem& AdblockPlus::JsEngine::GetLogSystem()
-{
- return *logSystem;
-}
-
void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
const AdblockPlus::JsValue& value)
{

Powered by Google App Engine
This is Rietveld