Commit 3a2cf9c4 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

[aw] Reorganize profile data on disk.

Set CACHE_DIR to WV-specific directory (WebView).
Folders under app_webview are moved into app_webview/Default.

HTTP Cache under cache/org.chromium.android_webview is moved into
cache/WebView/Default/HTTP Cache.

Bug: 963875
Change-Id: Ifa150fe0a40a775bc1705e1ac4ea355e67dbee0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793087
Commit-Queue: Anna Malova <amalova@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702833}
parent dbfe7b06
...@@ -58,7 +58,7 @@ public class WebViewApkApplication extends Application { ...@@ -58,7 +58,7 @@ public class WebViewApkApplication extends Application {
// Either "webview_service", or "webview_apk". // Either "webview_service", or "webview_apk".
// "webview_service" is meant to be very light-weight and never load the native library. // "webview_service" is meant to be very light-weight and never load the native library.
if (ContextUtils.getProcessName().contains(":webview_")) { if (ContextUtils.getProcessName().contains(":webview_")) {
PathUtils.setPrivateDataDirectorySuffix("webview"); PathUtils.setPrivateDataDirectorySuffix("webview", "WebView");
CommandLineUtil.initCommandLine(); CommandLineUtil.initCommandLine();
} }
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "base/base_paths_posix.h" #include "base/base_paths_posix.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -76,12 +77,56 @@ bool IgnoreOriginSecurityCheck(const GURL& url) { ...@@ -76,12 +77,56 @@ bool IgnoreOriginSecurityCheck(const GURL& url) {
return true; return true;
} }
void MigrateProfileData(base::FilePath cache_path,
base::FilePath context_storage_path) {
FilePath old_cache_path;
base::PathService::Get(base::DIR_CACHE, &old_cache_path);
old_cache_path = old_cache_path.DirName().Append(
FILE_PATH_LITERAL("org.chromium.android_webview"));
if (!base::PathExists(old_cache_path))
return;
bool success = base::CreateDirectory(cache_path);
if (success)
success &= base::Move(old_cache_path, cache_path);
DCHECK(success);
base::FilePath old_context_storage_path;
base::PathService::Get(base::DIR_ANDROID_APP_DATA, &old_context_storage_path);
if (!base::PathExists(context_storage_path)) {
base::CreateDirectory(context_storage_path);
}
auto migrate_context_storage_data = [&old_context_storage_path,
&context_storage_path](auto& suffix) {
if (base::PathExists(old_context_storage_path.Append(suffix))) {
bool success = base::Move(old_context_storage_path.Append(suffix),
context_storage_path.Append(suffix));
DCHECK(success);
}
};
migrate_context_storage_data("Web Data");
migrate_context_storage_data("Web Data-journal");
migrate_context_storage_data("GPUCache");
migrate_context_storage_data("blob_storage");
migrate_context_storage_data("Session Storage");
}
} // namespace } // namespace
AwBrowserContext::AwBrowserContext() AwBrowserContext::AwBrowserContext()
: context_storage_path_(GetContextStoragePath()), : context_storage_path_(GetContextStoragePath()),
simple_factory_key_(GetPath(), IsOffTheRecord()) { simple_factory_key_(GetPath(), IsOffTheRecord()) {
DCHECK(!g_browser_context); DCHECK(!g_browser_context);
if (IsDefaultBrowserContext()) {
MigrateProfileData(GetCacheDir(), GetContextStoragePath());
}
g_browser_context = this; g_browser_context = this;
SimpleKeyMap::GetInstance()->Associate(this, &simple_factory_key_); SimpleKeyMap::GetInstance()->Associate(this, &simple_factory_key_);
...@@ -131,8 +176,8 @@ base::FilePath AwBrowserContext::GetCacheDir() { ...@@ -131,8 +176,8 @@ base::FilePath AwBrowserContext::GetCacheDir() {
if (!base::PathService::Get(base::DIR_CACHE, &cache_path)) { if (!base::PathService::Get(base::DIR_CACHE, &cache_path)) {
NOTREACHED() << "Failed to get app cache directory for Android WebView"; NOTREACHED() << "Failed to get app cache directory for Android WebView";
} }
cache_path = cache_path = cache_path.Append(FILE_PATH_LITERAL("Default"))
cache_path.Append(FILE_PATH_LITERAL("org.chromium.android_webview")); .Append(FILE_PATH_LITERAL("HTTP Cache"));
return cache_path; return cache_path;
} }
...@@ -158,6 +203,7 @@ base::FilePath AwBrowserContext::GetContextStoragePath() { ...@@ -158,6 +203,7 @@ base::FilePath AwBrowserContext::GetContextStoragePath() {
NOTREACHED() << "Failed to get app data directory for Android WebView"; NOTREACHED() << "Failed to get app data directory for Android WebView";
} }
user_data_dir = user_data_dir.Append(FILE_PATH_LITERAL("Default"));
return user_data_dir; return user_data_dir;
} }
......
...@@ -18,14 +18,12 @@ bool PathProvider(int key, base::FilePath* result) { ...@@ -18,14 +18,12 @@ bool PathProvider(int key, base::FilePath* result) {
case DIR_CRASH_DUMPS: case DIR_CRASH_DUMPS:
if (!base::android::GetCacheDirectory(&cur)) if (!base::android::GetCacheDirectory(&cur))
return false; return false;
cur = cur.Append(FILE_PATH_LITERAL("WebView")) cur = cur.Append(FILE_PATH_LITERAL("Crashpad"));
.Append(FILE_PATH_LITERAL("Crashpad"));
break; break;
case DIR_SAFE_BROWSING: case DIR_SAFE_BROWSING:
if (!base::android::GetCacheDirectory(&cur)) if (!base::android::GetCacheDirectory(&cur))
return false; return false;
cur = cur.Append(FILE_PATH_LITERAL("WebView")) cur = cur.Append(FILE_PATH_LITERAL("SafeBrowsing"));
.Append(FILE_PATH_LITERAL("SafeBrowsing"));
break; break;
default: default:
return false; return false;
......
...@@ -76,7 +76,7 @@ public final class AwBrowserProcess { ...@@ -76,7 +76,7 @@ public final class AwBrowserProcess {
*/ */
public static void loadLibrary(String processDataDirSuffix) { public static void loadLibrary(String processDataDirSuffix) {
if (processDataDirSuffix == null) { if (processDataDirSuffix == null) {
PathUtils.setPrivateDataDirectorySuffix(WEBVIEW_DIR_BASENAME, null); PathUtils.setPrivateDataDirectorySuffix(WEBVIEW_DIR_BASENAME, "WebView");
} else { } else {
String processDataDirName = WEBVIEW_DIR_BASENAME + "_" + processDataDirSuffix; String processDataDirName = WEBVIEW_DIR_BASENAME + "_" + processDataDirSuffix;
PathUtils.setPrivateDataDirectorySuffix(processDataDirName, processDataDirName); PathUtils.setPrivateDataDirectorySuffix(processDataDirName, processDataDirName);
......
...@@ -44,7 +44,7 @@ public class OnDiskFileTest { ...@@ -44,7 +44,7 @@ public class OnDiskFileTest {
.getTargetContext() .getTargetContext()
.getCacheDir() .getCacheDir()
.getPath(), .getPath(),
"org.chromium.android_webview"); "WebView/Default/HTTP Cache");
FileUtils.recursivelyDeleteFile(webViewCacheDir); FileUtils.recursivelyDeleteFile(webViewCacheDir);
mActivityTestRule.startBrowserProcess(); mActivityTestRule.startBrowserProcess();
......
...@@ -23,7 +23,7 @@ public class AwShellApplication extends Application { ...@@ -23,7 +23,7 @@ public class AwShellApplication extends Application {
protected void attachBaseContext(Context context) { protected void attachBaseContext(Context context) {
super.attachBaseContext(context); super.attachBaseContext(context);
ContextUtils.initApplicationContext(this); ContextUtils.initApplicationContext(this);
PathUtils.setPrivateDataDirectorySuffix("webview"); PathUtils.setPrivateDataDirectorySuffix("webview", "WebView");
CommandLine.initFromFile("/data/local/tmp/android-webview-command-line"); CommandLine.initFromFile("/data/local/tmp/android-webview-command-line");
ResourceBundle.setAvailablePakLocales( ResourceBundle.setAvailablePakLocales(
new String[] {}, AwLocaleConfig.getWebViewSupportedPakLocales()); new String[] {}, AwLocaleConfig.getWebViewSupportedPakLocales());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment