Index: gin/isolate_holder.cc |
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc |
index 317b5822bd8f47f773a0927d1a2b18ef6c2ebcb8..c9373e1ad369e4120a7ee3e30701663632ef6a31 100644 |
--- a/gin/isolate_holder.cc |
+++ b/gin/isolate_holder.cc |
@@ -7,6 +7,7 @@ |
#include <stdlib.h> |
#include <string.h> |
+#include "base/files/file.h" |
#include "base/files/memory_mapped_file.h" |
#include "base/logging.h" |
#include "base/message_loop/message_loop.h" |
@@ -43,6 +44,43 @@ base::MemoryMappedFile* g_mapped_natives = NULL; |
base::MemoryMappedFile* g_mapped_snapshot = NULL; |
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
+#if !defined(OS_MACOSX) |
+const int kV8SnapshotBasePathKey = |
+#if defined(OS_ANDROID) |
+ base::DIR_ANDROID_APP_DATA; |
+#elif defined(OS_POSIX) |
+ base::DIR_EXE; |
+#elif defined(OS_WIN) |
+ base::DIR_MODULE; |
+#endif // OS_ANDROID |
+#endif // !OS_MACOSX |
+ |
+const char kNativesFileName[] = "natives_blob.bin"; |
+const char kSnapshotFileName[] = "snapshot_blob.bin"; |
+ |
+void GetV8FilePaths(base::FilePath* natives_path_out, |
+ base::FilePath* snapshot_path_out) { |
+#if !defined(OS_MACOSX) |
+ base::FilePath data_path; |
+ PathService::Get(kV8SnapshotBasePathKey, &data_path); |
+ DCHECK(!data_path.empty()); |
+ |
+ *natives_path_out = data_path.AppendASCII(kNativesFileName); |
+ *snapshot_path_out = data_path.AppendASCII(kSnapshotFileName); |
+#else // !defined(OS_MACOSX) |
+ base::ScopedCFTypeRef<CFStringRef> natives_file_name( |
+ base::SysUTF8ToCFStringRef(kNativesFileName)); |
+ *natives_path_out = |
+ base::mac::PathForFrameworkBundleResource(natives_file_name); |
+ base::ScopedCFTypeRef<CFStringRef> snapshot_file_name( |
+ base::SysUTF8ToCFStringRef(kSnapshotFileName)); |
+ *snapshot_path_out = |
+ base::mac::PathForFrameworkBundleResource(snapshot_file_name); |
+ DCHECK(!natives_path.empty()); |
+ DCHECK(!snapshot_path.empty()); |
+#endif // !defined(OS_MACOSX) |
+} |
+ |
bool MapV8Files(base::FilePath* natives_path, |
base::FilePath* snapshot_path, |
int natives_fd = -1, |
@@ -117,45 +155,14 @@ extern const unsigned char g_natives_fingerprint[]; |
extern const unsigned char g_snapshot_fingerprint[]; |
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
-#if !defined(OS_MACOSX) |
-const int IsolateHolder::kV8SnapshotBasePathKey = |
-#if defined(OS_ANDROID) |
- base::DIR_ANDROID_APP_DATA; |
-#elif defined(OS_POSIX) |
- base::DIR_EXE; |
-#elif defined(OS_WIN) |
- base::DIR_MODULE; |
-#endif // OS_ANDROID |
-#endif // !OS_MACOSX |
- |
-const char IsolateHolder::kNativesFileName[] = "natives_blob.bin"; |
-const char IsolateHolder::kSnapshotFileName[] = "snapshot_blob.bin"; |
- |
// static |
bool IsolateHolder::LoadV8Snapshot() { |
if (g_mapped_natives && g_mapped_snapshot) |
return true; |
-#if !defined(OS_MACOSX) |
- base::FilePath data_path; |
- PathService::Get(kV8SnapshotBasePathKey, &data_path); |
- DCHECK(!data_path.empty()); |
- |
- base::FilePath natives_path = data_path.AppendASCII(kNativesFileName); |
- base::FilePath snapshot_path = data_path.AppendASCII(kSnapshotFileName); |
-#else // !defined(OS_MACOSX) |
- base::ScopedCFTypeRef<CFStringRef> natives_file_name( |
- base::SysUTF8ToCFStringRef(kNativesFileName)); |
- base::FilePath natives_path = base::mac::PathForFrameworkBundleResource( |
- natives_file_name); |
- base::ScopedCFTypeRef<CFStringRef> snapshot_file_name( |
- base::SysUTF8ToCFStringRef(kSnapshotFileName)); |
- base::FilePath snapshot_path = base::mac::PathForFrameworkBundleResource( |
- snapshot_file_name); |
- DCHECK(!natives_path.empty()); |
- DCHECK(!snapshot_path.empty()); |
-#endif // !defined(OS_MACOSX) |
- |
+ base::FilePath natives_path; |
+ base::FilePath snapshot_path; |
+ GetV8FilePaths(&natives_path, &snapshot_path); |
if (!MapV8Files(&natives_path, &snapshot_path)) |
return false; |
@@ -194,6 +201,26 @@ bool IsolateHolder::LoadV8SnapshotFd(int natives_fd, |
return MapV8Files( |
NULL, NULL, natives_fd, snapshot_fd, natives_region, snapshot_region); |
} |
+ |
+// static |
+bool IsolateHolder::OpenV8FilesForChildProcesses( |
+ base::PlatformFile* natives_fd_out, |
+ base::PlatformFile* snapshot_fd_out) { |
+ base::FilePath natives_data_path; |
+ base::FilePath snapshot_data_path; |
+ GetV8FilePaths(&natives_data_path, &snapshot_data_path); |
+ |
+ int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
+ base::File natives_data_file(natives_data_path, file_flags); |
+ base::File snapshot_data_file(snapshot_data_path, file_flags); |
+ |
+ if (!natives_data_file.IsValid() || !snapshot_data_file.IsValid()) |
+ return false; |
+ |
+ *natives_fd_out = natives_data_file.TakePlatformFile(); |
+ *snapshot_fd_out = snapshot_data_file.TakePlatformFile(); |
+ return true; |
+} |
#endif // V8_USE_EXTERNAL_STARTUP_DATA |
//static |