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

Side by Side Diff: src/JsEngine.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebase on master. Last changes. Created July 7, 2017, 1:36 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 | « src/FilterEngine.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 }; 71 };
72 } 72 }
73 73
74 using namespace AdblockPlus; 74 using namespace AdblockPlus;
75 75
76 TimerPtr AdblockPlus::CreateDefaultTimer() 76 TimerPtr AdblockPlus::CreateDefaultTimer()
77 { 77 {
78 return TimerPtr(new DefaultTimer()); 78 return TimerPtr(new DefaultTimer());
79 } 79 }
80 80
81 FileSystemPtr AdblockPlus::CreateDefaultFileSystem()
82 {
83 return FileSystemPtr(new DefaultFileSystem(std::make_shared<DefaultFileSystemS ync>()));
84 }
85
81 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() 86 WebRequestPtr AdblockPlus::CreateDefaultWebRequest()
82 { 87 {
83 return WebRequestPtr(new DefaultWebRequest(std::make_shared<DefaultWebRequestS ync>())); 88 return WebRequestPtr(new DefaultWebRequest(std::make_shared<DefaultWebRequestS ync>()));
84 } 89 }
85 90
86 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() 91 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate()
87 { 92 {
88 V8Initializer::Init(); 93 V8Initializer::Init();
89 v8::Isolate::CreateParams isolateParams; 94 v8::Isolate::CreateParams isolateParams;
90 isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultA llocator(); 95 isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultA llocator();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) 135 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID)
131 { 136 {
132 auto timerParams = TakeJsValues(timerParamsID); 137 auto timerParams = TakeJsValues(timerParamsID);
133 JsValue callback = std::move(timerParams[0]); 138 JsValue callback = std::move(timerParams[0]);
134 139
135 timerParams.erase(timerParams.begin()); // remove callback placeholder 140 timerParams.erase(timerParams.begin()); // remove callback placeholder
136 timerParams.erase(timerParams.begin()); // remove timeout param 141 timerParams.erase(timerParams.begin()); // remove timeout param
137 callback.Call(timerParams); 142 callback.Call(timerParams);
138 } 143 }
139 144
140 AdblockPlus::JsEngine::JsEngine(TimerPtr timer, WebRequestPtr webRequest) 145 AdblockPlus::JsEngine::JsEngine(TimerPtr timer, FileSystemPtr fileSystem,
141 : fileSystem(new DefaultFileSystem()) 146 WebRequestPtr webRequest)
147 : fileSystem(std::move(fileSystem))
142 , logSystem(new DefaultLogSystem()) 148 , logSystem(new DefaultLogSystem())
143 , timer(std::move(timer)) 149 , timer(std::move(timer))
144 , webRequest(std::move(webRequest)) 150 , webRequest(std::move(webRequest))
145 { 151 {
146 } 152 }
147 153
148 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, 154 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
149 TimerPtr timer, WebRequestPtr webRequest) 155 TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest)
150 { 156 {
151 JsEnginePtr result(new JsEngine(std::move(timer), std::move(webRequest))); 157 JsEnginePtr result(new JsEngine(std::move(timer),
158 std::move(fileSystem),
159 std::move(webRequest)));
152 160
153 const v8::Locker locker(result->GetIsolate()); 161 const v8::Locker locker(result->GetIsolate());
154 const v8::Isolate::Scope isolateScope(result->GetIsolate()); 162 const v8::Isolate::Scope isolateScope(result->GetIsolate());
155 const v8::HandleScope handleScope(result->GetIsolate()); 163 const v8::HandleScope handleScope(result->GetIsolate());
156 164
157 result->context.reset(new v8::Global<v8::Context>(result->GetIsolate(), 165 result->context.reset(new v8::Global<v8::Context>(result->GetIsolate(),
158 v8::Context::New(result->GetIsolate()))); 166 v8::Context::New(result->GetIsolate())));
159 auto global = result->GetGlobalObject(); 167 auto global = result->GetGlobalObject();
160 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); 168 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global);
161 return result; 169 return result;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 312
305 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Funct ionCallbackInfo<v8::Value>& arguments) 313 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Funct ionCallbackInfo<v8::Value>& arguments)
306 { 314 {
307 const JsContext context(*this); 315 const JsContext context(*this);
308 JsValueList list; 316 JsValueList list;
309 for (int i = 0; i < arguments.Length(); i++) 317 for (int i = 0; i < arguments.Length(); i++)
310 list.push_back(JsValue(shared_from_this(), arguments[i])); 318 list.push_back(JsValue(shared_from_this(), arguments[i]));
311 return list; 319 return list;
312 } 320 }
313 321
314 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const 322 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetAsyncFileSystem() const
315 { 323 {
316 return fileSystem; 324 return fileSystem;
317 } 325 }
318 326
319 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemPtr& val) 327 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemSyncPtr& val)
320 { 328 {
321 if (!val) 329 if (!val)
322 throw std::runtime_error("FileSystem cannot be null"); 330 throw std::runtime_error("FileSystem cannot be null");
323 331
324 fileSystem = val; 332 fileSystem.reset(new DefaultFileSystem(val));
325 } 333 }
326 334
327 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestSharedPtr & val) 335 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestSharedPtr & val)
328 { 336 {
329 if (!val) 337 if (!val)
330 throw std::runtime_error("WebRequest cannot be null"); 338 throw std::runtime_error("WebRequest cannot be null");
331 339
332 webRequestLegacy = val; 340 webRequestLegacy = val;
333 } 341 }
334 342
(...skipping 10 matching lines...) Expand all
345 logSystem = val; 353 logSystem = val;
346 } 354 }
347 355
348 356
349 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 357 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
350 const AdblockPlus::JsValue& value) 358 const AdblockPlus::JsValue& value)
351 { 359 {
352 auto global = GetGlobalObject(); 360 auto global = GetGlobalObject();
353 global.SetProperty(name, value); 361 global.SetProperty(name, value);
354 } 362 }
OLDNEW
« no previous file with comments | « src/FilterEngine.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld