diff options
author | rmcilroy <rmcilroy@chromium.org> | 2015-04-06 14:14:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-06 21:15:46 +0000 |
commit | 54fab5e3b8f16436d3329ecbdb6c40e050278a51 (patch) | |
tree | eb24d311c8e1ae64afbad532e027ebcc901f6628 /gin | |
parent | 6f6eba38275695220ec63e358d83d9e3b548c7ad (diff) | |
download | chromium_src-54fab5e3b8f16436d3329ecbdb6c40e050278a51.zip chromium_src-54fab5e3b8f16436d3329ecbdb6c40e050278a51.tar.gz chromium_src-54fab5e3b8f16436d3329ecbdb6c40e050278a51.tar.bz2 |
Add support to extension_shell and ash_shell to use external V8 snapshot files.
Adds support to extension_shell and ash_shell to use external V8 snapshot files
in preparation for moving ChromeOS and ChromeCast to use this.
Re-factors the chrome_content_browser_client and
content/shell_content_browser_client to allow more reuse
of the code which opens the V8 external snapshot for child processes
by adding IsolateHolder::OpenV8FilesForChildProcesses.
This does not yet switch ChromeOS to use external V8 snapshot files -
this will be done in follow up CL https://codereview.chromium.org/1019123002.
BUG=421063
Review URL: https://codereview.chromium.org/1019483002
Cr-Commit-Position: refs/heads/master@{#323953}
Diffstat (limited to 'gin')
-rw-r--r-- | gin/v8_initializer.cc | 108 | ||||
-rw-r--r-- | gin/v8_initializer.h | 6 |
2 files changed, 73 insertions, 41 deletions
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc index 76f227d..67b5f88 100644 --- a/gin/v8_initializer.cc +++ b/gin/v8_initializer.cc @@ -24,15 +24,47 @@ namespace gin { namespace { -bool GenerateEntropy(unsigned char* buffer, size_t amount) { - base::RandBytes(buffer, amount); - return true; -} - base::MemoryMappedFile* g_mapped_natives = nullptr; base::MemoryMappedFile* g_mapped_snapshot = nullptr; #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_out->empty()); + DCHECK(!snapshot_path_out->empty()); +#endif // !defined(OS_MACOSX) +} + bool MapV8Files(base::File natives_file, base::File snapshot_file, base::MemoryMappedFile::Region natives_region = @@ -75,58 +107,32 @@ bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file, #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA #endif // V8_USE_EXTERNAL_STARTUP_DATA +bool GenerateEntropy(unsigned char* buffer, size_t amount) { + base::RandBytes(buffer, amount); + return true; +} + } // namespace #if defined(V8_USE_EXTERNAL_STARTUP_DATA) - #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) // Defined in gen/gin/v8_snapshot_fingerprint.cc 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 V8Initializer::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 V8Initializer::kNativesFileName[] = "natives_blob.bin"; -const char V8Initializer::kSnapshotFileName[] = "snapshot_blob.bin"; - // static bool V8Initializer::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_data_path; + base::FilePath snapshot_data_path; + GetV8FilePaths(&natives_data_path, &snapshot_data_path); int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; - if (!MapV8Files(base::File(natives_path, flags), - base::File(snapshot_path, flags))) + if (!MapV8Files(base::File(natives_data_path, flags), + base::File(snapshot_data_path, flags))) return false; #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) @@ -165,6 +171,26 @@ bool V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile natives_pf, natives_region, snapshot_region); } +// static +bool V8Initializer::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 diff --git a/gin/v8_initializer.h b/gin/v8_initializer.h index ad3ed6e..6c9c6c2 100644 --- a/gin/v8_initializer.h +++ b/gin/v8_initializer.h @@ -49,6 +49,12 @@ class GIN_EXPORT V8Initializer { // snapshot is already loaded, false otherwise. static bool LoadV8Snapshot(); + // Opens the V8 snapshot data files and returns open file descriptors to these + // files in |natives_fd_out| and |snapshot_fd_out|, which can be passed to + // child processes. + static bool OpenV8FilesForChildProcesses(base::PlatformFile* natives_fd_out, + base::PlatformFile* snapshot_fd_out); + #endif // V8_USE_EXTERNAL_STARTUP_DATA }; |