| 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
ig_service.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_service.h" |
| 22 #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" | 23 #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" | 24 #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" | 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" | 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 27 #include "components/user_prefs/user_prefs.h" | 27 #include "components/user_prefs/user_prefs.h" |
| 28 #include "components/visitedlink/browser/visitedlink_master.h" | 28 #include "components/visitedlink/browser/visitedlink_master.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/ssl_host_state_delegate.h" | 30 #include "content/public/browser/ssl_host_state_delegate.h" |
| 31 #include "content/public/browser/storage_partition.h" | 31 #include "content/public/browser/storage_partition.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "net/cookies/cookie_store.h" | 33 #include "net/cookies/cookie_store.h" |
| 34 #include "net/proxy/proxy_config_service_android.h" | 34 #include "net/proxy/proxy_config_service_android.h" |
| 35 #include "net/proxy/proxy_service.h" | 35 #include "net/proxy/proxy_service.h" |
| 36 | 36 |
| 37 using base::FilePath; | 37 using base::FilePath; |
| 38 using content::BrowserThread; | 38 using content::BrowserThread; |
| 39 using data_reduction_proxy::DataReductionProxyConfigService; | 39 |
| 40 using data_reduction_proxy::DataReductionProxyEventStore; | 40 namespace data_reduction_proxy { |
| 41 using data_reduction_proxy::DataReductionProxySettings; | 41 class DataReductionProxyStatisticsPrefs; |
| 42 } |
| 42 | 43 |
| 43 namespace android_webview { | 44 namespace android_webview { |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 48 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
| 48 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 49 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
| 49 } | 50 } |
| 50 | 51 |
| 51 void DeleteDirRecursively(const base::FilePath& path) { | 52 void DeleteDirRecursively(const base::FilePath& path) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 // static | 112 // static |
| 112 void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { | 113 void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { |
| 113 // Cache the setting value. It is possible that data reduction proxy is | 114 // Cache the setting value. It is possible that data reduction proxy is |
| 114 // not created yet. | 115 // not created yet. |
| 115 data_reduction_proxy_enabled_ = enabled; | 116 data_reduction_proxy_enabled_ = enabled; |
| 116 AwBrowserContext* context = AwBrowserContext::GetDefault(); | 117 AwBrowserContext* context = AwBrowserContext::GetDefault(); |
| 117 // Can't enable Data reduction proxy if user pref service is not ready. | 118 // Can't enable Data reduction proxy if user pref service is not ready. |
| 118 if (context == NULL || context->user_pref_service_.get() == NULL) | 119 if (context == NULL || context->user_pref_service_.get() == NULL) |
| 119 return; | 120 return; |
| 120 DataReductionProxySettings* proxy_settings = | 121 data_reduction_proxy::DataReductionProxySettings* proxy_settings = |
| 121 context->GetDataReductionProxySettings(); | 122 context->GetDataReductionProxySettings(); |
| 122 if (proxy_settings == NULL) | 123 if (proxy_settings == NULL) |
| 123 return; | 124 return; |
| 124 | 125 // At this point, context->PreMainMessageLoopRun() has run, so |
| 126 // context->data_reduction_proxy_io_data() is valid. |
| 127 DCHECK(context->GetDataReductionProxyIOData()); |
| 125 context->CreateDataReductionProxyStatisticsIfNecessary(); | 128 context->CreateDataReductionProxyStatisticsIfNecessary(); |
| 126 proxy_settings->SetDataReductionProxyStatisticsPrefs( | 129 proxy_settings->SetDataReductionProxyStatisticsPrefs( |
| 127 context->data_reduction_proxy_statistics_.get()); | 130 context->GetDataReductionProxyIOData()->statistics_prefs()); |
| 128 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 131 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
| 129 } | 132 } |
| 130 | 133 |
| 131 // static | 134 // static |
| 132 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { | 135 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { |
| 133 legacy_cache_removal_delay_ms_ = delay_ms; | 136 legacy_cache_removal_delay_ms_ = delay_ms; |
| 134 } | 137 } |
| 135 | 138 |
| 136 void AwBrowserContext::PreMainMessageLoopRun() { | 139 void AwBrowserContext::PreMainMessageLoopRun() { |
| 137 cookie_store_ = CreateCookieStore(this); | 140 cookie_store_ = CreateCookieStore(this); |
| 138 data_reduction_proxy_settings_.reset( | 141 data_reduction_proxy_settings_.reset( |
| 139 new DataReductionProxySettings( | 142 new data_reduction_proxy::DataReductionProxySettings( |
| 140 new data_reduction_proxy::DataReductionProxyParams( | 143 new data_reduction_proxy::DataReductionProxyParams( |
| 141 data_reduction_proxy::DataReductionProxyParams::kAllowed))); | 144 data_reduction_proxy::DataReductionProxyParams::kAllowed))); |
| 142 data_reduction_proxy_event_store_.reset( | 145 scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService> |
| 143 new DataReductionProxyEventStore( | |
| 144 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))); | |
| 145 scoped_ptr<DataReductionProxyConfigService> | |
| 146 data_reduction_proxy_config_service( | 146 data_reduction_proxy_config_service( |
| 147 new DataReductionProxyConfigService( | 147 new data_reduction_proxy::DataReductionProxyConfigService( |
| 148 scoped_ptr<net::ProxyConfigService>( | 148 scoped_ptr<net::ProxyConfigService>( |
| 149 CreateProxyConfigService()).Pass())); | 149 CreateProxyConfigService()).Pass())); |
| 150 if (data_reduction_proxy_settings_.get()) { | 150 data_reduction_proxy_io_data_.reset( |
| 151 data_reduction_proxy_configurator_.reset( | 151 new data_reduction_proxy::DataReductionProxyIOData( |
| 152 new data_reduction_proxy::DataReductionProxyConfigTracker( | 152 data_reduction_proxy::Client::WEBVIEW_ANDROID, |
| 153 base::Bind(&DataReductionProxyConfigService::UpdateProxyConfig, | 153 data_reduction_proxy_settings_->params()->Clone(), |
| 154 base::Unretained( | 154 make_scoped_ptr( |
| 155 data_reduction_proxy_config_service.get())), | 155 new data_reduction_proxy::DataReductionProxyConfigTracker( |
| 156 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 156 base::Bind( |
| 157 data_reduction_proxy_settings_->SetProxyConfigurator( | 157 &data_reduction_proxy::DataReductionProxyConfigService:: |
| 158 data_reduction_proxy_configurator_.get()); | 158 UpdateProxyConfig, |
| 159 } | 159 base::Unretained( |
| 160 | 160 data_reduction_proxy_config_service.get())), |
| 161 BrowserThread::GetMessageLoopProxyForThread( |
| 162 BrowserThread::IO))), |
| 163 scoped_ptr< |
| 164 data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), |
| 165 make_scoped_ptr( |
| 166 new data_reduction_proxy::DataReductionProxyEventStore( |
| 167 BrowserThread::GetMessageLoopProxyForThread( |
| 168 BrowserThread::UI))), |
| 169 data_reduction_proxy::DataReductionProxyNetworkDelegate:: |
| 170 ProxyConfigGetter(), |
| 171 base::Callback<void(bool)>(), |
| 172 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 173 BrowserThread::GetMessageLoopProxyForThread( |
| 174 BrowserThread::UI))); |
| 175 data_reduction_proxy_settings_->SetProxyConfigurator( |
| 176 data_reduction_proxy_io_data_->configurator()); |
| 161 FilePath cache_path; | 177 FilePath cache_path; |
| 162 const FilePath fallback_cache_dir = | 178 const FilePath fallback_cache_dir = |
| 163 GetPath().Append(FILE_PATH_LITERAL("Cache")); | 179 GetPath().Append(FILE_PATH_LITERAL("Cache")); |
| 164 if (PathService::Get(base::DIR_CACHE, &cache_path)) { | 180 if (PathService::Get(base::DIR_CACHE, &cache_path)) { |
| 165 cache_path = cache_path.Append( | 181 cache_path = cache_path.Append( |
| 166 FILE_PATH_LITERAL("org.chromium.android_webview")); | 182 FILE_PATH_LITERAL("org.chromium.android_webview")); |
| 167 // Delay the legacy dir removal to not impact startup performance. | 183 // Delay the legacy dir removal to not impact startup performance. |
| 168 BrowserThread::PostDelayedTask( | 184 BrowserThread::PostDelayedTask( |
| 169 BrowserThread::FILE, FROM_HERE, | 185 BrowserThread::FILE, FROM_HERE, |
| 170 base::Bind(&DeleteDirRecursively, fallback_cache_dir), | 186 base::Bind(&DeleteDirRecursively, fallback_cache_dir), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (!quota_manager_bridge_.get()) { | 236 if (!quota_manager_bridge_.get()) { |
| 221 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); | 237 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); |
| 222 } | 238 } |
| 223 return quota_manager_bridge_.get(); | 239 return quota_manager_bridge_.get(); |
| 224 } | 240 } |
| 225 | 241 |
| 226 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 242 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
| 227 return form_database_service_.get(); | 243 return form_database_service_.get(); |
| 228 } | 244 } |
| 229 | 245 |
| 230 DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { | 246 data_reduction_proxy::DataReductionProxySettings* |
| 247 AwBrowserContext::GetDataReductionProxySettings() { |
| 231 return data_reduction_proxy_settings_.get(); | 248 return data_reduction_proxy_settings_.get(); |
| 232 } | 249 } |
| 233 | 250 |
| 234 DataReductionProxyEventStore* | 251 data_reduction_proxy::DataReductionProxyIOData* |
| 235 AwBrowserContext::GetDataReductionProxyEventStore() { | 252 AwBrowserContext::GetDataReductionProxyIOData() { |
| 236 return data_reduction_proxy_event_store_.get(); | 253 return data_reduction_proxy_io_data_.get(); |
| 237 } | 254 } |
| 238 | 255 |
| 239 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 256 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
| 240 return url_request_context_getter_.get(); | 257 return url_request_context_getter_.get(); |
| 241 } | 258 } |
| 242 | 259 |
| 243 // Create user pref service for autofill functionality. | 260 // Create user pref service for autofill functionality. |
| 244 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 261 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
| 245 if (user_pref_service_) | 262 if (user_pref_service_) |
| 246 return; | 263 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 262 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 279 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
| 263 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 280 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
| 264 | 281 |
| 265 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 282 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
| 266 | 283 |
| 267 if (data_reduction_proxy_settings_.get()) { | 284 if (data_reduction_proxy_settings_.get()) { |
| 268 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 285 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
| 269 user_pref_service_.get(), | 286 user_pref_service_.get(), |
| 270 GetRequestContext(), | 287 GetRequestContext(), |
| 271 GetAwURLRequestContext()->GetNetLog(), | 288 GetAwURLRequestContext()->GetNetLog(), |
| 272 GetDataReductionProxyEventStore()); | 289 data_reduction_proxy_io_data_->event_store()); |
| 273 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); | 290 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); |
| 274 | 291 |
| 275 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 292 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
| 276 } | 293 } |
| 277 } | 294 } |
| 278 | 295 |
| 279 scoped_ptr<content::ZoomLevelDelegate> | 296 scoped_ptr<content::ZoomLevelDelegate> |
| 280 AwBrowserContext::CreateZoomLevelDelegate( | 297 AwBrowserContext::CreateZoomLevelDelegate( |
| 281 const base::FilePath& partition_path) { | 298 const base::FilePath& partition_path) { |
| 282 return nullptr; | 299 return nullptr; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 void AwBrowserContext::RebuildTable( | 373 void AwBrowserContext::RebuildTable( |
| 357 const scoped_refptr<URLEnumerator>& enumerator) { | 374 const scoped_refptr<URLEnumerator>& enumerator) { |
| 358 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 375 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
| 359 // can change in the lifetime of this WebView and may not yet be set here. | 376 // can change in the lifetime of this WebView and may not yet be set here. |
| 360 // Therefore this initialization path is not used. | 377 // Therefore this initialization path is not used. |
| 361 enumerator->OnComplete(true); | 378 enumerator->OnComplete(true); |
| 362 } | 379 } |
| 363 | 380 |
| 364 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { | 381 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { |
| 365 DCHECK(user_pref_service_.get()); | 382 DCHECK(user_pref_service_.get()); |
| 366 | 383 DCHECK(GetDataReductionProxyIOData()); |
| 367 if (!data_reduction_proxy_statistics_.get()) { | 384 if (GetDataReductionProxyIOData()->statistics_prefs()) |
| 368 // We don't care about commit_delay for now. It is just a dummy value. | 385 return; |
| 369 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | 386 // We don't care about commit_delay for now. It is just a dummy value. |
| 370 data_reduction_proxy_statistics_ = | 387 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
| 371 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>( | 388 GetDataReductionProxyIOData()->CreateStatisticsPrefs( |
| 372 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | 389 user_pref_service_.get(), commit_delay); |
| 373 user_pref_service_.get(), | |
| 374 base::MessageLoopProxy::current(), | |
| 375 commit_delay)); | |
| 376 } | |
| 377 } | 390 } |
| 378 | 391 |
| 379 } // namespace android_webview | 392 } // namespace android_webview |
| OLD | NEW |