Chromium Code Reviews| 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/aw_resource_context.h" | 10 #include "android_webview/browser/aw_resource_context.h" |
| 11 #include "android_webview/browser/jni_dependency_factory.h" | 11 #include "android_webview/browser/jni_dependency_factory.h" |
| 12 #include "android_webview/browser/net/aw_url_request_context_getter.h" | 12 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
| 13 #include "android_webview/browser/net/init_native_callback.h" | 13 #include "android_webview/browser/net/init_native_callback.h" |
| 14 #include "base/base_paths_android.h" | 14 #include "base/base_paths_android.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/prefs/pref_registry_simple.h" | 17 #include "base/prefs/pref_registry_simple.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/prefs/pref_service_factory.h" | 19 #include "base/prefs/pref_service_factory.h" |
| 20 #include "components/autofill/core/common/autofill_pref_names.h" | 20 #include "components/autofill/core/common/autofill_pref_names.h" |
| 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" |
| 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref s.h" | 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref s.h" |
| 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" |
| 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat istics_prefs.h" | |
| 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h" | |
| 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 27 #include "components/user_prefs/user_prefs.h" | 25 #include "components/user_prefs/user_prefs.h" |
| 28 #include "components/visitedlink/browser/visitedlink_master.h" | 26 #include "components/visitedlink/browser/visitedlink_master.h" |
| 29 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/ssl_host_state_delegate.h" | 28 #include "content/public/browser/ssl_host_state_delegate.h" |
| 31 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
| 32 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 33 #include "net/cookies/cookie_store.h" | 31 #include "net/cookies/cookie_store.h" |
| 34 #include "net/proxy/proxy_config_service_android.h" | 32 #include "net/proxy/proxy_config_service_android.h" |
| 35 #include "net/proxy/proxy_service.h" | 33 #include "net/proxy/proxy_service.h" |
| 36 | 34 |
| 37 using base::FilePath; | 35 using base::FilePath; |
| 38 using content::BrowserThread; | 36 using content::BrowserThread; |
| 39 using data_reduction_proxy::DataReductionProxyConfigurator; | 37 |
| 40 using data_reduction_proxy::DataReductionProxyEventStore; | 38 namespace data_reduction_proxy { |
| 41 using data_reduction_proxy::DataReductionProxySettings; | 39 class DataReductionProxyConfigurator; |
| 40 class DataReductionProxyStatisticsPrefs; | |
| 41 } | |
| 42 | 42 |
| 43 namespace android_webview { | 43 namespace android_webview { |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 47 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
| 48 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 48 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 void DeleteDirRecursively(const base::FilePath& path) { | 51 void DeleteDirRecursively(const base::FilePath& path) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 // static | 111 // static |
| 112 void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { | 112 void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { |
| 113 // Cache the setting value. It is possible that data reduction proxy is | 113 // Cache the setting value. It is possible that data reduction proxy is |
| 114 // not created yet. | 114 // not created yet. |
| 115 data_reduction_proxy_enabled_ = enabled; | 115 data_reduction_proxy_enabled_ = enabled; |
| 116 AwBrowserContext* context = AwBrowserContext::GetDefault(); | 116 AwBrowserContext* context = AwBrowserContext::GetDefault(); |
| 117 // Can't enable Data reduction proxy if user pref service is not ready. | 117 // Can't enable Data reduction proxy if user pref service is not ready. |
| 118 if (context == NULL || context->user_pref_service_.get() == NULL) | 118 if (context == NULL || context->user_pref_service_.get() == NULL) |
| 119 return; | 119 return; |
| 120 DataReductionProxySettings* proxy_settings = | 120 data_reduction_proxy::DataReductionProxySettings* proxy_settings = |
| 121 context->GetDataReductionProxySettings(); | 121 context->GetDataReductionProxySettings(); |
| 122 if (proxy_settings == NULL) | 122 if (proxy_settings == NULL) |
| 123 return; | 123 return; |
| 124 | 124 // At this point, context->PreMainMessageLoopRun() has run, so |
| 125 // context->data_reduction_proxy_io_data() is valid. | |
| 126 DCHECK(context->GetDataReductionProxyIOData()); | |
| 125 context->CreateDataReductionProxyStatisticsIfNecessary(); | 127 context->CreateDataReductionProxyStatisticsIfNecessary(); |
| 126 proxy_settings->SetDataReductionProxyStatisticsPrefs( | 128 proxy_settings->SetDataReductionProxyStatisticsPrefs( |
| 127 context->data_reduction_proxy_statistics_.get()); | 129 context->GetDataReductionProxyIOData()->statistics_prefs()); |
| 128 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 130 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // static | 133 // static |
| 132 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { | 134 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { |
| 133 legacy_cache_removal_delay_ms_ = delay_ms; | 135 legacy_cache_removal_delay_ms_ = delay_ms; |
| 134 } | 136 } |
| 135 | 137 |
| 136 void AwBrowserContext::PreMainMessageLoopRun() { | 138 void AwBrowserContext::PreMainMessageLoopRun() { |
| 137 cookie_store_ = CreateCookieStore(this); | 139 cookie_store_ = CreateCookieStore(this); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 149 } else { | 151 } else { |
| 150 cache_path = fallback_cache_dir; | 152 cache_path = fallback_cache_dir; |
| 151 LOG(WARNING) << "Failed to get cache directory for Android WebView. " | 153 LOG(WARNING) << "Failed to get cache directory for Android WebView. " |
| 152 << "Using app data directory as a fallback."; | 154 << "Using app data directory as a fallback."; |
| 153 } | 155 } |
| 154 url_request_context_getter_ = | 156 url_request_context_getter_ = |
| 155 new AwURLRequestContextGetter( | 157 new AwURLRequestContextGetter( |
| 156 cache_path, cookie_store_.get(), | 158 cache_path, cookie_store_.get(), |
| 157 make_scoped_ptr(CreateProxyConfigService()).Pass()); | 159 make_scoped_ptr(CreateProxyConfigService()).Pass()); |
| 158 | 160 |
| 159 data_reduction_proxy_settings_.reset( | 161 data_reduction_proxy_settings_.reset( |
|
sclittle
2015/01/14 22:54:46
Would it be possible to pull the initialization of
bengr
2015/01/15 00:30:31
I considered that. For now, I'd like to leave it a
| |
| 160 new DataReductionProxySettings( | 162 new data_reduction_proxy::DataReductionProxySettings( |
| 161 new data_reduction_proxy::DataReductionProxyParams( | 163 new data_reduction_proxy::DataReductionProxyParams( |
| 162 data_reduction_proxy::DataReductionProxyParams::kAllowed))); | 164 data_reduction_proxy::DataReductionProxyParams::kAllowed))); |
| 163 data_reduction_proxy_event_store_.reset( | 165 data_reduction_proxy_io_data_.reset( |
| 164 new DataReductionProxyEventStore( | 166 new data_reduction_proxy::DataReductionProxyIOData( |
| 165 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))); | 167 data_reduction_proxy::Client::WEBVIEW_ANDROID, |
| 166 data_reduction_proxy_configurator_.reset( | 168 data_reduction_proxy_settings_->params()->Clone(), |
| 167 new data_reduction_proxy::DataReductionProxyConfigurator( | 169 scoped_ptr< |
| 170 data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | |
| 171 data_reduction_proxy_settings_.get(), | |
| 172 url_request_context_getter_->GetNetLog(), | |
| 168 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 173 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 169 url_request_context_getter_->GetNetLog(), | 174 BrowserThread::GetMessageLoopProxyForThread( |
| 170 data_reduction_proxy_event_store_.get())); | 175 BrowserThread::UI))); |
| 171 data_reduction_proxy_settings_->SetProxyConfigurator( | 176 data_reduction_proxy_settings_->SetProxyConfigurator( |
| 172 data_reduction_proxy_configurator_.get()); | 177 data_reduction_proxy_io_data_->configurator()); |
| 173 | 178 |
| 174 visitedlink_master_.reset( | 179 visitedlink_master_.reset( |
| 175 new visitedlink::VisitedLinkMaster(this, this, false)); | 180 new visitedlink::VisitedLinkMaster(this, this, false)); |
| 176 visitedlink_master_->Init(); | 181 visitedlink_master_->Init(); |
| 177 | 182 |
| 178 form_database_service_.reset( | 183 form_database_service_.reset( |
| 179 new AwFormDatabaseService(context_storage_path_)); | 184 new AwFormDatabaseService(context_storage_path_)); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 187 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 212 if (!quota_manager_bridge_.get()) { | 217 if (!quota_manager_bridge_.get()) { |
| 213 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); | 218 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); |
| 214 } | 219 } |
| 215 return quota_manager_bridge_.get(); | 220 return quota_manager_bridge_.get(); |
| 216 } | 221 } |
| 217 | 222 |
| 218 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 223 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
| 219 return form_database_service_.get(); | 224 return form_database_service_.get(); |
| 220 } | 225 } |
| 221 | 226 |
| 222 DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { | 227 data_reduction_proxy::DataReductionProxySettings* |
| 228 AwBrowserContext::GetDataReductionProxySettings() { | |
| 223 return data_reduction_proxy_settings_.get(); | 229 return data_reduction_proxy_settings_.get(); |
| 224 } | 230 } |
| 225 | 231 |
| 226 DataReductionProxyEventStore* | 232 data_reduction_proxy::DataReductionProxyIOData* |
| 227 AwBrowserContext::GetDataReductionProxyEventStore() { | 233 AwBrowserContext::GetDataReductionProxyIOData() { |
| 228 return data_reduction_proxy_event_store_.get(); | 234 return data_reduction_proxy_io_data_.get(); |
| 229 } | 235 } |
| 230 | 236 |
| 231 data_reduction_proxy::DataReductionProxyConfigurator* | 237 data_reduction_proxy::DataReductionProxyConfigurator* |
| 232 AwBrowserContext::GetDataReductionProxyConfigurator() { | 238 AwBrowserContext::GetDataReductionProxyConfigurator() { |
| 233 return data_reduction_proxy_configurator_.get(); | 239 return data_reduction_proxy_io_data_->configurator(); |
| 234 } | 240 } |
| 235 | 241 |
| 236 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 242 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
| 237 return url_request_context_getter_.get(); | 243 return url_request_context_getter_.get(); |
| 238 } | 244 } |
| 239 | 245 |
| 240 // Create user pref service for autofill functionality. | 246 // Create user pref service for autofill functionality. |
| 241 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 247 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
| 242 if (user_pref_service_) | 248 if (user_pref_service_) |
| 243 return; | 249 return; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 254 autofill::prefs::kAutofillNegativeUploadRate, 0.0); | 260 autofill::prefs::kAutofillNegativeUploadRate, 0.0); |
| 255 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); | 261 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); |
| 256 | 262 |
| 257 base::PrefServiceFactory pref_service_factory; | 263 base::PrefServiceFactory pref_service_factory; |
| 258 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); | 264 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); |
| 259 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 265 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
| 260 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 266 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
| 261 | 267 |
| 262 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 268 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
| 263 | 269 |
| 264 if (data_reduction_proxy_settings_.get()) { | 270 if (data_reduction_proxy_settings_.get()) { |
|
sclittle
2015/01/14 22:54:46
nit: do you need the .get() here?
bengr
2015/01/15 00:30:31
Done. Call me old fashioned.
| |
| 265 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 271 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
|
sclittle
2015/01/14 22:54:46
Would it be possible to pull this initialization o
bengr
2015/01/15 00:30:31
Eventually, yes. Not in this CL, which is too larg
| |
| 266 user_pref_service_.get(), | 272 user_pref_service_.get(), |
| 267 GetRequestContext(), | 273 GetRequestContext(), |
| 268 GetAwURLRequestContext()->GetNetLog(), | 274 GetAwURLRequestContext()->GetNetLog(), |
| 269 GetDataReductionProxyEventStore()); | 275 data_reduction_proxy_io_data_->event_store()); |
| 270 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); | 276 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); |
| 271 | 277 |
| 272 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 278 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 | 281 |
| 276 scoped_ptr<content::ZoomLevelDelegate> | 282 scoped_ptr<content::ZoomLevelDelegate> |
| 277 AwBrowserContext::CreateZoomLevelDelegate( | 283 AwBrowserContext::CreateZoomLevelDelegate( |
| 278 const base::FilePath& partition_path) { | 284 const base::FilePath& partition_path) { |
| 279 return nullptr; | 285 return nullptr; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 void AwBrowserContext::RebuildTable( | 359 void AwBrowserContext::RebuildTable( |
| 354 const scoped_refptr<URLEnumerator>& enumerator) { | 360 const scoped_refptr<URLEnumerator>& enumerator) { |
| 355 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 361 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
| 356 // can change in the lifetime of this WebView and may not yet be set here. | 362 // can change in the lifetime of this WebView and may not yet be set here. |
| 357 // Therefore this initialization path is not used. | 363 // Therefore this initialization path is not used. |
| 358 enumerator->OnComplete(true); | 364 enumerator->OnComplete(true); |
| 359 } | 365 } |
| 360 | 366 |
| 361 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { | 367 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { |
| 362 DCHECK(user_pref_service_.get()); | 368 DCHECK(user_pref_service_.get()); |
| 363 | 369 DCHECK(GetDataReductionProxyIOData()); |
| 364 if (!data_reduction_proxy_statistics_.get()) { | 370 if (GetDataReductionProxyIOData()->statistics_prefs()) |
| 365 // We don't care about commit_delay for now. It is just a dummy value. | 371 return; |
| 366 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | 372 // We don't care about commit_delay for now. It is just a dummy value. |
| 367 data_reduction_proxy_statistics_ = | 373 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
| 368 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>( | 374 GetDataReductionProxyIOData()->EnableCompressionStatisticsLogging( |
| 369 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | 375 user_pref_service_.get(), commit_delay); |
| 370 user_pref_service_.get(), | |
| 371 base::MessageLoopProxy::current(), | |
| 372 commit_delay)); | |
| 373 } | |
| 374 } | 376 } |
| 375 | 377 |
| 376 } // namespace android_webview | 378 } // namespace android_webview |
| OLD | NEW |