Index: gin/v8_initializer.cc |
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc |
index 1e1bd8dc6e865d10b73a4c68d064e271a5bdcfc0..2146c3fcbb65074e8d60df3f1abc6bdabebae090 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 |
@@ -35,25 +38,24 @@ base::File* g_snapshot_file = nullptr; |
base::MemoryMappedFile::Region g_natives_region; |
base::MemoryMappedFile::Region g_snapshot_region; |
-#if !defined(OS_MACOSX) |
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
const int kV8SnapshotBasePathKey = |
-#if defined(OS_ANDROID) |
- base::DIR_ANDROID_APP_DATA; |
-#elif defined(OS_POSIX) |
+#if defined(OS_POSIX) |
base::DIR_EXE; |
#elif defined(OS_WIN) |
base::DIR_MODULE; |
-#endif // OS_ANDROID |
-#endif // !OS_MACOSX |
+#endif // defined(OS_POSIX) |
+#endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) |
+#if defined(OS_ANDROID) |
+const char kNativesFileName[] = "assets/natives_blob.bin"; |
+const char kSnapshotFileName[] = "assets/snapshot_blob.bin"; |
rmcilroy
2015/06/15 10:21:02
this is effective the file path (within the APK) n
agrieve
2015/06/15 14:22:04
Done.
|
+#else |
const char kNativesFileName[] = "natives_blob.bin"; |
const char kSnapshotFileName[] = "snapshot_blob.bin"; |
+#endif // defined(OS_ANDROID) |
-// Constants for snapshot loading retries taken from: |
-// https://support.microsoft.com/en-us/kb/316609. |
-const int kMaxOpenAttempts = 5; |
-const int kOpenRetryDelayMillis = 250; |
- |
+#if !defined(OS_ANDROID) |
void GetV8FilePath(const char* file_name, base::FilePath* path_out) { |
#if !defined(OS_MACOSX) |
base::FilePath data_path; |
@@ -68,6 +70,7 @@ void GetV8FilePath(const char* file_name, base::FilePath* path_out) { |
#endif // !defined(OS_MACOSX) |
DCHECK(!path_out->empty()); |
} |
+#endif // !defined(OS_ANDROID) |
static bool MapV8File(base::File file, |
base::MemoryMappedFile::Region region, |
@@ -86,9 +89,6 @@ static bool MapV8File(base::File file, |
base::File OpenV8File(const char* file_name, |
base::MemoryMappedFile::Region* region_out) { |
- // Re-try logic here is motivated by http://crbug.com/479537 |
- // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). |
- |
// These match tools/metrics/histograms.xml |
enum OpenV8FileResult { |
OPENED = 0, |
@@ -97,6 +97,15 @@ base::File OpenV8File(const char* file_name, |
FAILED_OTHER, |
MAX_VALUE |
}; |
+#if defined(OS_ANDROID) |
+ base::File file(base::android::OpenApkAsset(file_name, region_out)); |
+ OpenV8FileResult result = file.IsValid() ? OpenV8FileResult::OPENED |
+ : OpenV8FileResult::FAILED_OTHER; |
+#else |
+ // Re-try logic here is motivated by http://crbug.com/479537 |
+ // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). |
+ const int kMaxOpenAttempts = 5; |
+ const int kOpenRetryDelayMillis = 250; |
base::FilePath path; |
GetV8FilePath(file_name, &path); |
@@ -123,6 +132,7 @@ base::File OpenV8File(const char* file_name, |
base::TimeDelta::FromMilliseconds(kOpenRetryDelayMillis)); |
} |
} |
+#endif // defined(OS_ANDROID) |
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", |
result, |