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

Powered by Google App Engine
This is Rietveld