Chromium Code Reviews| Index: gin/v8_initializer.cc |
| diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc |
| index 726d7c043a21a81b9ee2f434a8a6706d7c2de57e..916c0411a10ef7ccef316d8398ca18e408bb2494 100644 |
| --- a/gin/v8_initializer.cc |
| +++ b/gin/v8_initializer.cc |
| @@ -43,6 +43,9 @@ namespace { |
| // None of these globals are ever freed nor closed. |
| base::MemoryMappedFile* g_mapped_natives = nullptr; |
| base::MemoryMappedFile* g_mapped_snapshot = nullptr; |
| +base::MemoryMappedFile* g_mapped_context = nullptr; |
| + |
| +const char kV8ContextFileName[] = "context_blob.bin"; |
|
Yuki
2017/04/28 13:48:27
kV8ContextSnapshotFilename?
peria
2017/06/01 08:33:31
Done.
|
| #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| @@ -388,7 +391,7 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode, |
| natives.raw_size = static_cast<int>(g_mapped_natives->length()); |
| v8::V8::SetNativesDataBlob(&natives); |
| - if (g_mapped_snapshot != NULL) { |
| + if (g_mapped_snapshot) { |
| v8::StartupData snapshot; |
| snapshot.data = reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
| snapshot.raw_size = static_cast<int>(g_mapped_snapshot->length()); |
| @@ -424,4 +427,70 @@ void V8Initializer::GetV8ExternalSnapshotData(const char** natives_data_out, |
| } |
| } |
| +// static |
| +void V8Initializer::LoadV8Context() { |
| + if (g_mapped_context) |
| + return; |
| + |
| + OpenFileIfNecessary(kV8ContextFileName); |
| + MapOpenedFile(GetOpenedFile(kV8ContextFileName), &g_mapped_context); |
| +} |
| + |
| +// static |
| +void V8Initializer::LoadV8ContextFromFD(base::PlatformFile snapshot_pf, |
| + int64_t snapshot_offset, |
| + int64_t snapshot_size) { |
| + if (g_mapped_context) |
| + return; |
| + |
| + if (snapshot_pf == base::kInvalidPlatformFile) |
| + return; |
|
Yuki
2017/04/28 13:48:27
Is it really okay to simply return?
Do we need to
peria
2017/06/01 08:33:31
In this case, we fail to load the blob file.
Let's
|
| + |
| + base::MemoryMappedFile::Region snapshot_region = |
| + base::MemoryMappedFile::Region::kWholeFile; |
| + if (snapshot_size != 0 || snapshot_offset != 0) { |
| + snapshot_region.offset = snapshot_offset; |
| + snapshot_region.size = snapshot_size; |
| + } |
| + |
| + LoadV8FileResult result = V8_LOAD_SUCCESS; |
| + if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_context)) |
| + result = V8_LOAD_FAILED_MAP; |
| + if (result == V8_LOAD_SUCCESS) { |
|
Yuki
2017/04/28 13:48:27
Why don't you simply write
if (MapV8File(...)) {
peria
2017/05/30 08:25:41
Done.
|
| + g_opened_files.Get()[kV8ContextFileName] = |
| + std::make_pair(snapshot_pf, snapshot_region); |
| + } |
| +} |
| + |
| +// static |
| +base::PlatformFile V8Initializer::GetOpenV8ContextFileForChildProcesses( |
|
Yuki
2017/04/28 13:48:27
GetOpened?
I'm not sure what child processes are.
peria
2017/05/30 08:25:41
Acknowledged.
|
| + base::MemoryMappedFile::Region* region_out) { |
| + const OpenedFileMap::mapped_type& opened = |
| + OpenFileIfNecessary(kV8ContextFileName); |
| + *region_out = opened.second; |
| + return opened.first; |
| +} |
| + |
| +// static |
| +void V8Initializer::GetV8ContextData(const char** snapshot_data_out, |
| + int* snapshot_size_out) { |
| + if (g_mapped_context) { |
| + *snapshot_data_out = |
| + reinterpret_cast<const char*>(g_mapped_context->data()); |
| + *snapshot_size_out = static_cast<int>(g_mapped_context->length()); |
| + } else { |
| + *snapshot_data_out = nullptr; |
| + *snapshot_size_out = 0; |
| + } |
| +} |
| + |
| +#if defined(OS_ANDROID) |
| +// static |
| +base::FilePath V8Initializer::GetV8ContextFilePath() { |
| + base::FilePath path; |
| + GetV8FilePath(kV8ContextFileName, &path); |
| + return path; |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| } // namespace gin |