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_settings_.get(), |
| 170 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 171 BrowserThread::GetMessageLoopProxyForThread( |
| 172 BrowserThread::UI))); |
| 173 data_reduction_proxy_settings_->SetProxyConfigurator( |
| 174 data_reduction_proxy_io_data_->configurator()); |
161 FilePath cache_path; | 175 FilePath cache_path; |
162 const FilePath fallback_cache_dir = | 176 const FilePath fallback_cache_dir = |
163 GetPath().Append(FILE_PATH_LITERAL("Cache")); | 177 GetPath().Append(FILE_PATH_LITERAL("Cache")); |
164 if (PathService::Get(base::DIR_CACHE, &cache_path)) { | 178 if (PathService::Get(base::DIR_CACHE, &cache_path)) { |
165 cache_path = cache_path.Append( | 179 cache_path = cache_path.Append( |
166 FILE_PATH_LITERAL("org.chromium.android_webview")); | 180 FILE_PATH_LITERAL("org.chromium.android_webview")); |
167 // Delay the legacy dir removal to not impact startup performance. | 181 // Delay the legacy dir removal to not impact startup performance. |
168 BrowserThread::PostDelayedTask( | 182 BrowserThread::PostDelayedTask( |
169 BrowserThread::FILE, FROM_HERE, | 183 BrowserThread::FILE, FROM_HERE, |
170 base::Bind(&DeleteDirRecursively, fallback_cache_dir), | 184 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()) { | 234 if (!quota_manager_bridge_.get()) { |
221 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); | 235 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); |
222 } | 236 } |
223 return quota_manager_bridge_.get(); | 237 return quota_manager_bridge_.get(); |
224 } | 238 } |
225 | 239 |
226 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 240 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
227 return form_database_service_.get(); | 241 return form_database_service_.get(); |
228 } | 242 } |
229 | 243 |
230 DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { | 244 data_reduction_proxy::DataReductionProxySettings* |
| 245 AwBrowserContext::GetDataReductionProxySettings() { |
231 return data_reduction_proxy_settings_.get(); | 246 return data_reduction_proxy_settings_.get(); |
232 } | 247 } |
233 | 248 |
234 DataReductionProxyEventStore* | 249 data_reduction_proxy::DataReductionProxyIOData* |
235 AwBrowserContext::GetDataReductionProxyEventStore() { | 250 AwBrowserContext::GetDataReductionProxyIOData() { |
236 return data_reduction_proxy_event_store_.get(); | 251 return data_reduction_proxy_io_data_.get(); |
237 } | 252 } |
238 | 253 |
239 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 254 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
240 return url_request_context_getter_.get(); | 255 return url_request_context_getter_.get(); |
241 } | 256 } |
242 | 257 |
243 // Create user pref service for autofill functionality. | 258 // Create user pref service for autofill functionality. |
244 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 259 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
245 if (user_pref_service_) | 260 if (user_pref_service_) |
246 return; | 261 return; |
(...skipping 15 matching lines...) Expand all Loading... |
262 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 277 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
263 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 278 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
264 | 279 |
265 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 280 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
266 | 281 |
267 if (data_reduction_proxy_settings_.get()) { | 282 if (data_reduction_proxy_settings_.get()) { |
268 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 283 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
269 user_pref_service_.get(), | 284 user_pref_service_.get(), |
270 GetRequestContext(), | 285 GetRequestContext(), |
271 GetAwURLRequestContext()->GetNetLog(), | 286 GetAwURLRequestContext()->GetNetLog(), |
272 GetDataReductionProxyEventStore()); | 287 data_reduction_proxy_io_data_->event_store()); |
273 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); | 288 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); |
274 | 289 |
275 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 290 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
276 } | 291 } |
277 } | 292 } |
278 | 293 |
279 scoped_ptr<content::ZoomLevelDelegate> | 294 scoped_ptr<content::ZoomLevelDelegate> |
280 AwBrowserContext::CreateZoomLevelDelegate( | 295 AwBrowserContext::CreateZoomLevelDelegate( |
281 const base::FilePath& partition_path) { | 296 const base::FilePath& partition_path) { |
282 return nullptr; | 297 return nullptr; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 void AwBrowserContext::RebuildTable( | 371 void AwBrowserContext::RebuildTable( |
357 const scoped_refptr<URLEnumerator>& enumerator) { | 372 const scoped_refptr<URLEnumerator>& enumerator) { |
358 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 373 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
359 // can change in the lifetime of this WebView and may not yet be set here. | 374 // can change in the lifetime of this WebView and may not yet be set here. |
360 // Therefore this initialization path is not used. | 375 // Therefore this initialization path is not used. |
361 enumerator->OnComplete(true); | 376 enumerator->OnComplete(true); |
362 } | 377 } |
363 | 378 |
364 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { | 379 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { |
365 DCHECK(user_pref_service_.get()); | 380 DCHECK(user_pref_service_.get()); |
366 | 381 DCHECK(GetDataReductionProxyIOData()); |
367 if (!data_reduction_proxy_statistics_.get()) { | 382 if (GetDataReductionProxyIOData()->statistics_prefs()) |
368 // We don't care about commit_delay for now. It is just a dummy value. | 383 return; |
369 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | 384 // We don't care about commit_delay for now. It is just a dummy value. |
370 data_reduction_proxy_statistics_ = | 385 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
371 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>( | 386 GetDataReductionProxyIOData()->EnableCompressionStatisticsLogging( |
372 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | 387 user_pref_service_.get(), commit_delay); |
373 user_pref_service_.get(), | |
374 base::MessageLoopProxy::current(), | |
375 commit_delay)); | |
376 } | |
377 } | 388 } |
378 | 389 |
379 } // namespace android_webview | 390 } // namespace android_webview |
OLD | NEW |