Index: gin/v8_initializer.cc |
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc |
index ca0e3efd3b47b9000299f514e4e59e88ffa8134d..56011d9ff5be2e8152d01c7f41249dad6d441cc4 100644 |
--- a/gin/v8_initializer.cc |
+++ b/gin/v8_initializer.cc |
@@ -18,20 +18,20 @@ |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/metrics/histogram_macros.h" |
-#include "base/path_service.h" |
#include "base/rand_util.h" |
#include "base/strings/sys_string_conversions.h" |
#include "base/sys_info.h" |
#include "base/threading/platform_thread.h" |
#include "base/time/time.h" |
-#include "build/build_config.h" |
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
#if defined(OS_ANDROID) |
#include "base/android/apk_assets.h" |
-#elif defined(OS_MACOSX) |
+#endif |
+#if defined(OS_MACOSX) |
#include "base/mac/foundation_util.h" |
-#endif |
+#endif // OS_MACOSX |
+#include "base/path_service.h" |
#endif // V8_USE_EXTERNAL_STARTUP_DATA |
namespace gin { |
@@ -41,17 +41,16 @@ |
// 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_v8_context_snapshot = nullptr; |
- |
-const char kV8ContextSnapshotFileName[] = "v8_context_snapshot.bin"; |
+ |
+#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
// File handles intentionally never closed. Not using File here because its |
// Windows implementation guards against two instances owning the same |
// PlatformFile (which we allow since we know it is never freed). |
-using OpenedFileMap = |
- std::map<const char*, |
- std::pair<base::PlatformFile, base::MemoryMappedFile::Region>>; |
-base::LazyInstance<OpenedFileMap>::Leaky g_opened_files = |
+typedef std::map<const char*, |
+ std::pair<base::PlatformFile, base::MemoryMappedFile::Region>> |
+ OpenedFileMap; |
+static base::LazyInstance<OpenedFileMap>::Leaky g_opened_files = |
LAZY_INSTANCE_INITIALIZER; |
OpenedFileMap::mapped_type& GetOpenedFile(const char* file) { |
@@ -63,8 +62,6 @@ |
return opened_files[file]; |
} |
-#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
- |
const char kNativesFileName[] = "natives_blob.bin"; |
#if defined(OS_ANDROID) |
@@ -80,8 +77,6 @@ |
#else // defined(OS_ANDROID) |
const char kSnapshotFileName[] = "snapshot_blob.bin"; |
#endif // defined(OS_ANDROID) |
- |
-#endif // defined(V8_USE_EXTERNAL_STATUP_DATA) |
void GetV8FilePath(const char* file_name, base::FilePath* path_out) { |
#if !defined(OS_MACOSX) |
@@ -102,11 +97,12 @@ |
base::SysUTF8ToCFStringRef(file_name)); |
*path_out = base::mac::PathForFrameworkBundleResource(natives_file_name); |
#endif // !defined(OS_MACOSX) |
-} |
- |
-bool MapV8File(base::PlatformFile platform_file, |
- base::MemoryMappedFile::Region region, |
- base::MemoryMappedFile** mmapped_file_out) { |
+ DCHECK(!path_out->empty()); |
+} |
+ |
+static bool MapV8File(base::PlatformFile platform_file, |
+ base::MemoryMappedFile::Region region, |
+ base::MemoryMappedFile** mmapped_file_out) { |
DCHECK(*mmapped_file_out == NULL); |
std::unique_ptr<base::MemoryMappedFile> mmapped_file( |
new base::MemoryMappedFile()); |
@@ -184,7 +180,8 @@ |
return file.TakePlatformFile(); |
} |
-const OpenedFileMap::mapped_type OpenFileIfNecessary(const char* file_name) { |
+static const OpenedFileMap::mapped_type OpenFileIfNecessary( |
+ const char* file_name) { |
OpenedFileMap::mapped_type& opened = GetOpenedFile(file_name); |
if (opened.first == base::kInvalidPlatformFile) { |
opened.first = OpenV8File(file_name, &opened.second); |
@@ -192,10 +189,18 @@ |
return opened; |
} |
+#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) |
+ |
+namespace { |
enum LoadV8FileResult { |
V8_LOAD_SUCCESS = 0, |
@@ -205,8 +210,9 @@ |
V8_LOAD_MAX_VALUE |
}; |
-LoadV8FileResult MapOpenedFile(const OpenedFileMap::mapped_type& file_region, |
- base::MemoryMappedFile** mmapped_file_out) { |
+static LoadV8FileResult MapOpenedFile( |
+ const OpenedFileMap::mapped_type& file_region, |
+ base::MemoryMappedFile** mmapped_file_out) { |
if (file_region.first == base::kInvalidPlatformFile) |
return V8_LOAD_FAILED_OPEN; |
if (!MapV8File(file_region.first, file_region.second, mmapped_file_out)) |
@@ -215,8 +221,6 @@ |
} |
} // namespace |
- |
-#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
// static |
void V8Initializer::LoadV8Snapshot() { |
@@ -366,7 +370,7 @@ |
natives.raw_size = static_cast<int>(g_mapped_natives->length()); |
v8::V8::SetNativesDataBlob(&natives); |
- if (g_mapped_snapshot) { |
+ if (g_mapped_snapshot != NULL) { |
v8::StartupData snapshot; |
snapshot.data = reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
snapshot.raw_size = static_cast<int>(g_mapped_snapshot->length()); |
@@ -402,51 +406,4 @@ |
} |
} |
-// static |
-void V8Initializer::LoadV8ContextSnapshot() { |
- if (g_mapped_v8_context_snapshot) |
- return; |
- |
- OpenFileIfNecessary(kV8ContextSnapshotFileName); |
- MapOpenedFile(GetOpenedFile(kV8ContextSnapshotFileName), |
- &g_mapped_v8_context_snapshot); |
- |
- // TODO(peria): Check if the snapshot file is loaded successfully. |
-} |
- |
-// static |
-void V8Initializer::LoadV8ContextSnapshotFromFD(base::PlatformFile snapshot_pf, |
- int64_t snapshot_offset, |
- int64_t snapshot_size) { |
- if (g_mapped_v8_context_snapshot) |
- return; |
- CHECK_NE(base::kInvalidPlatformFile, snapshot_pf); |
- |
- 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; |
- } |
- |
- if (MapV8File(snapshot_pf, snapshot_region, &g_mapped_v8_context_snapshot)) { |
- g_opened_files.Get()[kV8ContextSnapshotFileName] = |
- std::make_pair(snapshot_pf, snapshot_region); |
- } |
-} |
- |
-// static |
-void V8Initializer::GetV8ContextSnapshotData(const char** snapshot_data_out, |
- int* snapshot_size_out) { |
- if (g_mapped_v8_context_snapshot) { |
- *snapshot_data_out = |
- reinterpret_cast<const char*>(g_mapped_v8_context_snapshot->data()); |
- *snapshot_size_out = |
- static_cast<int>(g_mapped_v8_context_snapshot->length()); |
- } else { |
- *snapshot_data_out = nullptr; |
- *snapshot_size_out = 0; |
- } |
-} |
- |
} // namespace gin |