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
igurator.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" | 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 using data_reduction_proxy::DataReductionProxyConfigurator; |
40 using data_reduction_proxy::DataReductionProxyEventStore; | 40 using data_reduction_proxy::DataReductionProxyEventStore; |
41 using data_reduction_proxy::DataReductionProxySettings; | 41 using data_reduction_proxy::DataReductionProxySettings; |
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 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); | 128 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); |
129 } | 129 } |
130 | 130 |
131 // static | 131 // static |
132 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { | 132 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { |
133 legacy_cache_removal_delay_ms_ = delay_ms; | 133 legacy_cache_removal_delay_ms_ = delay_ms; |
134 } | 134 } |
135 | 135 |
136 void AwBrowserContext::PreMainMessageLoopRun() { | 136 void AwBrowserContext::PreMainMessageLoopRun() { |
137 cookie_store_ = CreateCookieStore(this); | 137 cookie_store_ = CreateCookieStore(this); |
138 data_reduction_proxy_settings_.reset( | |
139 new DataReductionProxySettings( | |
140 new data_reduction_proxy::DataReductionProxyParams( | |
141 data_reduction_proxy::DataReductionProxyParams::kAllowed))); | |
142 data_reduction_proxy_event_store_.reset( | |
143 new DataReductionProxyEventStore( | |
144 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))); | |
145 scoped_ptr<DataReductionProxyConfigService> | |
146 data_reduction_proxy_config_service( | |
147 new DataReductionProxyConfigService( | |
148 scoped_ptr<net::ProxyConfigService>( | |
149 CreateProxyConfigService()).Pass())); | |
150 if (data_reduction_proxy_settings_.get()) { | |
151 data_reduction_proxy_configurator_.reset( | |
152 new data_reduction_proxy::DataReductionProxyConfigTracker( | |
153 base::Bind(&DataReductionProxyConfigService::UpdateProxyConfig, | |
154 base::Unretained( | |
155 data_reduction_proxy_config_service.get())), | |
156 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | |
157 data_reduction_proxy_settings_->SetProxyConfigurator( | |
158 data_reduction_proxy_configurator_.get()); | |
159 } | |
160 | |
161 FilePath cache_path; | 138 FilePath cache_path; |
162 const FilePath fallback_cache_dir = | 139 const FilePath fallback_cache_dir = |
163 GetPath().Append(FILE_PATH_LITERAL("Cache")); | 140 GetPath().Append(FILE_PATH_LITERAL("Cache")); |
164 if (PathService::Get(base::DIR_CACHE, &cache_path)) { | 141 if (PathService::Get(base::DIR_CACHE, &cache_path)) { |
165 cache_path = cache_path.Append( | 142 cache_path = cache_path.Append( |
166 FILE_PATH_LITERAL("org.chromium.android_webview")); | 143 FILE_PATH_LITERAL("org.chromium.android_webview")); |
167 // Delay the legacy dir removal to not impact startup performance. | 144 // Delay the legacy dir removal to not impact startup performance. |
168 BrowserThread::PostDelayedTask( | 145 BrowserThread::PostDelayedTask( |
169 BrowserThread::FILE, FROM_HERE, | 146 BrowserThread::FILE, FROM_HERE, |
170 base::Bind(&DeleteDirRecursively, fallback_cache_dir), | 147 base::Bind(&DeleteDirRecursively, fallback_cache_dir), |
171 base::TimeDelta::FromMilliseconds(legacy_cache_removal_delay_ms_)); | 148 base::TimeDelta::FromMilliseconds(legacy_cache_removal_delay_ms_)); |
172 } else { | 149 } else { |
173 cache_path = fallback_cache_dir; | 150 cache_path = fallback_cache_dir; |
174 LOG(WARNING) << "Failed to get cache directory for Android WebView. " | 151 LOG(WARNING) << "Failed to get cache directory for Android WebView. " |
175 << "Using app data directory as a fallback."; | 152 << "Using app data directory as a fallback."; |
176 } | 153 } |
177 url_request_context_getter_ = | 154 url_request_context_getter_ = |
178 new AwURLRequestContextGetter(cache_path, | 155 new AwURLRequestContextGetter( |
179 cookie_store_.get(), | 156 cache_path, cookie_store_.get(), |
180 data_reduction_proxy_config_service.Pass()); | 157 make_scoped_ptr(CreateProxyConfigService()).Pass()); |
| 158 |
| 159 data_reduction_proxy_settings_.reset( |
| 160 new DataReductionProxySettings( |
| 161 new data_reduction_proxy::DataReductionProxyParams( |
| 162 data_reduction_proxy::DataReductionProxyParams::kAllowed))); |
| 163 data_reduction_proxy_event_store_.reset( |
| 164 new DataReductionProxyEventStore( |
| 165 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))); |
| 166 data_reduction_proxy_configurator_.reset( |
| 167 new data_reduction_proxy::DataReductionProxyConfigurator( |
| 168 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 169 url_request_context_getter_->GetNetLog(), |
| 170 data_reduction_proxy_event_store_.get())); |
| 171 data_reduction_proxy_settings_->SetProxyConfigurator( |
| 172 data_reduction_proxy_configurator_.get()); |
181 | 173 |
182 visitedlink_master_.reset( | 174 visitedlink_master_.reset( |
183 new visitedlink::VisitedLinkMaster(this, this, false)); | 175 new visitedlink::VisitedLinkMaster(this, this, false)); |
184 visitedlink_master_->Init(); | 176 visitedlink_master_->Init(); |
185 | 177 |
186 form_database_service_.reset( | 178 form_database_service_.reset( |
187 new AwFormDatabaseService(context_storage_path_)); | 179 new AwFormDatabaseService(context_storage_path_)); |
188 } | 180 } |
189 | 181 |
190 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 182 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 221 |
230 DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { | 222 DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { |
231 return data_reduction_proxy_settings_.get(); | 223 return data_reduction_proxy_settings_.get(); |
232 } | 224 } |
233 | 225 |
234 DataReductionProxyEventStore* | 226 DataReductionProxyEventStore* |
235 AwBrowserContext::GetDataReductionProxyEventStore() { | 227 AwBrowserContext::GetDataReductionProxyEventStore() { |
236 return data_reduction_proxy_event_store_.get(); | 228 return data_reduction_proxy_event_store_.get(); |
237 } | 229 } |
238 | 230 |
| 231 data_reduction_proxy::DataReductionProxyConfigurator* |
| 232 AwBrowserContext::GetDataReductionProxyConfigurator() { |
| 233 return data_reduction_proxy_configurator_.get(); |
| 234 } |
| 235 |
239 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { | 236 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { |
240 return url_request_context_getter_.get(); | 237 return url_request_context_getter_.get(); |
241 } | 238 } |
242 | 239 |
243 // Create user pref service for autofill functionality. | 240 // Create user pref service for autofill functionality. |
244 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 241 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
245 if (user_pref_service_) | 242 if (user_pref_service_) |
246 return; | 243 return; |
247 | 244 |
248 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | 245 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 data_reduction_proxy_statistics_ = | 367 data_reduction_proxy_statistics_ = |
371 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>( | 368 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>( |
372 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | 369 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( |
373 user_pref_service_.get(), | 370 user_pref_service_.get(), |
374 base::MessageLoopProxy::current(), | 371 base::MessageLoopProxy::current(), |
375 commit_delay)); | 372 commit_delay)); |
376 } | 373 } |
377 } | 374 } |
378 | 375 |
379 } // namespace android_webview | 376 } // namespace android_webview |
OLD | NEW |