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

Unified Diff: gin/isolate_holder.cc

Issue 1019483002: Add support to extension_shell and ash_shell to use external V8 snapshot files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Mac and Win builds Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/shell/browser/shell_content_browser_client.cc ('k') | gin/public/isolate_holder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « extensions/shell/browser/shell_content_browser_client.cc ('k') | gin/public/isolate_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698