| OLD | NEW |
| 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 namespace base { |
| 14 |
| 15 // Forward declaration of PlatformFile from base/file/file.h |
| 16 #if defined(OS_WIN) |
| 17 typedef HANDLE PlatformFile; |
| 18 #elif defined(OS_POSIX) |
| 19 typedef int PlatformFile; |
| 20 #endif |
| 21 } |
| 22 |
| 13 namespace gin { | 23 namespace gin { |
| 14 | 24 |
| 15 class PerIsolateData; | 25 class PerIsolateData; |
| 16 class RunMicrotasksObserver; | 26 class RunMicrotasksObserver; |
| 17 | 27 |
| 18 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then | 28 // 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 | 29 // 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 | 30 // will execute JavaScript. You might wish to subclass IsolateHolder if you |
| 21 // want to tie more state to the lifetime of the isolate. | 31 // want to tie more state to the lifetime of the isolate. |
| 22 class GIN_EXPORT IsolateHolder { | 32 class GIN_EXPORT IsolateHolder { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 45 // Microtasks each time a Task is completed. This method should be called | 55 // Microtasks each time a Task is completed. This method should be called |
| 46 // once, when a MessageLoop is created and it should be called on the | 56 // once, when a MessageLoop is created and it should be called on the |
| 47 // MessageLoop's thread. | 57 // MessageLoop's thread. |
| 48 void AddRunMicrotasksObserver(); | 58 void AddRunMicrotasksObserver(); |
| 49 | 59 |
| 50 // This method should also only be called once, and on the MessageLoop's | 60 // This method should also only be called once, and on the MessageLoop's |
| 51 // thread. | 61 // thread. |
| 52 void RemoveRunMicrotasksObserver(); | 62 void RemoveRunMicrotasksObserver(); |
| 53 | 63 |
| 54 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 64 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 55 static const int kV8SnapshotBasePathKey; | 65 // Load the V8 snapshot data from the given file descriptors. If offset and |
| 56 static const char kNativesFileName[]; | 66 // size are zero it will load the whole file, otherwise it will map and load |
| 57 static const char kSnapshotFileName[]; | 67 // the region of the file specified by offset and size. Returns true on |
| 58 | 68 // success. |
| 59 static bool LoadV8SnapshotFd(int natives_fd, | 69 static bool LoadV8SnapshotFd(int natives_fd, |
| 60 int64 natives_offset, | 70 int64 natives_offset, |
| 61 int64 natives_size, | 71 int64 natives_size, |
| 62 int snapshot_fd, | 72 int snapshot_fd, |
| 63 int64 snapshot_offset, | 73 int64 snapshot_offset, |
| 64 int64 snapshot_size); | 74 int64 snapshot_size); |
| 75 |
| 76 // Load the V8 snapshot data from the snapshot files. Returns true on success. |
| 65 static bool LoadV8Snapshot(); | 77 static bool LoadV8Snapshot(); |
| 78 |
| 79 // Opens the V8 snapshot data files and returns open file descriptors to these |
| 80 // files in |natives_fd_out| and |snapshot_fd_out|, which can be passed to |
| 81 // child processes. |
| 82 static bool OpenV8FilesForChildProcesses(base::PlatformFile* natives_fd_out, |
| 83 base::PlatformFile* snapshot_fd_out); |
| 84 |
| 66 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 85 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 67 static void GetV8ExternalSnapshotData(const char** natives_data_out, | 86 static void GetV8ExternalSnapshotData(const char** natives_data_out, |
| 68 int* natives_size_out, | 87 int* natives_size_out, |
| 69 const char** snapshot_data_out, | 88 const char** snapshot_data_out, |
| 70 int* snapshot_size_out); | 89 int* snapshot_size_out); |
| 71 | 90 |
| 72 private: | 91 private: |
| 73 v8::Isolate* isolate_; | 92 v8::Isolate* isolate_; |
| 74 scoped_ptr<PerIsolateData> isolate_data_; | 93 scoped_ptr<PerIsolateData> isolate_data_; |
| 75 scoped_ptr<RunMicrotasksObserver> task_observer_; | 94 scoped_ptr<RunMicrotasksObserver> task_observer_; |
| 76 | 95 |
| 77 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); | 96 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); |
| 78 }; | 97 }; |
| 79 | 98 |
| 80 } // namespace gin | 99 } // namespace gin |
| 81 | 100 |
| 82 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ | 101 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ |
| OLD | NEW |