summaryrefslogtreecommitdiffstats
path: root/gin
diff options
context:
space:
mode:
authoragrieve <agrieve@chromium.org>2015-06-19 09:49:06 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-19 16:49:44 +0000
commit6f3002d9e87d690bb368931faa2c3ba4638f811e (patch)
tree2b98bfa95368ec2bffcbe583a4bbeca5ab38a884 /gin
parent5ec519daa7bd0d2285d7a61b808e44b86aacb0a8 (diff)
downloadchromium_src-6f3002d9e87d690bb368931faa2c3ba4638f811e.zip
chromium_src-6f3002d9e87d690bb368931faa2c3ba4638f811e.tar.gz
chromium_src-6f3002d9e87d690bb368931faa2c3ba4638f811e.tar.bz2
Load V8 startup data directly from the APK on Android.
Startup data files are now stored uncompressed within the .apk, increasing size of the apk, but decreasing total disk requirements (since they don't need to be extracted). BUG=394502 Review URL: https://codereview.chromium.org/1156873002 Cr-Commit-Position: refs/heads/master@{#335271}
Diffstat (limited to 'gin')
-rw-r--r--gin/v8_initializer.cc40
1 files changed, 22 insertions, 18 deletions
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc
index cc854e1..a82209f 100644
--- a/gin/v8_initializer.cc
+++ b/gin/v8_initializer.cc
@@ -19,6 +19,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,29 +53,20 @@ base::PlatformFile g_snapshot_pf = kInvalidPlatformFile;
base::MemoryMappedFile::Region g_natives_region;
base::MemoryMappedFile::Region g_snapshot_region;
-#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";
-// Constants for snapshot loading retries taken from:
-// https://support.microsoft.com/en-us/kb/316609.
-const int kMaxOpenAttempts = 5;
-const int kOpenRetryDelayMillis = 250;
-
void GetV8FilePath(const char* file_name, base::FilePath* path_out) {
#if !defined(OS_MACOSX)
base::FilePath data_path;
- PathService::Get(kV8SnapshotBasePathKey, &data_path);
+#if defined(OS_ANDROID)
+ // This is the path within the .apk.
+ data_path = base::FilePath(FILE_PATH_LITERAL("assets"));
+#elif defined(OS_POSIX)
+ PathService::Get(base::DIR_EXE, &data_path);
+#elif defined(OS_WIN)
+ PathService::Get(base::DIR_MODULE, &data_path);
+#endif
DCHECK(!data_path.empty());
*path_out = data_path.AppendASCII(file_name);
@@ -109,10 +103,19 @@ base::PlatformFile OpenV8File(const char* file_name,
FAILED_OTHER,
MAX_VALUE
};
-
base::FilePath path;
GetV8FilePath(file_name, &path);
+#if defined(OS_ANDROID)
+ base::File file(base::android::OpenApkAsset(path.value(), 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;
+
OpenV8FileResult result = OpenV8FileResult::FAILED_IN_USE;
int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
base::File file;
@@ -146,6 +149,7 @@ base::PlatformFile OpenV8File(const char* file_name,
base::TimeDelta::FromMilliseconds(kOpenRetryDelayMillis));
}
}
+#endif // defined(OS_ANDROID)
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result",
result,