Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: gin/public/isolate_holder.h

Issue 594603003: Infrastructure for reading V8's initial snapshot from external files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Ross' comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_ 5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_
6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_ 6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "gin/gin_export.h" 10 #include "gin/gin_export.h"
11 #include "v8/include/v8.h" 11 #include "v8/include/v8.h"
12 12
13 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
14 #include "base/files/file_path.h"
15 #endif
16
13 namespace gin { 17 namespace gin {
14 18
15 class PerIsolateData; 19 class PerIsolateData;
16 class RunMicrotasksObserver; 20 class RunMicrotasksObserver;
17 21
18 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then 22 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then
19 // create an instance of IsolateHolder to hold the v8::Isolate in which you 23 // create an instance of IsolateHolder to hold the v8::Isolate in which you
20 // will execute JavaScript. You might wish to subclass IsolateHolder if you 24 // will execute JavaScript. You might wish to subclass IsolateHolder if you
21 // want to tie more state to the lifetime of the isolate. 25 // want to tie more state to the lifetime of the isolate.
22 class GIN_EXPORT IsolateHolder { 26 class GIN_EXPORT IsolateHolder {
23 public: 27 public:
24 // Controls whether or not V8 should only accept strict mode scripts. 28 // Controls whether or not V8 should only accept strict mode scripts.
25 enum ScriptMode { 29 enum ScriptMode {
26 kNonStrictMode, 30 kNonStrictMode,
27 kStrictMode 31 kStrictMode
28 }; 32 };
29 33
30 IsolateHolder(); 34 IsolateHolder();
31 ~IsolateHolder(); 35 ~IsolateHolder();
32 36
33 // Should be invoked once before creating IsolateHolder instances to 37 // Should be invoked once before creating IsolateHolder instances to
34 // initialize V8 and Gin. 38 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is defined,
39 // V8's initial snapshot should be loaded (by calling LoadV8Snapshot or
40 // LoadV8SnapshotFD) before calling Initialize.
35 static void Initialize(ScriptMode mode, 41 static void Initialize(ScriptMode mode,
36 v8::ArrayBuffer::Allocator* allocator); 42 v8::ArrayBuffer::Allocator* allocator);
37 43
38 v8::Isolate* isolate() { return isolate_; } 44 v8::Isolate* isolate() { return isolate_; }
39 45
40 // The implementations of Object.observe() and Promise enqueue v8 Microtasks 46 // The implementations of Object.observe() and Promise enqueue v8 Microtasks
41 // that should be executed just before control is returned to the message 47 // that should be executed just before control is returned to the message
42 // loop. This method adds a MessageLoop TaskObserver which runs any pending 48 // loop. This method adds a MessageLoop TaskObserver which runs any pending
43 // Microtasks each time a Task is completed. This method should be called 49 // Microtasks each time a Task is completed. This method should be called
44 // once, when a MessageLoop is created and it should be called on the 50 // once, when a MessageLoop is created and it should be called on the
45 // MessageLoop's thread. 51 // MessageLoop's thread.
46 void AddRunMicrotasksObserver(); 52 void AddRunMicrotasksObserver();
47 53
48 // This method should also only be called once, and on the MessageLoop's 54 // This method should also only be called once, and on the MessageLoop's
49 // thread. 55 // thread.
50 void RemoveRunMicrotasksObserver(); 56 void RemoveRunMicrotasksObserver();
51 57
58 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
59 #ifdef OS_ANDROID
60 static bool LoadV8SnapshotFD(int natives_fd, int snapshot_fd);
61 #endif
62 static bool LoadV8Snapshot();
63 #endif // V8_USE_EXTERNAL_STARTUP_DATA
64
52 private: 65 private:
53 v8::Isolate* isolate_; 66 v8::Isolate* isolate_;
54 scoped_ptr<PerIsolateData> isolate_data_; 67 scoped_ptr<PerIsolateData> isolate_data_;
55 scoped_ptr<RunMicrotasksObserver> task_observer_; 68 scoped_ptr<RunMicrotasksObserver> task_observer_;
56 69
70 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
71
72 static bool MapV8Files(
jochen (gone - plz use gerrit) 2014/10/08 15:16:05 this method can be in an anonymous namespace in is
baixo 2014/10/14 16:36:42 Done.
73 base::FilePath* natives_path, base::FilePath* snapshot_path,
74 int natives = -1, int snapshot = -1);
75
76 #endif // V8_USE_EXTERNAL_STARTUP_DATA
77
57 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); 78 DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
58 }; 79 };
59 80
60 } // namespace gin 81 } // namespace gin
61 82
62 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ 83 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698