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

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

Issue 29498576: Issue 4832 - remove API allowing changing of LogSystem after Initialization of JsEngine (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: address comment Created July 26, 2017, 4:48 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 | « no previous file | include/AdblockPlus/LogSystem.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * A factory to construct DefaultFileSystem. 59 * A factory to construct DefaultFileSystem.
60 */ 60 */
61 FileSystemPtr CreateDefaultFileSystem(); 61 FileSystemPtr CreateDefaultFileSystem();
62 62
63 /** 63 /**
64 * A factory to construct DefaultWebRequest. 64 * A factory to construct DefaultWebRequest.
65 */ 65 */
66 WebRequestPtr CreateDefaultWebRequest(); 66 WebRequestPtr CreateDefaultWebRequest();
67 67
68 /** 68 /**
69 * A factory to construct LogSystem.
70 */
71 LogSystemPtr CreateDefaultLogSystem();
72
73 /**
69 * Scope based isolate manager. Creates a new isolate instance on 74 * Scope based isolate manager. Creates a new isolate instance on
70 * constructing and disposes it on destructing. 75 * constructing and disposes it on destructing.
71 */ 76 */
72 class ScopedV8Isolate 77 class ScopedV8Isolate
73 { 78 {
74 public: 79 public:
75 ScopedV8Isolate(); 80 ScopedV8Isolate();
76 ~ScopedV8Isolate(); 81 ~ScopedV8Isolate();
77 v8::Isolate* Get() 82 v8::Isolate* Get()
78 { 83 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 friend class JsEngine; 124 friend class JsEngine;
120 JsWeakValuesLists::const_iterator iterator; 125 JsWeakValuesLists::const_iterator iterator;
121 }; 126 };
122 127
123 /** 128 /**
124 * Creates a new JavaScript engine instance. 129 * Creates a new JavaScript engine instance.
125 * @param appInfo Information about the app. 130 * @param appInfo Information about the app.
126 * @param timer Implementation of timer. 131 * @param timer Implementation of timer.
127 * @param fileSystem Implementation of filesystem. 132 * @param fileSystem Implementation of filesystem.
128 * @param webRequest Implementation of web request. 133 * @param webRequest Implementation of web request.
134 * @param logSystem Implementation of log system.
129 * @return New `JsEngine` instance. 135 * @return New `JsEngine` instance.
130 */ 136 */
131 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), 137 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(),
132 TimerPtr timer = CreateDefaultTimer(), 138 TimerPtr timer = CreateDefaultTimer(),
133 FileSystemPtr fileSystem = CreateDefaultFileSystem(), 139 FileSystemPtr fileSystem = CreateDefaultFileSystem(),
134 WebRequestPtr webRequest = CreateDefaultWebRequest()); 140 WebRequestPtr webRequest = CreateDefaultWebRequest(),
141 LogSystemPtr logSystem = CreateDefaultLogSystem());
135 142
136 /** 143 /**
137 * Registers the callback function for an event. 144 * Registers the callback function for an event.
138 * @param eventName Event name. Note that this can be any string - it's a 145 * @param eventName Event name. Note that this can be any string - it's a
139 * general purpose event handling mechanism. 146 * general purpose event handling mechanism.
140 * @param callback Event callback function. 147 * @param callback Event callback function.
141 */ 148 */
142 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback); 149 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback);
143 150
144 /** 151 /**
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 /** 277 /**
271 * Sets the synchronous `FileSystem` implementation used for all 278 * Sets the synchronous `FileSystem` implementation used for all
272 * file I/O. Setting this is optional, the engine will use the 279 * file I/O. Setting this is optional, the engine will use the
273 * implementation created by `CreateDefaultFileSystem()` by 280 * implementation created by `CreateDefaultFileSystem()` by
274 * default, which might be sufficient. 281 * default, which might be sufficient.
275 * @param The `FileSystem` instance to use. 282 * @param The `FileSystem` instance to use.
276 */ 283 */
277 void SetFileSystem(const FileSystemSyncPtr& val); 284 void SetFileSystem(const FileSystemSyncPtr& val);
278 285
279 /** 286 /**
280 * @see `SetLogSystem()`. 287 * Private functionality.
288 * @return The LogSystem implementation.
281 */ 289 */
282 LogSystemPtr GetLogSystem() const; 290 LogSystem& GetLogSystem();
283
284 /**
285 * Sets the `LogSystem` implementation used for logging (e.g. to handle
286 * `console.log()` calls from JavaScript).
287 * Setting this is optional, the engine will use a `DefaultLogSystem`
288 * instance by default, which might be sufficient.
289 * @param The `LogSystem` instance to use.
290 */
291 void SetLogSystem(const LogSystemPtr& val);
292 291
293 /** 292 /**
294 * Sets a global property that can be accessed by all the scripts. 293 * Sets a global property that can be accessed by all the scripts.
295 * @param name Name of the property to set. 294 * @param name Name of the property to set.
296 * @param value Value of the property to set. 295 * @param value Value of the property to set.
297 */ 296 */
298 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value); 297 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value);
299 298
300 /** 299 /**
301 * Returns a pointer to associated v8::Isolate. 300 * Returns a pointer to associated v8::Isolate.
302 */ 301 */
303 v8::Isolate* GetIsolate() 302 v8::Isolate* GetIsolate()
304 { 303 {
305 return isolate.Get(); 304 return isolate.Get();
306 } 305 }
307 306
308 /** 307 /**
309 * Notifies JS engine about critically low memory what should cause a 308 * Notifies JS engine about critically low memory what should cause a
310 * garbage collection. 309 * garbage collection.
311 */ 310 */
312 void NotifyLowMemory(); 311 void NotifyLowMemory();
313 private: 312 private:
314 void CallTimerTask(const JsWeakValuesID& timerParamsID); 313 void CallTimerTask(const JsWeakValuesID& timerParamsID);
315 314
316 explicit JsEngine(TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr we bRequest); 315 explicit JsEngine(TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr we bRequest, LogSystemPtr logSystem);
317 316
318 JsValue GetGlobalObject(); 317 JsValue GetGlobalObject();
319 318
320 /// Isolate must be disposed only after disposing of all objects which are 319 /// Isolate must be disposed only after disposing of all objects which are
321 /// using it. 320 /// using it.
322 ScopedV8Isolate isolate; 321 ScopedV8Isolate isolate;
323 322
324 FileSystemPtr fileSystem; 323 FileSystemPtr fileSystem;
325 LogSystemPtr logSystem; 324 LogSystemPtr logSystem;
326 std::unique_ptr<v8::Global<v8::Context>> context; 325 std::unique_ptr<v8::Global<v8::Context>> context;
327 EventMap eventCallbacks; 326 EventMap eventCallbacks;
328 std::mutex eventCallbacksMutex; 327 std::mutex eventCallbacksMutex;
329 JsWeakValuesLists jsWeakValuesLists; 328 JsWeakValuesLists jsWeakValuesLists;
330 std::mutex jsWeakValuesListsMutex; 329 std::mutex jsWeakValuesListsMutex;
331 TimerPtr timer; 330 TimerPtr timer;
332 WebRequestPtr webRequest; 331 WebRequestPtr webRequest;
333 }; 332 };
334 } 333 }
335 334
336 #endif 335 #endif
OLDNEW
« no previous file with comments | « no previous file | include/AdblockPlus/LogSystem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld