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_io_d ata.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_serv ice.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" |
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat istics_prefs.h" | |
24 #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" |
25 #include "components/user_prefs/user_prefs.h" | 27 #include "components/user_prefs/user_prefs.h" |
26 #include "components/visitedlink/browser/visitedlink_master.h" | 28 #include "components/visitedlink/browser/visitedlink_master.h" |
27 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/ssl_host_state_delegate.h" | 30 #include "content/public/browser/ssl_host_state_delegate.h" |
29 #include "content/public/browser/storage_partition.h" | 31 #include "content/public/browser/storage_partition.h" |
30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
31 #include "net/cookies/cookie_store.h" | 33 #include "net/cookies/cookie_store.h" |
32 #include "net/proxy/proxy_config_service_android.h" | 34 #include "net/proxy/proxy_config_service_android.h" |
33 #include "net/proxy/proxy_service.h" | 35 #include "net/proxy/proxy_service.h" |
34 | 36 |
35 using base::FilePath; | 37 using base::FilePath; |
36 using content::BrowserThread; | 38 using content::BrowserThread; |
37 | 39 |
38 namespace data_reduction_proxy { | 40 namespace data_reduction_proxy { |
39 class DataReductionProxyConfigurator; | 41 class DataReductionProxyConfigurator; |
sgurun-gerrit only
2015/02/20 21:53:28
remove.
jeremyim
2015/02/20 22:04:13
Done.
| |
40 class DataReductionProxyStatisticsPrefs; | 42 class DataReductionProxyStatisticsPrefs; |
41 } | 43 } |
42 | 44 |
43 namespace android_webview { | 45 namespace android_webview { |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 49 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
48 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 50 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
49 } | 51 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after 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( | |
160 new data_reduction_proxy::DataReductionProxySettings( | |
161 scoped_ptr<data_reduction_proxy::DataReductionProxyParams>( | |
162 new data_reduction_proxy::DataReductionProxyParams( | |
163 data_reduction_proxy::DataReductionProxyParams::kAllowed)) | |
164 .Pass())); | |
165 data_reduction_proxy_io_data_.reset( | 161 data_reduction_proxy_io_data_.reset( |
166 new data_reduction_proxy::DataReductionProxyIOData( | 162 new data_reduction_proxy::DataReductionProxyIOData( |
167 data_reduction_proxy::Client::WEBVIEW_ANDROID, | 163 data_reduction_proxy::Client::WEBVIEW_ANDROID, |
168 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | 164 data_reduction_proxy::DataReductionProxyParams::kAllowed, |
169 data_reduction_proxy_settings_.get(), | |
170 url_request_context_getter_->GetNetLog(), | 165 url_request_context_getter_->GetNetLog(), |
171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 166 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
172 BrowserThread::GetMessageLoopProxyForThread( | 167 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
173 BrowserThread::UI))); | 168 false /* enable_quic */)); |
174 data_reduction_proxy_io_data_->Init(); | 169 data_reduction_proxy_settings_.reset( |
175 data_reduction_proxy_settings_->SetProxyConfigurator( | 170 new data_reduction_proxy::DataReductionProxySettings()); |
176 data_reduction_proxy_io_data_->configurator()); | 171 data_reduction_proxy_service_.reset( |
172 new data_reduction_proxy::DataReductionProxyService( | |
173 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | |
174 data_reduction_proxy_settings_.get(), GetAwURLRequestContext())); | |
175 data_reduction_proxy_io_data_->SetDataReductionProxyService( | |
176 data_reduction_proxy_service_->GetWeakPtr()); | |
177 | 177 |
178 visitedlink_master_.reset( | 178 visitedlink_master_.reset( |
179 new visitedlink::VisitedLinkMaster(this, this, false)); | 179 new visitedlink::VisitedLinkMaster(this, this, false)); |
180 visitedlink_master_->Init(); | 180 visitedlink_master_->Init(); |
181 | 181 |
182 form_database_service_.reset( | 182 form_database_service_.reset( |
183 new AwFormDatabaseService(context_storage_path_)); | 183 new AwFormDatabaseService(context_storage_path_)); |
184 } | 184 } |
185 | 185 |
186 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 186 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 data_reduction_proxy::DataReductionProxySettings* | 226 data_reduction_proxy::DataReductionProxySettings* |
227 AwBrowserContext::GetDataReductionProxySettings() { | 227 AwBrowserContext::GetDataReductionProxySettings() { |
228 return data_reduction_proxy_settings_.get(); | 228 return data_reduction_proxy_settings_.get(); |
229 } | 229 } |
230 | 230 |
231 data_reduction_proxy::DataReductionProxyIOData* | 231 data_reduction_proxy::DataReductionProxyIOData* |
232 AwBrowserContext::GetDataReductionProxyIOData() { | 232 AwBrowserContext::GetDataReductionProxyIOData() { |
233 return data_reduction_proxy_io_data_.get(); | 233 return data_reduction_proxy_io_data_.get(); |
234 } | 234 } |
235 | 235 |
236 data_reduction_proxy::DataReductionProxyConfigurator* | |
237 AwBrowserContext::GetDataReductionProxyConfigurator() { | |
238 return data_reduction_proxy_io_data_->configurator(); | |
239 } | |
240 | |
241 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 236 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
242 return url_request_context_getter_.get(); | 237 return url_request_context_getter_.get(); |
243 } | 238 } |
244 | 239 |
245 AwMessagePortService* AwBrowserContext::GetMessagePortService() { | 240 AwMessagePortService* AwBrowserContext::GetMessagePortService() { |
246 if (!message_port_service_.get()) { | 241 if (!message_port_service_.get()) { |
247 message_port_service_.reset( | 242 message_port_service_.reset( |
248 native_factory_->CreateAwMessagePortService()); | 243 native_factory_->CreateAwMessagePortService()); |
249 } | 244 } |
250 return message_port_service_.get(); | 245 return message_port_service_.get(); |
(...skipping 18 matching lines...) Expand all Loading... | |
269 | 264 |
270 base::PrefServiceFactory pref_service_factory; | 265 base::PrefServiceFactory pref_service_factory; |
271 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); | 266 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); |
272 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 267 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
273 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 268 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
274 | 269 |
275 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 270 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
276 | 271 |
277 if (data_reduction_proxy_settings_) { | 272 if (data_reduction_proxy_settings_) { |
278 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 273 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
279 user_pref_service_.get(), | 274 user_pref_service_.get(), data_reduction_proxy_io_data_.get(), |
280 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | 275 data_reduction_proxy_service_.Pass()); |
281 GetRequestContext(), | |
282 GetAwURLRequestContext()->GetNetLog(), | |
283 data_reduction_proxy_io_data_->event_store(), | |
284 false /* disable QUIC for WebView */); | |
285 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); | 276 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); |
286 | 277 |
287 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 278 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
288 } | 279 } |
289 } | 280 } |
290 | 281 |
291 scoped_ptr<content::ZoomLevelDelegate> | 282 scoped_ptr<content::ZoomLevelDelegate> |
292 AwBrowserContext::CreateZoomLevelDelegate( | 283 AwBrowserContext::CreateZoomLevelDelegate( |
293 const base::FilePath& partition_path) { | 284 const base::FilePath& partition_path) { |
294 return nullptr; | 285 return nullptr; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 const scoped_refptr<URLEnumerator>& enumerator) { | 360 const scoped_refptr<URLEnumerator>& enumerator) { |
370 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 361 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
371 // 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. |
372 // Therefore this initialization path is not used. | 363 // Therefore this initialization path is not used. |
373 enumerator->OnComplete(true); | 364 enumerator->OnComplete(true); |
374 } | 365 } |
375 | 366 |
376 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { | 367 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { |
377 DCHECK(user_pref_service_.get()); | 368 DCHECK(user_pref_service_.get()); |
378 DCHECK(GetDataReductionProxySettings()); | 369 DCHECK(GetDataReductionProxySettings()); |
379 if (GetDataReductionProxySettings()->statistics_prefs()) | 370 data_reduction_proxy::DataReductionProxyService* |
371 data_reduction_proxy_service = | |
372 GetDataReductionProxySettings()->data_reduction_proxy_service(); | |
373 DCHECK(data_reduction_proxy_service); | |
374 if (data_reduction_proxy_service->statistics_prefs()) | |
380 return; | 375 return; |
381 // We don't care about commit_delay for now. It is just a dummy value. | 376 // We don't care about commit_delay for now. It is just a dummy value. |
382 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | 377 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
383 GetDataReductionProxySettings()->EnableCompressionStatisticsLogging( | 378 data_reduction_proxy_service->EnableCompressionStatisticsLogging( |
384 user_pref_service_.get(), | 379 user_pref_service_.get(), |
385 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 380 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
386 commit_delay); | 381 commit_delay); |
387 GetDataReductionProxyIOData()->SetDataReductionProxyStatisticsPrefs( | |
388 GetDataReductionProxySettings()->statistics_prefs()); | |
389 } | 382 } |
390 | 383 |
391 } // namespace android_webview | 384 } // namespace android_webview |
OLD | NEW |