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

Side by Side Diff: include/AdblockPlus/JsEngine.h

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Updated implementation. Created June 2, 2017, 3:49 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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * Shared smart pointer to a `JsEngine` instance. 50 * Shared smart pointer to a `JsEngine` instance.
51 */ 51 */
52 typedef std::shared_ptr<JsEngine> JsEnginePtr; 52 typedef std::shared_ptr<JsEngine> JsEnginePtr;
53 53
54 /** 54 /**
55 * A factory to construct DefaultTimer. 55 * A factory to construct DefaultTimer.
56 */ 56 */
57 TimerPtr CreateDefaultTimer(); 57 TimerPtr CreateDefaultTimer();
58 58
59 /** 59 /**
60 * A factory to construct DefaultFileSystem.
61 */
62 FileSystemPtr CreateDefaultFileSystem();
63
64 /**
60 * A factory to construct DefaultWebRequest. 65 * A factory to construct DefaultWebRequest.
61 */ 66 */
62 WebRequestPtr CreateDefaultWebRequest(); 67 WebRequestPtr CreateDefaultWebRequest();
63 68
64 /** 69 /**
65 * Scope based isolate manager. Creates a new isolate instance on 70 * Scope based isolate manager. Creates a new isolate instance on
66 * constructing and disposes it on destructing. 71 * constructing and disposes it on destructing.
67 */ 72 */
68 class ScopedV8Isolate 73 class ScopedV8Isolate
69 { 74 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 class JsWeakValuesID 118 class JsWeakValuesID
114 { 119 {
115 friend class JsEngine; 120 friend class JsEngine;
116 JsWeakValuesLists::const_iterator iterator; 121 JsWeakValuesLists::const_iterator iterator;
117 }; 122 };
118 123
119 /** 124 /**
120 * Creates a new JavaScript engine instance. 125 * Creates a new JavaScript engine instance.
121 * @param appInfo Information about the app. 126 * @param appInfo Information about the app.
122 * @param timer Implementation of timer. 127 * @param timer Implementation of timer.
128 * @param fileSystem Implementation of filesystem.
123 * @param webRequest Implementation of web request. 129 * @param webRequest Implementation of web request.
124 * @param isolate v8::Isolate wrapper. This parameter should be considered 130 * @param isolate v8::Isolate wrapper. This parameter should be considered
125 * as a temporary hack for tests, it will go away. Issue #3593. 131 * as a temporary hack for tests, it will go away. Issue #3593.
126 * @return New `JsEngine` instance. 132 * @return New `JsEngine` instance.
127 */ 133 */
128 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), 134 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(),
129 TimerPtr timer = CreateDefaultTimer(), 135 TimerPtr timer = CreateDefaultTimer(),
136 FileSystemPtr fileSystem = CreateDefaultFileSystem(),
130 WebRequestPtr webRequest = CreateDefaultWebRequest()); 137 WebRequestPtr webRequest = CreateDefaultWebRequest());
131 138
132 /** 139 /**
133 * Registers the callback function for an event. 140 * Registers the callback function for an event.
134 * @param eventName Event name. Note that this can be any string - it's a 141 * @param eventName Event name. Note that this can be any string - it's a
135 * general purpose event handling mechanism. 142 * general purpose event handling mechanism.
136 * @param callback Event callback function. 143 * @param callback Event callback function.
137 */ 144 */
138 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback); 145 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback);
139 146
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 258
252 /** 259 /**
253 * Converts v8 arguments to `JsValue` objects. 260 * Converts v8 arguments to `JsValue` objects.
254 * @param arguments `v8::Arguments` object containing the arguments to 261 * @param arguments `v8::Arguments` object containing the arguments to
255 * convert. 262 * convert.
256 * @return List of arguments converted to `const JsValue` objects. 263 * @return List of arguments converted to `const JsValue` objects.
257 */ 264 */
258 JsValueList ConvertArguments(const v8::Arguments& arguments); 265 JsValueList ConvertArguments(const v8::Arguments& arguments);
259 266
260 /** 267 /**
261 * @see `SetFileSystem()`. 268 * @return The asynchronous IFileSystem implementation.
262 */ 269 */
263 FileSystemPtr GetFileSystem() const; 270 FileSystemPtr GetFileSystem() const;
264 271
265 /** 272 /**
266 * Sets the `FileSystem` implementation used for all file I/O.
267 * Setting this is optional, the engine will use a `DefaultFileSystem`
268 * instance by default, which might be sufficient.
269 * @param The `FileSystem` instance to use.
270 */
271 void SetFileSystem(const FileSystemPtr& val);
272
273 /**
274 * Sets the `WebRequest` implementation used for XMLHttpRequests. 273 * Sets the `WebRequest` implementation used for XMLHttpRequests.
275 * Setting this is optional, the engine will use a `DefaultWebRequest` 274 * Setting this is optional, the engine will use a `DefaultWebRequest`
276 * instance by default, which might be sufficient. 275 * instance by default, which might be sufficient.
277 * @param The `WebRequest` instance to use. 276 * @param The `WebRequest` instance to use.
278 */ 277 */
279 void SetWebRequest(const WebRequestSharedPtr& val); 278 void SetWebRequest(const WebRequestSharedPtr& val);
280 279
281 /** 280 /**
282 * @see `SetLogSystem()`. 281 * @see `SetLogSystem()`.
283 */ 282 */
(...skipping 24 matching lines...) Expand all
308 } 307 }
309 308
310 /** 309 /**
311 * Notifies JS engine about critically low memory what should cause a 310 * Notifies JS engine about critically low memory what should cause a
312 * garbage collection. 311 * garbage collection.
313 */ 312 */
314 void NotifyLowMemory(); 313 void NotifyLowMemory();
315 private: 314 private:
316 void CallTimerTask(const JsWeakValuesID& timerParamsID); 315 void CallTimerTask(const JsWeakValuesID& timerParamsID);
317 316
318 explicit JsEngine(TimerPtr timer, WebRequestPtr webRequest); 317 explicit JsEngine(TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr we bRequest);
319 318
320 JsValue GetGlobalObject(); 319 JsValue GetGlobalObject();
321 320
322 /// Isolate must be disposed only after disposing of all objects which are 321 /// Isolate must be disposed only after disposing of all objects which are
323 /// using it. 322 /// using it.
324 ScopedV8Isolate isolate; 323 ScopedV8Isolate isolate;
325 324
326 FileSystemPtr fileSystem; 325 FileSystemPtr fileSystem;
327 LogSystemPtr logSystem; 326 LogSystemPtr logSystem;
328 std::unique_ptr<v8::Persistent<v8::Context>> context; 327 std::unique_ptr<v8::Persistent<v8::Context>> context;
329 EventMap eventCallbacks; 328 EventMap eventCallbacks;
330 std::mutex eventCallbacksMutex; 329 std::mutex eventCallbacksMutex;
331 JsWeakValuesLists jsWeakValuesLists; 330 JsWeakValuesLists jsWeakValuesLists;
332 std::mutex jsWeakValuesListsMutex; 331 std::mutex jsWeakValuesListsMutex;
333 TimerPtr timer; 332 TimerPtr timer;
334 WebRequestPtr webRequest; 333 WebRequestPtr webRequest;
335 WebRequestSharedPtr webRequestLegacy; 334 WebRequestSharedPtr webRequestLegacy;
336 }; 335 };
337 } 336 }
338 337
339 #endif 338 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus/IFileSystem.h ('k') | lib/init.js » ('j') | lib/init.js » ('J')

Powered by Google App Engine
This is Rietveld