diff options
-rw-r--r-- | android_webview/browser/aw_browser_context.cc | 45 | ||||
-rw-r--r-- | base/android/java/src/org/chromium/base/PathUtils.java | 9 | ||||
-rw-r--r-- | base/android/path_utils.cc | 9 | ||||
-rw-r--r-- | base/android/path_utils.h | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.cc | 9 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.cc | 3 | ||||
-rw-r--r-- | content/browser/net/sqlite_persistent_cookie_store.cc | 8 | ||||
-rw-r--r-- | content/public/browser/cookie_store_factory.h | 6 |
8 files changed, 82 insertions, 11 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 6b52f8a..97978ca 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -10,9 +10,14 @@ #include "android_webview/browser/jni_dependency_factory.h" #include "android_webview/browser/net/aw_url_request_context_getter.h" #include "android_webview/browser/net/init_native_callback.h" +#include "base/android/path_utils.h" +#include "base/file_util.h" +#include "base/files/file_path.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/prefs/pref_service_builder.h" +#include "base/sequenced_task_runner.h" +#include "base/threading/sequenced_worker_pool.h" #include "components/autofill/core/common/autofill_pref_names.h" #include "components/user_prefs/user_prefs.h" #include "components/visitedlink/browser/visitedlink_master.h" @@ -23,6 +28,7 @@ #include "content/public/browser/web_contents.h" #include "net/url_request/url_request_context.h" +using base::FilePath; using content::BrowserThread; namespace android_webview { @@ -65,10 +71,31 @@ class AwResourceContext : public content::ResourceContext { AwBrowserContext* g_browser_context = NULL; +void ImportLegacyCookieStore(const FilePath& cookie_store_path) { + // We use the old cookie store to create the new cookie store only if the + // new cookie store does not exist. + if (base::PathExists(cookie_store_path)) + return; + + // WebViewClassic gets the database path from Context and appends a + // hardcoded name. (see https://android.googlesource.com/platform/frameworks/base/+/bf6f6f9de72c9fd15e6bd/core/java/android/webkit/JniUtil.java and + // https://android.googlesource.com/platform/external/webkit/+/7151ed0c74599/Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp) + FilePath old_cookie_store_path; + base::android::GetDatabaseDirectory(&old_cookie_store_path); + old_cookie_store_path = old_cookie_store_path.Append( + FILE_PATH_LITERAL("webviewCookiesChromium.db")); + if (base::PathExists(old_cookie_store_path) && + !base::Move(old_cookie_store_path, cookie_store_path)) { + LOG(WARNING) << "Failed to move old cookie store path from " + << old_cookie_store_path.AsUTF8Unsafe() << " to " + << cookie_store_path.AsUTF8Unsafe(); + } +} + } // namespace AwBrowserContext::AwBrowserContext( - const base::FilePath path, + const FilePath path, JniDependencyFactory* native_factory) : context_storage_path_(path), native_factory_(native_factory), @@ -101,11 +128,23 @@ AwBrowserContext* AwBrowserContext::FromWebContents( } void AwBrowserContext::PreMainMessageLoopRun() { + + FilePath cookie_store_path = GetPath().Append(FILE_PATH_LITERAL("Cookies")); + scoped_refptr<base::SequencedTaskRunner> background_task_runner = + BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( + BrowserThread::GetBlockingPool()->GetSequenceToken()); + + background_task_runner->PostTask( + FROM_HERE, + base::Bind(ImportLegacyCookieStore, cookie_store_path)); + cookie_store_ = content::CreatePersistentCookieStore( - GetPath().Append(FILE_PATH_LITERAL("Cookies")), + cookie_store_path, true, NULL, - NULL); + NULL, + background_task_runner); + cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); url_request_context_getter_ = new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); diff --git a/base/android/java/src/org/chromium/base/PathUtils.java b/base/android/java/src/org/chromium/base/PathUtils.java index aee5c05..e8a89e7 100644 --- a/base/android/java/src/org/chromium/base/PathUtils.java +++ b/base/android/java/src/org/chromium/base/PathUtils.java @@ -56,6 +56,15 @@ public abstract class PathUtils { } /** + * @return the private directory that is used to store application database. + */ + @CalledByNative + public static String getDatabaseDirectory(Context appContext) { + // Context.getDatabasePath() returns path for the provided filename. + return appContext.getDatabasePath("foo").getParent(); + } + + /** * @return the cache directory. */ @SuppressWarnings("unused") diff --git a/base/android/path_utils.cc b/base/android/path_utils.cc index 5737227..c98007c 100644 --- a/base/android/path_utils.cc +++ b/base/android/path_utils.cc @@ -23,6 +23,15 @@ bool GetDataDirectory(FilePath* result) { return true; } +bool GetDatabaseDirectory(FilePath* result) { + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jstring> path = + Java_PathUtils_getDatabaseDirectory(env, GetApplicationContext()); + FilePath data_path(ConvertJavaStringToUTF8(path)); + *result = data_path; + return true; +} + bool GetCacheDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jstring> path = diff --git a/base/android/path_utils.h b/base/android/path_utils.h index 60f8a79..d3421b3 100644 --- a/base/android/path_utils.h +++ b/base/android/path_utils.h @@ -21,6 +21,10 @@ namespace android { // PathService::Get(base::DIR_ANDROID_APP_DATA, ...) gets the data dir. BASE_EXPORT bool GetDataDirectory(FilePath* result); +// Retrieves the absolute path to the database directory that Android +// framework's SQLiteDatabase class uses when creating database files. +BASE_EXPORT bool GetDatabaseDirectory(FilePath* result); + // Retrieves the absolute path to the cache directory. The result is placed in // the FilePath pointed to by 'result'. This method is dedicated for // base_paths_android.c, Using PathService::Get(base::DIR_CACHE, ...) gets the diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index fd8149c..a096dd1 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -387,7 +387,8 @@ void ProfileImplIOData::InitializeInternal( lazy_params_->cookie_path, lazy_params_->restore_old_session_cookies, lazy_params_->special_storage_policy.get(), - profile_params->cookie_monster_delegate.get()); + profile_params->cookie_monster_delegate.get(), + scoped_refptr<base::SequencedTaskRunner>()); cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); } @@ -482,7 +483,8 @@ void ProfileImplIOData:: lazy_params_->extensions_cookie_path, lazy_params_->restore_old_session_cookies, NULL, - NULL); + NULL, + scoped_refptr<base::SequencedTaskRunner>()); // Enable cookies for devtools and extension URLs. const char* schemes[] = {chrome::kChromeDevToolsScheme, extensions::kExtensionScheme}; @@ -568,7 +570,8 @@ ProfileImplIOData::InitializeAppRequestContext( cookie_path, false, NULL, - NULL); + NULL, + scoped_refptr<base::SequencedTaskRunner>()); } // Transfer ownership of the cookies and cache to AppRequestContext. diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 6d3604d..4cceba8 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -307,7 +307,8 @@ void SafeBrowsingService::InitURLRequestContextOnIOThread( CookieFilePath(), false, NULL, - NULL)); + NULL, + scoped_refptr<base::SequencedTaskRunner>())); url_request_context_.reset(new net::URLRequestContext); // |system_url_request_context_getter| may be NULL during tests. diff --git a/content/browser/net/sqlite_persistent_cookie_store.cc b/content/browser/net/sqlite_persistent_cookie_store.cc index c23692d..517a8c1 100644 --- a/content/browser/net/sqlite_persistent_cookie_store.cc +++ b/content/browser/net/sqlite_persistent_cookie_store.cc @@ -1198,13 +1198,15 @@ net::CookieStore* CreatePersistentCookieStore( const base::FilePath& path, bool restore_old_session_cookies, quota::SpecialStoragePolicy* storage_policy, - net::CookieMonster::Delegate* cookie_monster_delegate) { + net::CookieMonster::Delegate* cookie_monster_delegate, + const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) { SQLitePersistentCookieStore* persistent_store = new SQLitePersistentCookieStore( path, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( - BrowserThread::GetBlockingPool()->GetSequenceToken()), + background_task_runner.get() ? background_task_runner : + BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( + BrowserThread::GetBlockingPool()->GetSequenceToken()), restore_old_session_cookies, storage_policy); net::CookieMonster* cookie_monster = diff --git a/content/public/browser/cookie_store_factory.h b/content/public/browser/cookie_store_factory.h index c7a9c6e..22de97d 100644 --- a/content/public/browser/cookie_store_factory.h +++ b/content/public/browser/cookie_store_factory.h @@ -18,11 +18,15 @@ class SpecialStoragePolicy; namespace content { +// All blocking database accesses will be performed on |background_task_runner|. +// If background_task_runner is NULL, then a background task runner will be +// created internally. CONTENT_EXPORT net::CookieStore* CreatePersistentCookieStore( const base::FilePath& path, bool restore_old_session_cookies, quota::SpecialStoragePolicy* storage_policy, - net::CookieMonster::Delegate* cookie_monster_delegate); + net::CookieMonster::Delegate* cookie_monster_delegate, + const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); } // namespace content |