Chromium Code Reviews| Index: gin/v8_initializer.cc |
| diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc |
| index 8f79d0d8693b23b01820e9906dad5da48a64bb77..6534adf20bf05e18d94e4ce667d89658b86b73d9 100644 |
| --- a/gin/v8_initializer.cc |
| +++ b/gin/v8_initializer.cc |
| @@ -17,6 +17,9 @@ |
| #include "crypto/sha2.h" |
| #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| +#if defined(OS_ANDROID) |
| +#include "base/android/apk_assets.h" |
| +#endif |
| #if defined(OS_MACOSX) |
| #include "base/mac/foundation_util.h" |
| #endif // OS_MACOSX |
| @@ -50,6 +53,7 @@ const char kSnapshotFileName[] = "snapshot_blob.bin"; |
| const int kMaxOpenAttempts = 5; |
| const int kOpenRetryDelayMillis = 250; |
| +#if !defined(OS_ANDROID) |
| void GetV8FilePaths(base::FilePath* natives_path_out, |
| base::FilePath* snapshot_path_out) { |
| #if !defined(OS_MACOSX) |
| @@ -72,13 +76,12 @@ void GetV8FilePaths(base::FilePath* natives_path_out, |
| DCHECK(!snapshot_path_out->empty()); |
| #endif // !defined(OS_MACOSX) |
| } |
| +#endif // !defined(OS_ANDROID) |
| static bool MapV8Files(base::File natives_file, |
| base::File snapshot_file, |
| - base::MemoryMappedFile::Region natives_region = |
| - base::MemoryMappedFile::Region::kWholeFile, |
| - base::MemoryMappedFile::Region snapshot_region = |
| - base::MemoryMappedFile::Region::kWholeFile) { |
| + base::MemoryMappedFile::Region natives_region, |
| + base::MemoryMappedFile::Region snapshot_region) { |
| g_mapped_natives = new base::MemoryMappedFile; |
| if (!g_mapped_natives->IsValid()) { |
| if (!g_mapped_natives->Initialize(natives_file.Pass(), natives_region)) { |
| @@ -102,6 +105,8 @@ static bool MapV8Files(base::File natives_file, |
| return true; |
| } |
| +#if !defined(OS_ANDROID) |
| + |
| static bool OpenV8File(const base::FilePath& path, |
| int flags, |
| base::File& file) { |
| @@ -144,6 +149,7 @@ static bool OpenV8File(const base::FilePath& path, |
| return result == OpenV8FileResult::OPENED |
| || result == OpenV8FileResult::OPENED_RETRY; |
| } |
| +#endif // !defined(OS_ANDROID) |
| #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file, |
| @@ -166,6 +172,11 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) { |
| } // namespace |
| #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| + |
| +bool V8Initializer::V8Files::IsLoaded() const { |
| + return snapshot_fd.get() != -1 && natives_fd.get() != -1; |
| +} |
| + |
| #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| // Defined in gen/gin/v8_snapshot_fingerprint.cc |
| extern const unsigned char g_natives_fingerprint[]; |
| @@ -186,19 +197,14 @@ bool V8Initializer::LoadV8Snapshot() { |
| if (g_mapped_natives && g_mapped_snapshot) |
| return true; |
| - base::FilePath natives_data_path; |
| - base::FilePath snapshot_data_path; |
| - GetV8FilePaths(&natives_data_path, &snapshot_data_path); |
| - |
| - base::File natives_file; |
| - base::File snapshot_file; |
| - int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
| - |
| + V8Files files; |
| + OpenV8FilesForChildProcesses(&files); |
|
rmcilroy
2015/05/28 12:03:29
I don't think you should be calling OpenV8FilesFor
agrieve
2015/06/13 02:21:29
I did this just because the two functions are copy
|
| LoadV8SnapshotResult result; |
| - if (!OpenV8File(natives_data_path, flags, natives_file) || |
| - !OpenV8File(snapshot_data_path, flags, snapshot_file)) { |
| + if (!files.IsLoaded()) { |
| result = LoadV8SnapshotResult::FAILED_OPEN; |
| - } else if (!MapV8Files(natives_file.Pass(), snapshot_file.Pass())) { |
| + } else if (!MapV8Files(base::File(files.natives_fd.release()), |
| + base::File(files.snapshot_fd.release()), |
| + files.natives_region, files.snapshot_region)) { |
| result = LoadV8SnapshotResult::FAILED_MAP; |
| #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| } else if (!VerifyV8SnapshotFile(g_mapped_natives, g_natives_fingerprint) || |
| @@ -244,9 +250,14 @@ bool V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile natives_pf, |
| } |
| // static |
| -bool V8Initializer::OpenV8FilesForChildProcesses( |
| - base::PlatformFile* natives_fd_out, |
| - base::PlatformFile* snapshot_fd_out) { |
| +void V8Initializer::OpenV8FilesForChildProcesses( |
| + V8Initializer::V8Files* files_out) { |
| +#if defined(OS_ANDROID) |
| + files_out->natives_fd.reset(base::android::OpenApkAsset( |
| + kNativesFileName, &files_out->natives_region)); |
| + files_out->snapshot_fd.reset(base::android::OpenApkAsset( |
| + kSnapshotFileName, &files_out->snapshot_region)); |
| +#else |
| base::FilePath natives_data_path; |
| base::FilePath snapshot_data_path; |
| GetV8FilePaths(&natives_data_path, &snapshot_data_path); |
| @@ -258,12 +269,15 @@ bool V8Initializer::OpenV8FilesForChildProcesses( |
| bool success = OpenV8File(natives_data_path, file_flags, natives_data_file) && |
| OpenV8File(snapshot_data_path, file_flags, snapshot_data_file); |
| if (success) { |
| - *natives_fd_out = natives_data_file.TakePlatformFile(); |
| - *snapshot_fd_out = snapshot_data_file.TakePlatformFile(); |
| + files_out->natives_fd.reset(natives_data_file.TakePlatformFile()); |
| + files_out->snapshot_fd.reset(snapshot_data_file.TakePlatformFile()); |
| + files_out->natives_region = base::MemoryMappedFile::Region::kWholeFile; |
| + files_out->snapshot_region = base::MemoryMappedFile::Region::kWholeFile; |
| } |
| - return success; |
| +#endif |
| } |
| + |
| #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| // static |