| OLD | NEW |
| 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" | 13 #include "base/android/path_utils.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/prefs/pref_service_builder.h" | 18 #include "base/prefs/pref_service_factory.h" |
| 19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 21 #include "components/autofill/core/common/autofill_pref_names.h" | 21 #include "components/autofill/core/common/autofill_pref_names.h" |
| 22 #include "components/user_prefs/user_prefs.h" | 22 #include "components/user_prefs/user_prefs.h" |
| 23 #include "components/visitedlink/browser/visitedlink_master.h" | 23 #include "components/visitedlink/browser/visitedlink_master.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/cookie_store_factory.h" | 25 #include "content/public/browser/cookie_store_factory.h" |
| 26 #include "content/public/browser/resource_context.h" | 26 #include "content/public/browser/resource_context.h" |
| 27 #include "content/public/browser/storage_partition.h" | 27 #include "content/public/browser/storage_partition.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 << cookie_store_path.AsUTF8Unsafe(); | 91 << cookie_store_path.AsUTF8Unsafe(); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 AwBrowserContext::AwBrowserContext( | 97 AwBrowserContext::AwBrowserContext( |
| 98 const FilePath path, | 98 const FilePath path, |
| 99 JniDependencyFactory* native_factory) | 99 JniDependencyFactory* native_factory) |
| 100 : context_storage_path_(path), | 100 : context_storage_path_(path), |
| 101 native_factory_(native_factory), | 101 native_factory_(native_factory) { |
| 102 user_pref_service_ready_(false) { | |
| 103 DCHECK(g_browser_context == NULL); | 102 DCHECK(g_browser_context == NULL); |
| 104 g_browser_context = this; | 103 g_browser_context = this; |
| 105 | 104 |
| 106 // This constructor is entered during the creation of ContentBrowserClient, | 105 // This constructor is entered during the creation of ContentBrowserClient, |
| 107 // before browser threads are created. Therefore any checks to enforce | 106 // before browser threads are created. Therefore any checks to enforce |
| 108 // threading (such as BrowserThread::CurrentlyOn()) will fail here. | 107 // threading (such as BrowserThread::CurrentlyOn()) will fail here. |
| 109 } | 108 } |
| 110 | 109 |
| 111 AwBrowserContext::~AwBrowserContext() { | 110 AwBrowserContext::~AwBrowserContext() { |
| 112 DCHECK(g_browser_context == this); | 111 DCHECK(g_browser_context == this); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 191 } |
| 193 return quota_manager_bridge_.get(); | 192 return quota_manager_bridge_.get(); |
| 194 } | 193 } |
| 195 | 194 |
| 196 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 195 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
| 197 return form_database_service_.get(); | 196 return form_database_service_.get(); |
| 198 } | 197 } |
| 199 | 198 |
| 200 // Create user pref service for autofill functionality. | 199 // Create user pref service for autofill functionality. |
| 201 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 200 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
| 202 if (user_pref_service_ready_) | 201 if (user_pref_service_) |
| 203 return; | 202 return; |
| 204 | 203 |
| 205 user_pref_service_ready_ = true; | |
| 206 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | 204 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); |
| 207 // We only use the autocomplete feature of the Autofill, which is | 205 // We only use the autocomplete feature of the Autofill, which is |
| 208 // controlled via the manager_delegate. We don't use the rest | 206 // controlled via the manager_delegate. We don't use the rest |
| 209 // of autofill, which is why it is hardcoded as disabled here. | 207 // of autofill, which is why it is hardcoded as disabled here. |
| 210 pref_registry->RegisterBooleanPref( | 208 pref_registry->RegisterBooleanPref( |
| 211 autofill::prefs::kAutofillEnabled, false); | 209 autofill::prefs::kAutofillEnabled, false); |
| 212 pref_registry->RegisterDoublePref( | 210 pref_registry->RegisterDoublePref( |
| 213 autofill::prefs::kAutofillPositiveUploadRate, 0.0); | 211 autofill::prefs::kAutofillPositiveUploadRate, 0.0); |
| 214 pref_registry->RegisterDoublePref( | 212 pref_registry->RegisterDoublePref( |
| 215 autofill::prefs::kAutofillNegativeUploadRate, 0.0); | 213 autofill::prefs::kAutofillNegativeUploadRate, 0.0); |
| 216 | 214 |
| 217 PrefServiceBuilder pref_service_builder; | 215 base::PrefServiceFactory pref_service_factory; |
| 218 pref_service_builder.WithUserPrefs(new AwPrefStore()); | 216 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); |
| 219 pref_service_builder.WithReadErrorCallback(base::Bind(&HandleReadError)); | 217 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
| 218 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
| 220 | 219 |
| 221 user_prefs::UserPrefs::Set(this, | 220 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
| 222 pref_service_builder.Create(pref_registry)); | |
| 223 } | 221 } |
| 224 | 222 |
| 225 base::FilePath AwBrowserContext::GetPath() const { | 223 base::FilePath AwBrowserContext::GetPath() const { |
| 226 return context_storage_path_; | 224 return context_storage_path_; |
| 227 } | 225 } |
| 228 | 226 |
| 229 bool AwBrowserContext::IsOffTheRecord() const { | 227 bool AwBrowserContext::IsOffTheRecord() const { |
| 230 // Android WebView does not support off the record profile yet. | 228 // Android WebView does not support off the record profile yet. |
| 231 return false; | 229 return false; |
| 232 } | 230 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 303 |
| 306 void AwBrowserContext::RebuildTable( | 304 void AwBrowserContext::RebuildTable( |
| 307 const scoped_refptr<URLEnumerator>& enumerator) { | 305 const scoped_refptr<URLEnumerator>& enumerator) { |
| 308 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 306 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
| 309 // can change in the lifetime of this WebView and may not yet be set here. | 307 // can change in the lifetime of this WebView and may not yet be set here. |
| 310 // Therefore this initialization path is not used. | 308 // Therefore this initialization path is not used. |
| 311 enumerator->OnComplete(true); | 309 enumerator->OnComplete(true); |
| 312 } | 310 } |
| 313 | 311 |
| 314 } // namespace android_webview | 312 } // namespace android_webview |
| OLD | NEW |