Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: android_webview/browser/aw_browser_context.cc

Issue 23964011: Reuse webview classic cookies file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fix Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/android/java/src/org/chromium/base/PathUtils.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/aw_browser_context.h" 5 #include "android_webview/browser/aw_browser_context.h"
6 6
7 #include "android_webview/browser/aw_form_database_service.h" 7 #include "android_webview/browser/aw_form_database_service.h"
8 #include "android_webview/browser/aw_pref_store.h" 8 #include "android_webview/browser/aw_pref_store.h"
9 #include "android_webview/browser/aw_quota_manager_bridge.h" 9 #include "android_webview/browser/aw_quota_manager_bridge.h"
10 #include "android_webview/browser/jni_dependency_factory.h" 10 #include "android_webview/browser/jni_dependency_factory.h"
11 #include "android_webview/browser/net/aw_url_request_context_getter.h" 11 #include "android_webview/browser/net/aw_url_request_context_getter.h"
12 #include "android_webview/browser/net/init_native_callback.h" 12 #include "android_webview/browser/net/init_native_callback.h"
13 #include "base/android/path_utils.h"
14 #include "base/file_util.h"
15 #include "base/files/file_path.h"
13 #include "base/prefs/pref_registry_simple.h" 16 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
15 #include "base/prefs/pref_service_builder.h" 18 #include "base/prefs/pref_service_builder.h"
19 #include "base/sequenced_task_runner.h"
20 #include "base/threading/sequenced_worker_pool.h"
16 #include "components/autofill/core/common/autofill_pref_names.h" 21 #include "components/autofill/core/common/autofill_pref_names.h"
17 #include "components/user_prefs/user_prefs.h" 22 #include "components/user_prefs/user_prefs.h"
18 #include "components/visitedlink/browser/visitedlink_master.h" 23 #include "components/visitedlink/browser/visitedlink_master.h"
19 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/cookie_store_factory.h" 25 #include "content/public/browser/cookie_store_factory.h"
21 #include "content/public/browser/resource_context.h" 26 #include "content/public/browser/resource_context.h"
22 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
23 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
24 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
25 30
31 using base::FilePath;
26 using content::BrowserThread; 32 using content::BrowserThread;
27 33
28 namespace android_webview { 34 namespace android_webview {
29 35
30 namespace { 36 namespace {
31 37
32 // Shows notifications which correspond to PersistentPrefStore's reading errors. 38 // Shows notifications which correspond to PersistentPrefStore's reading errors.
33 void HandleReadError(PersistentPrefStore::PrefReadError error) { 39 void HandleReadError(PersistentPrefStore::PrefReadError error) {
34 } 40 }
35 41
(...skipping 22 matching lines...) Expand all
58 } 64 }
59 65
60 private: 66 private:
61 net::URLRequestContextGetter* getter_; 67 net::URLRequestContextGetter* getter_;
62 68
63 DISALLOW_COPY_AND_ASSIGN(AwResourceContext); 69 DISALLOW_COPY_AND_ASSIGN(AwResourceContext);
64 }; 70 };
65 71
66 AwBrowserContext* g_browser_context = NULL; 72 AwBrowserContext* g_browser_context = NULL;
67 73
74 void ImportLegacyCookieStore(const FilePath& cookie_store_path) {
75 // We use the old cookie store to create the new cookie store only if the
76 // new cookie store does not exist.
77 if (base::PathExists(cookie_store_path))
78 return;
79
80 // WebViewClassic gets the database path from Context and appends a
81 // hardcoded name. (see https://android.googlesource.com/platform/frameworks/b ase/+/bf6f6f9de72c9fd15e6bd/core/java/android/webkit/JniUtil.java and
82 // https://android.googlesource.com/platform/external/webkit/+/7151ed0c74599/S ource/WebKit/android/WebCoreSupport/WebCookieJar.cpp)
83 FilePath old_cookie_store_path;
84 base::android::GetDatabaseDirectory(&old_cookie_store_path);
85 old_cookie_store_path = old_cookie_store_path.Append(
86 FILE_PATH_LITERAL("webviewCookiesChromium.db"));
87 if (base::PathExists(old_cookie_store_path) &&
88 !base::Move(old_cookie_store_path, cookie_store_path)) {
89 LOG(WARNING) << "Failed to move old cookie store path from "
90 << old_cookie_store_path.AsUTF8Unsafe() << " to "
91 << cookie_store_path.AsUTF8Unsafe();
92 }
93 }
94
68 } // namespace 95 } // namespace
69 96
70 AwBrowserContext::AwBrowserContext( 97 AwBrowserContext::AwBrowserContext(
71 const base::FilePath path, 98 const FilePath path,
72 JniDependencyFactory* native_factory) 99 JniDependencyFactory* native_factory)
73 : context_storage_path_(path), 100 : context_storage_path_(path),
74 native_factory_(native_factory), 101 native_factory_(native_factory),
75 user_pref_service_ready_(false) { 102 user_pref_service_ready_(false) {
76 DCHECK(g_browser_context == NULL); 103 DCHECK(g_browser_context == NULL);
77 g_browser_context = this; 104 g_browser_context = this;
78 105
79 // This constructor is entered during the creation of ContentBrowserClient, 106 // This constructor is entered during the creation of ContentBrowserClient,
80 // before browser threads are created. Therefore any checks to enforce 107 // before browser threads are created. Therefore any checks to enforce
81 // threading (such as BrowserThread::CurrentlyOn()) will fail here. 108 // threading (such as BrowserThread::CurrentlyOn()) will fail here.
(...skipping 12 matching lines...) Expand all
94 } 121 }
95 122
96 // static 123 // static
97 AwBrowserContext* AwBrowserContext::FromWebContents( 124 AwBrowserContext* AwBrowserContext::FromWebContents(
98 content::WebContents* web_contents) { 125 content::WebContents* web_contents) {
99 // This is safe; this is the only implementation of the browser context. 126 // This is safe; this is the only implementation of the browser context.
100 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); 127 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext());
101 } 128 }
102 129
103 void AwBrowserContext::PreMainMessageLoopRun() { 130 void AwBrowserContext::PreMainMessageLoopRun() {
131
132 FilePath cookie_store_path = GetPath().Append(FILE_PATH_LITERAL("Cookies"));
133 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
134 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
135 BrowserThread::GetBlockingPool()->GetSequenceToken());
136
137 background_task_runner->PostTask(
138 FROM_HERE,
139 base::Bind(ImportLegacyCookieStore, cookie_store_path));
140
104 cookie_store_ = content::CreatePersistentCookieStore( 141 cookie_store_ = content::CreatePersistentCookieStore(
105 GetPath().Append(FILE_PATH_LITERAL("Cookies")), 142 cookie_store_path,
106 true, 143 true,
107 NULL, 144 NULL,
108 NULL); 145 NULL,
146 background_task_runner);
147
109 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); 148 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true);
110 url_request_context_getter_ = 149 url_request_context_getter_ =
111 new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); 150 new AwURLRequestContextGetter(GetPath(), cookie_store_.get());
112 151
113 DidCreateCookieMonster(cookie_store_->GetCookieMonster()); 152 DidCreateCookieMonster(cookie_store_->GetCookieMonster());
114 153
115 visitedlink_master_.reset( 154 visitedlink_master_.reset(
116 new visitedlink::VisitedLinkMaster(this, this, false)); 155 new visitedlink::VisitedLinkMaster(this, this, false));
117 visitedlink_master_->Init(); 156 visitedlink_master_->Init();
118 157
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 297
259 void AwBrowserContext::RebuildTable( 298 void AwBrowserContext::RebuildTable(
260 const scoped_refptr<URLEnumerator>& enumerator) { 299 const scoped_refptr<URLEnumerator>& enumerator) {
261 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client 300 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client
262 // can change in the lifetime of this WebView and may not yet be set here. 301 // can change in the lifetime of this WebView and may not yet be set here.
263 // Therefore this initialization path is not used. 302 // Therefore this initialization path is not used.
264 enumerator->OnComplete(true); 303 enumerator->OnComplete(true);
265 } 304 }
266 305
267 } // namespace android_webview 306 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | base/android/java/src/org/chromium/base/PathUtils.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698