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 { | |
39 class DataReductionProxyConfigurator; | |
40 class DataReductionProxyStatisticsPrefs; | |
41 } | |
42 | |
43 namespace android_webview { | 40 namespace android_webview { |
44 | 41 |
45 namespace { | 42 namespace { |
46 | 43 |
47 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 44 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
48 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 45 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
49 } | 46 } |
50 | 47 |
51 void DeleteDirRecursively(const base::FilePath& path) { | 48 void DeleteDirRecursively(const base::FilePath& path) { |
52 if (!base::DeleteFile(path, true)) { | 49 if (!base::DeleteFile(path, true)) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } else { | 146 } else { |
150 cache_path = fallback_cache_dir; | 147 cache_path = fallback_cache_dir; |
151 LOG(WARNING) << "Failed to get cache directory for Android WebView. " | 148 LOG(WARNING) << "Failed to get cache directory for Android WebView. " |
152 << "Using app data directory as a fallback."; | 149 << "Using app data directory as a fallback."; |
153 } | 150 } |
154 url_request_context_getter_ = | 151 url_request_context_getter_ = |
155 new AwURLRequestContextGetter( | 152 new AwURLRequestContextGetter( |
156 cache_path, cookie_store_.get(), | 153 cache_path, cookie_store_.get(), |
157 make_scoped_ptr(CreateProxyConfigService()).Pass()); | 154 make_scoped_ptr(CreateProxyConfigService()).Pass()); |
158 | 155 |
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( | 156 data_reduction_proxy_io_data_.reset( |
166 new data_reduction_proxy::DataReductionProxyIOData( | 157 new data_reduction_proxy::DataReductionProxyIOData( |
167 data_reduction_proxy::Client::WEBVIEW_ANDROID, | 158 data_reduction_proxy::Client::WEBVIEW_ANDROID, |
168 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | 159 data_reduction_proxy::DataReductionProxyParams::kAllowed, |
169 data_reduction_proxy_settings_.get(), | |
170 url_request_context_getter_->GetNetLog(), | 160 url_request_context_getter_->GetNetLog(), |
171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 161 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
172 BrowserThread::GetMessageLoopProxyForThread( | 162 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
173 BrowserThread::UI))); | 163 false /* enable_quic */)); |
174 data_reduction_proxy_io_data_->Init(); | 164 data_reduction_proxy_settings_.reset( |
175 data_reduction_proxy_settings_->SetProxyConfigurator( | 165 new data_reduction_proxy::DataReductionProxySettings()); |
176 data_reduction_proxy_io_data_->configurator()); | 166 data_reduction_proxy_service_.reset( |
| 167 new data_reduction_proxy::DataReductionProxyService( |
| 168 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), |
| 169 data_reduction_proxy_settings_.get(), GetAwURLRequestContext())); |
| 170 data_reduction_proxy_io_data_->SetDataReductionProxyService( |
| 171 data_reduction_proxy_service_->GetWeakPtr()); |
177 | 172 |
178 visitedlink_master_.reset( | 173 visitedlink_master_.reset( |
179 new visitedlink::VisitedLinkMaster(this, this, false)); | 174 new visitedlink::VisitedLinkMaster(this, this, false)); |
180 visitedlink_master_->Init(); | 175 visitedlink_master_->Init(); |
181 | 176 |
182 form_database_service_.reset( | 177 form_database_service_.reset( |
183 new AwFormDatabaseService(context_storage_path_)); | 178 new AwFormDatabaseService(context_storage_path_)); |
184 } | 179 } |
185 | 180 |
186 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 181 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* | 221 data_reduction_proxy::DataReductionProxySettings* |
227 AwBrowserContext::GetDataReductionProxySettings() { | 222 AwBrowserContext::GetDataReductionProxySettings() { |
228 return data_reduction_proxy_settings_.get(); | 223 return data_reduction_proxy_settings_.get(); |
229 } | 224 } |
230 | 225 |
231 data_reduction_proxy::DataReductionProxyIOData* | 226 data_reduction_proxy::DataReductionProxyIOData* |
232 AwBrowserContext::GetDataReductionProxyIOData() { | 227 AwBrowserContext::GetDataReductionProxyIOData() { |
233 return data_reduction_proxy_io_data_.get(); | 228 return data_reduction_proxy_io_data_.get(); |
234 } | 229 } |
235 | 230 |
236 data_reduction_proxy::DataReductionProxyConfigurator* | |
237 AwBrowserContext::GetDataReductionProxyConfigurator() { | |
238 return data_reduction_proxy_io_data_->configurator(); | |
239 } | |
240 | |
241 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 231 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
242 return url_request_context_getter_.get(); | 232 return url_request_context_getter_.get(); |
243 } | 233 } |
244 | 234 |
245 AwMessagePortService* AwBrowserContext::GetMessagePortService() { | 235 AwMessagePortService* AwBrowserContext::GetMessagePortService() { |
246 if (!message_port_service_.get()) { | 236 if (!message_port_service_.get()) { |
247 message_port_service_.reset( | 237 message_port_service_.reset( |
248 native_factory_->CreateAwMessagePortService()); | 238 native_factory_->CreateAwMessagePortService()); |
249 } | 239 } |
250 return message_port_service_.get(); | 240 return message_port_service_.get(); |
(...skipping 18 matching lines...) Expand all Loading... |
269 | 259 |
270 base::PrefServiceFactory pref_service_factory; | 260 base::PrefServiceFactory pref_service_factory; |
271 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); | 261 pref_service_factory.set_user_prefs(make_scoped_refptr(new AwPrefStore())); |
272 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | 262 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
273 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); | 263 user_pref_service_ = pref_service_factory.Create(pref_registry).Pass(); |
274 | 264 |
275 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); | 265 user_prefs::UserPrefs::Set(this, user_pref_service_.get()); |
276 | 266 |
277 if (data_reduction_proxy_settings_) { | 267 if (data_reduction_proxy_settings_) { |
278 data_reduction_proxy_settings_->InitDataReductionProxySettings( | 268 data_reduction_proxy_settings_->InitDataReductionProxySettings( |
279 user_pref_service_.get(), | 269 user_pref_service_.get(), data_reduction_proxy_io_data_.get(), |
280 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(), | 270 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); | 271 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); |
286 | 272 |
287 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 273 SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
288 } | 274 } |
289 } | 275 } |
290 | 276 |
291 scoped_ptr<content::ZoomLevelDelegate> | 277 scoped_ptr<content::ZoomLevelDelegate> |
292 AwBrowserContext::CreateZoomLevelDelegate( | 278 AwBrowserContext::CreateZoomLevelDelegate( |
293 const base::FilePath& partition_path) { | 279 const base::FilePath& partition_path) { |
294 return nullptr; | 280 return nullptr; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 const scoped_refptr<URLEnumerator>& enumerator) { | 355 const scoped_refptr<URLEnumerator>& enumerator) { |
370 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 356 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
371 // can change in the lifetime of this WebView and may not yet be set here. | 357 // can change in the lifetime of this WebView and may not yet be set here. |
372 // Therefore this initialization path is not used. | 358 // Therefore this initialization path is not used. |
373 enumerator->OnComplete(true); | 359 enumerator->OnComplete(true); |
374 } | 360 } |
375 | 361 |
376 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { | 362 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() { |
377 DCHECK(user_pref_service_.get()); | 363 DCHECK(user_pref_service_.get()); |
378 DCHECK(GetDataReductionProxySettings()); | 364 DCHECK(GetDataReductionProxySettings()); |
379 if (GetDataReductionProxySettings()->statistics_prefs()) | 365 data_reduction_proxy::DataReductionProxyService* |
| 366 data_reduction_proxy_service = |
| 367 GetDataReductionProxySettings()->data_reduction_proxy_service(); |
| 368 DCHECK(data_reduction_proxy_service); |
| 369 if (data_reduction_proxy_service->statistics_prefs()) |
380 return; | 370 return; |
381 // We don't care about commit_delay for now. It is just a dummy value. | 371 // We don't care about commit_delay for now. It is just a dummy value. |
382 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); | 372 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
383 GetDataReductionProxySettings()->EnableCompressionStatisticsLogging( | 373 data_reduction_proxy_service->EnableCompressionStatisticsLogging( |
384 user_pref_service_.get(), | 374 user_pref_service_.get(), |
385 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 375 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
386 commit_delay); | 376 commit_delay); |
387 GetDataReductionProxyIOData()->SetDataReductionProxyStatisticsPrefs( | |
388 GetDataReductionProxySettings()->statistics_prefs()); | |
389 } | 377 } |
390 | 378 |
391 } // namespace android_webview | 379 } // namespace android_webview |
OLD | NEW |