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 12 matching lines...) Expand all Loading... |
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( |
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 scoped_ptr< |
167 new data_reduction_proxy::DataReductionProxyConfigurator( | 169 data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), |
| 170 data_reduction_proxy_settings_.get(), |
| 171 url_request_context_getter_->GetNetLog(), |
168 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 172 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
169 url_request_context_getter_->GetNetLog(), | 173 BrowserThread::GetMessageLoopProxyForThread( |
170 data_reduction_proxy_event_store_.get())); | 174 BrowserThread::UI))); |
171 data_reduction_proxy_settings_->SetProxyConfigurator( | 175 data_reduction_proxy_settings_->SetProxyConfigurator( |
172 data_reduction_proxy_configurator_.get()); | 176 data_reduction_proxy_io_data_->configurator()); |
173 | 177 |
174 visitedlink_master_.reset( | 178 visitedlink_master_.reset( |
175 new visitedlink::VisitedLinkMaster(this, this, false)); | 179 new visitedlink::VisitedLinkMaster(this, this, false)); |
176 visitedlink_master_->Init(); | 180 visitedlink_master_->Init(); |
177 | 181 |
178 form_database_service_.reset( | 182 form_database_service_.reset( |
179 new AwFormDatabaseService(context_storage_path_)); | 183 new AwFormDatabaseService(context_storage_path_)); |
180 } | 184 } |
181 | 185 |
182 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 186 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { |
(...skipping 29 matching lines...) Expand all Loading... |
212 if (!quota_manager_bridge_.get()) { | 216 if (!quota_manager_bridge_.get()) { |
213 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); | 217 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); |
214 } | 218 } |
215 return quota_manager_bridge_.get(); | 219 return quota_manager_bridge_.get(); |
216 } | 220 } |
217 | 221 |
218 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 222 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
219 return form_database_service_.get(); | 223 return form_database_service_.get(); |
220 } | 224 } |
221 | 225 |
222 DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { | 226 data_reduction_proxy::DataReductionProxySettings* |
| 227 AwBrowserContext::GetDataReductionProxySettings() { |
223 return data_reduction_proxy_settings_.get(); | 228 return data_reduction_proxy_settings_.get(); |
224 } | 229 } |
225 | 230 |
226 DataReductionProxyEventStore* | 231 data_reduction_proxy::DataReductionProxyIOData* |
227 AwBrowserContext::GetDataReductionProxyEventStore() { | 232 AwBrowserContext::GetDataReductionProxyIOData() { |
228 return data_reduction_proxy_event_store_.get(); | 233 return data_reduction_proxy_io_data_.get(); |
229 } | 234 } |
230 | 235 |
231 data_reduction_proxy::DataReductionProxyConfigurator* | 236 data_reduction_proxy::DataReductionProxyConfigurator* |
232 AwBrowserContext::GetDataReductionProxyConfigurator() { | 237 AwBrowserContext::GetDataReductionProxyConfigurator() { |
233 return data_reduction_proxy_configurator_.get(); | 238 return data_reduction_proxy_io_data_->configurator(); |
234 } | 239 } |
235 | 240 |
236 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 241 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
237 return url_request_context_getter_.get(); | 242 return url_request_context_getter_.get(); |
238 } | 243 } |
239 | 244 |
240 // Create user pref service for autofill functionality. | 245 // Create user pref service for autofill functionality. |
241 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 246 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
242 if (user_pref_service_) | 247 if (user_pref_service_) |
243 return; | 248 return; |
(...skipping 10 matching lines...) Expand all Loading... |
254 autofill::prefs::kAutofillNegativeUploadRate, 0.0); | 259 autofill::prefs::kAutofillNegativeUploadRate, 0.0); |
255 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); | 260 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); |
256 | 261 |
257 base::PrefServiceFactory pref_service_factory; | 262 base::PrefServiceFactory pref_service_factory; |
258 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); | 263 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); |
259 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 264 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
260 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 265 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
261 | 266 |
262 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 267 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
263 | 268 |
264 if (data_reduction_proxy_settings_.get()) { | 269 if (data_reduction_proxy_settings_) { |
265 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 270 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
266 user_pref_service_.get(), | 271 user_pref_service_.get(), |
267 GetRequestContext(), | 272 GetRequestContext(), |
268 GetAwURLRequestContext()->GetNetLog(), | 273 GetAwURLRequestContext()->GetNetLog(), |
269 GetDataReductionProxyEventStore()); | 274 data_reduction_proxy_io_data_->event_store()); |
270 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); | 275 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); |
271 | 276 |
272 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 277 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
273 } | 278 } |
274 } | 279 } |
275 | 280 |
276 scoped_ptr<content::ZoomLevelDelegate> | 281 scoped_ptr<content::ZoomLevelDelegate> |
277 AwBrowserContext::CreateZoomLevelDelegate( | 282 AwBrowserContext::CreateZoomLevelDelegate( |
278 const base::FilePath& partition_path) { | 283 const base::FilePath& partition_path) { |
279 return nullptr; | 284 return nullptr; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 void AwBrowserContext::RebuildTable( | 358 void AwBrowserContext::RebuildTable( |
354 const scoped_refptr<URLEnumerator>& enumerator) { | 359 const scoped_refptr<URLEnumerator>& enumerator) { |
355 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 360 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
356 // can change in the lifetime of this WebView and may not yet be set here. | 361 // can change in the lifetime of this WebView and may not yet be set here. |
357 // Therefore this initialization path is not used. | 362 // Therefore this initialization path is not used. |
358 enumerator->OnComplete(true); | 363 enumerator->OnComplete(true); |
359 } | 364 } |
360 | 365 |
361 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { | 366 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { |
362 DCHECK(user_pref_service_.get()); | 367 DCHECK(user_pref_service_.get()); |
363 | 368 DCHECK(GetDataReductionProxyIOData()); |
364 if (!data_reduction_proxy_statistics_.get()) { | 369 if (GetDataReductionProxyIOData()->statistics_prefs()) |
365 // We don't care about commit_delay for now. It is just a dummy value. | 370 return; |
366 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | 371 // We don't care about commit_delay for now. It is just a dummy value. |
367 data_reduction_proxy_statistics_ = | 372 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
368 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>( | 373 GetDataReductionProxyIOData()->EnableCompressionStatisticsLogging( |
369 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | 374 user_pref_service_.get(), commit_delay); |
370 user_pref_service_.get(), | |
371 base::MessageLoopProxy::current(), | |
372 commit_delay)); | |
373 } | |
374 } | 375 } |
375 | 376 |
376 } // namespace android_webview | 377 } // namespace android_webview |
OLD | NEW |