| 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_V8_INITIALIZER_H_ | 5 #ifndef GIN_V8_INITIALIZER_H_ |
| 6 #define GIN_V8_INITIALIZER_H_ | 6 #define GIN_V8_INITIALIZER_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/memory_mapped_file.h" |
| 9 #include "gin/array_buffer.h" | 10 #include "gin/array_buffer.h" |
| 10 #include "gin/gin_export.h" | 11 #include "gin/gin_export.h" |
| 11 #include "gin/public/isolate_holder.h" | 12 #include "gin/public/isolate_holder.h" |
| 12 #include "gin/public/v8_platform.h" | 13 #include "gin/public/v8_platform.h" |
| 13 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 14 | 15 |
| 15 namespace gin { | 16 namespace gin { |
| 16 | 17 |
| 17 class GIN_EXPORT V8Initializer { | 18 class GIN_EXPORT V8Initializer { |
| 18 public: | 19 public: |
| 19 static const int kV8SnapshotBasePathKey; | |
| 20 static const char kNativesFileName[]; | |
| 21 static const char kSnapshotFileName[]; | |
| 22 | |
| 23 // This should be called by IsolateHolder::Initialize(). | 20 // This should be called by IsolateHolder::Initialize(). |
| 24 static void Initialize(gin::IsolateHolder::ScriptMode mode); | 21 static void Initialize(gin::IsolateHolder::ScriptMode mode); |
| 25 | 22 |
| 26 // Get address and size information for currently loaded snapshot. | 23 // Get address and size information for currently loaded snapshot. |
| 27 // If no snapshot is loaded, the return values are null for addresses | 24 // If no snapshot is loaded, the return values are null for addresses |
| 28 // and 0 for sizes. | 25 // and 0 for sizes. |
| 29 static void GetV8ExternalSnapshotData(const char** natives_data_out, | 26 static void GetV8ExternalSnapshotData(const char** natives_data_out, |
| 30 int* natives_size_out, | 27 int* natives_size_out, |
| 31 const char** snapshot_data_out, | 28 const char** snapshot_data_out, |
| 32 int* snapshot_size_out); | 29 int* snapshot_size_out); |
| 33 | 30 |
| 34 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 31 #if defined(OS_POSIX) && defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 32 |
| 33 struct V8Files { |
| 34 base::ScopedFD natives_fd; |
| 35 base::ScopedFD snapshot_fd; |
| 36 base::MemoryMappedFile::Region natives_region; |
| 37 base::MemoryMappedFile::Region snapshot_region; |
| 38 public: |
| 39 bool IsLoaded() const; |
| 40 }; |
| 35 | 41 |
| 36 // Load V8 snapshot from user provided platform file descriptors. | 42 // Load V8 snapshot from user provided platform file descriptors. |
| 37 // The offset and size arguments, if non-zero, specify the portions | 43 // The offset and size arguments, if non-zero, specify the portions |
| 38 // of the files to be loaded. This methods returns true on success | 44 // of the files to be loaded. This methods returns true on success |
| 39 // (or if snapshot is already loaded), false otherwise. | 45 // (or if snapshot is already loaded), false otherwise. |
| 40 static bool LoadV8SnapshotFromFD(base::PlatformFile natives_fd, | 46 static bool LoadV8SnapshotFromFD(base::PlatformFile natives_fd, |
| 41 int64 natives_offset, | 47 int64 natives_offset, |
| 42 int64 natives_size, | 48 int64 natives_size, |
| 43 base::PlatformFile snapshot_fd, | 49 base::PlatformFile snapshot_fd, |
| 44 int64 snapshot_offset, | 50 int64 snapshot_offset, |
| 45 int64 snapshot_size); | 51 int64 snapshot_size); |
| 46 | 52 |
| 47 // Load V8 snapshot from default resources. Returns true on success or | 53 // Load V8 snapshot from default resources. Returns true on success or |
| 48 // snapshot is already loaded, false otherwise. | 54 // snapshot is already loaded, false otherwise. |
| 49 static bool LoadV8Snapshot(); | 55 static bool LoadV8Snapshot(); |
| 50 | 56 |
| 51 // Opens the V8 snapshot data files and returns open file descriptors to these | 57 // Opens the V8 snapshot data files and returns open file descriptors and |
| 52 // files in |natives_fd_out| and |snapshot_fd_out|, which can be passed to | 58 // file regions to these files that can be passed to child processes. |
| 53 // child processes. | 59 static void OpenV8FilesForChildProcesses(V8Files* files_out); |
| 54 static bool OpenV8FilesForChildProcesses(base::PlatformFile* natives_fd_out, | |
| 55 base::PlatformFile* snapshot_fd_out); | |
| 56 | 60 |
| 57 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 61 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 } // namespace gin | 64 } // namespace gin |
| 61 | 65 |
| 62 #endif // GIN_V8_INITIALIZER_H_ | 66 #endif // GIN_V8_INITIALIZER_H_ |
| OLD | NEW |