Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: android_webview/browser/aw_browser_context.cc

Issue 2101153003: Remove data reduction proxy code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/aw_browser_policy_connector.h" 9 #include "android_webview/browser/aw_browser_policy_connector.h"
10 #include "android_webview/browser/aw_form_database_service.h" 10 #include "android_webview/browser/aw_form_database_service.h"
11 #include "android_webview/browser/aw_metrics_service_client.h" 11 #include "android_webview/browser/aw_metrics_service_client.h"
12 #include "android_webview/browser/aw_permission_manager.h" 12 #include "android_webview/browser/aw_permission_manager.h"
13 #include "android_webview/browser/aw_quota_manager_bridge.h" 13 #include "android_webview/browser/aw_quota_manager_bridge.h"
14 #include "android_webview/browser/aw_resource_context.h" 14 #include "android_webview/browser/aw_resource_context.h"
15 #include "android_webview/browser/jni_dependency_factory.h" 15 #include "android_webview/browser/jni_dependency_factory.h"
16 #include "android_webview/browser/net/aw_url_request_context_getter.h" 16 #include "android_webview/browser/net/aw_url_request_context_getter.h"
17 #include "android_webview/common/aw_content_client.h" 17 #include "android_webview/common/aw_content_client.h"
18 #include "base/base_paths_android.h" 18 #include "base/base_paths_android.h"
19 #include "base/bind.h" 19 #include "base/bind.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "components/autofill/core/common/autofill_pref_names.h" 21 #include "components/autofill/core/common/autofill_pref_names.h"
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h"
24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref s.h"
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
27 #include "components/data_reduction_proxy/core/browser/data_store.h"
28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
29 #include "components/metrics/metrics_service.h" 22 #include "components/metrics/metrics_service.h"
30 #include "components/policy/core/browser/browser_policy_connector_base.h" 23 #include "components/policy/core/browser/browser_policy_connector_base.h"
31 #include "components/policy/core/browser/configuration_policy_pref_store.h" 24 #include "components/policy/core/browser/configuration_policy_pref_store.h"
32 #include "components/policy/core/browser/url_blacklist_manager.h" 25 #include "components/policy/core/browser/url_blacklist_manager.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 26 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/prefs/in_memory_pref_store.h" 27 #include "components/prefs/in_memory_pref_store.h"
35 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
36 #include "components/prefs/pref_service_factory.h" 29 #include "components/prefs/pref_service_factory.h"
37 #include "components/url_formatter/url_fixer.h" 30 #include "components/url_formatter/url_fixer.h"
38 #include "components/user_prefs/user_prefs.h" 31 #include "components/user_prefs/user_prefs.h"
(...skipping 16 matching lines...) Expand all
55 // authentication. 48 // authentication.
56 const char kAuthAndroidNegotiateAccountType[] = 49 const char kAuthAndroidNegotiateAccountType[] =
57 "auth.android_negotiate_account_type"; 50 "auth.android_negotiate_account_type";
58 51
59 // Whitelist containing servers for which Integrated Authentication is enabled. 52 // Whitelist containing servers for which Integrated Authentication is enabled.
60 const char kAuthServerWhitelist[] = "auth.server_whitelist"; 53 const char kAuthServerWhitelist[] = "auth.server_whitelist";
61 54
62 } // namespace prefs 55 } // namespace prefs
63 56
64 namespace { 57 namespace {
65 // Name of the preference that governs enabling the Data Reduction Proxy.
66 const char kDataReductionProxyEnabled[] = "data_reduction_proxy.enabled";
67 58
68 // Shows notifications which correspond to PersistentPrefStore's reading errors. 59 // Shows notifications which correspond to PersistentPrefStore's reading errors.
69 void HandleReadError(PersistentPrefStore::PrefReadError error) { 60 void HandleReadError(PersistentPrefStore::PrefReadError error) {
70 } 61 }
71 62
72 void DeleteDirRecursively(const base::FilePath& path) { 63 void DeleteDirRecursively(const base::FilePath& path) {
73 if (!base::DeleteFile(path, true)) { 64 if (!base::DeleteFile(path, true)) {
74 // Deleting a non-existent file is considered successful, so this will 65 // Deleting a non-existent file is considered successful, so this will
75 // trigger only in case of real errors. 66 // trigger only in case of real errors.
76 LOG(WARNING) << "Failed to delete " << path.AsUTF8Unsafe(); 67 LOG(WARNING) << "Failed to delete " << path.AsUTF8Unsafe();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = 100 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
110 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
111 102
112 return new policy::URLBlacklistManager(pref_service, background_task_runner, 103 return new policy::URLBlacklistManager(pref_service, background_task_runner,
113 io_task_runner, segment_url_callback, 104 io_task_runner, segment_url_callback,
114 base::Bind(OverrideBlacklistForURL)); 105 base::Bind(OverrideBlacklistForURL));
115 } 106 }
116 107
117 } // namespace 108 } // namespace
118 109
119 // Data reduction proxy is disabled by default.
120 bool AwBrowserContext::data_reduction_proxy_enabled_ = false;
121
122 // Delete the legacy cache dir (in the app data dir) in 10 seconds after init. 110 // Delete the legacy cache dir (in the app data dir) in 10 seconds after init.
123 int AwBrowserContext::legacy_cache_removal_delay_ms_ = 10000; 111 int AwBrowserContext::legacy_cache_removal_delay_ms_ = 10000;
124 112
125 AwBrowserContext::AwBrowserContext( 113 AwBrowserContext::AwBrowserContext(
126 const FilePath path, 114 const FilePath path,
127 JniDependencyFactory* native_factory) 115 JniDependencyFactory* native_factory)
128 : context_storage_path_(path), 116 : context_storage_path_(path),
129 native_factory_(native_factory) { 117 native_factory_(native_factory) {
130 DCHECK(!g_browser_context); 118 DCHECK(!g_browser_context);
131 g_browser_context = this; 119 g_browser_context = this;
(...skipping 17 matching lines...) Expand all
149 } 137 }
150 138
151 // static 139 // static
152 AwBrowserContext* AwBrowserContext::FromWebContents( 140 AwBrowserContext* AwBrowserContext::FromWebContents(
153 content::WebContents* web_contents) { 141 content::WebContents* web_contents) {
154 // This is safe; this is the only implementation of the browser context. 142 // This is safe; this is the only implementation of the browser context.
155 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); 143 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext());
156 } 144 }
157 145
158 // static 146 // static
159 void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) {
160 // Cache the setting value. It is possible that data reduction proxy is
161 // not created yet.
162 data_reduction_proxy_enabled_ = enabled;
163 AwBrowserContext* context = AwBrowserContext::GetDefault();
164 // Can't enable Data reduction proxy if user pref service is not ready.
165 if (context == NULL || context->user_pref_service_.get() == NULL)
166 return;
167 data_reduction_proxy::DataReductionProxySettings* proxy_settings =
168 context->GetDataReductionProxySettings();
169 if (proxy_settings == NULL)
170 return;
171 // At this point, context->PreMainMessageLoopRun() has run, so
172 // context->data_reduction_proxy_io_data() is valid.
173 DCHECK(context->GetDataReductionProxyIOData());
174 context->CreateDataReductionProxyStatisticsIfNecessary();
175 proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_);
176 }
177
178 // static
179 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) { 147 void AwBrowserContext::SetLegacyCacheRemovalDelayForTest(int delay_ms) {
180 legacy_cache_removal_delay_ms_ = delay_ms; 148 legacy_cache_removal_delay_ms_ = delay_ms;
181 } 149 }
182 150
183 void AwBrowserContext::PreMainMessageLoopRun() { 151 void AwBrowserContext::PreMainMessageLoopRun() {
184 FilePath cache_path; 152 FilePath cache_path;
185 const FilePath fallback_cache_dir = 153 const FilePath fallback_cache_dir =
186 GetPath().Append(FILE_PATH_LITERAL("Cache")); 154 GetPath().Append(FILE_PATH_LITERAL("Cache"));
187 if (PathService::Get(base::DIR_CACHE, &cache_path)) { 155 if (PathService::Get(base::DIR_CACHE, &cache_path)) {
188 cache_path = cache_path.Append( 156 cache_path = cache_path.Append(
189 FILE_PATH_LITERAL("org.chromium.android_webview")); 157 FILE_PATH_LITERAL("org.chromium.android_webview"));
190 // Delay the legacy dir removal to not impact startup performance. 158 // Delay the legacy dir removal to not impact startup performance.
191 BrowserThread::PostDelayedTask( 159 BrowserThread::PostDelayedTask(
192 BrowserThread::FILE, FROM_HERE, 160 BrowserThread::FILE, FROM_HERE,
193 base::Bind(&DeleteDirRecursively, fallback_cache_dir), 161 base::Bind(&DeleteDirRecursively, fallback_cache_dir),
194 base::TimeDelta::FromMilliseconds(legacy_cache_removal_delay_ms_)); 162 base::TimeDelta::FromMilliseconds(legacy_cache_removal_delay_ms_));
195 } else { 163 } else {
196 cache_path = fallback_cache_dir; 164 cache_path = fallback_cache_dir;
197 LOG(WARNING) << "Failed to get cache directory for Android WebView. " 165 LOG(WARNING) << "Failed to get cache directory for Android WebView. "
198 << "Using app data directory as a fallback."; 166 << "Using app data directory as a fallback.";
199 } 167 }
200 168
201 browser_policy_connector_.reset(new AwBrowserPolicyConnector()); 169 browser_policy_connector_.reset(new AwBrowserPolicyConnector());
202 170
203 InitUserPrefService(); 171 InitUserPrefService();
204 172
205 url_request_context_getter_ = new AwURLRequestContextGetter( 173 url_request_context_getter_ = new AwURLRequestContextGetter(
206 cache_path, CreateProxyConfigService(), user_pref_service_.get()); 174 cache_path, CreateProxyConfigService(), user_pref_service_.get());
207 175
208 data_reduction_proxy_io_data_.reset(
209 new data_reduction_proxy::DataReductionProxyIOData(
210 data_reduction_proxy::Client::WEBVIEW_ANDROID,
211 data_reduction_proxy::DataReductionProxyParams::kAllowed,
212 url_request_context_getter_->GetNetLog(),
213 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
214 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
215 false /* enable */,
216 GetUserAgent()));
217 data_reduction_proxy_settings_.reset(
218 new data_reduction_proxy::DataReductionProxySettings());
219 std::unique_ptr<data_reduction_proxy::DataStore> store(
220 new data_reduction_proxy::DataStore());
221 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 176 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
222 scoped_refptr<base::SequencedTaskRunner> db_task_runner = 177 scoped_refptr<base::SequencedTaskRunner> db_task_runner =
223 pool->GetSequencedTaskRunnerWithShutdownBehavior( 178 pool->GetSequencedTaskRunnerWithShutdownBehavior(
224 pool->GetSequenceToken(), 179 pool->GetSequenceToken(),
225 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 180 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
226 data_reduction_proxy_service_.reset(
227 new data_reduction_proxy::DataReductionProxyService(
228 data_reduction_proxy_settings_.get(), nullptr,
229 GetAwURLRequestContext(), std::move(store),
230 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
231 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
232 db_task_runner, base::TimeDelta()));
233 data_reduction_proxy_io_data_->SetDataReductionProxyService(
234 data_reduction_proxy_service_->GetWeakPtr());
235
236 visitedlink_master_.reset( 181 visitedlink_master_.reset(
237 new visitedlink::VisitedLinkMaster(this, this, false)); 182 new visitedlink::VisitedLinkMaster(this, this, false));
238 visitedlink_master_->Init(); 183 visitedlink_master_->Init();
239 184
240 form_database_service_.reset( 185 form_database_service_.reset(
241 new AwFormDatabaseService(context_storage_path_)); 186 new AwFormDatabaseService(context_storage_path_));
242 187
243 // Ensure the storage partition is initialized in time for DataReductionProxy.
244 EnsureResourceContextInitialized(this); 188 EnsureResourceContextInitialized(this);
245 189
246 // TODO(dgn) lazy init, see http://crbug.com/521542
247 data_reduction_proxy_settings_->InitDataReductionProxySettings(
248 kDataReductionProxyEnabled, user_pref_service_.get(),
249 data_reduction_proxy_io_data_.get(),
250 std::move(data_reduction_proxy_service_));
251 data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true);
252
253 blacklist_manager_.reset(CreateURLBlackListManager(user_pref_service_.get())); 190 blacklist_manager_.reset(CreateURLBlackListManager(user_pref_service_.get()));
254 191
255 // UMA uses randomly-generated GUIDs (globally unique identifiers) to 192 // UMA uses randomly-generated GUIDs (globally unique identifiers) to
256 // anonymously identify logs. Every WebView-using app on every device 193 // anonymously identify logs. Every WebView-using app on every device
257 // is given a GUID, stored in this file in the app's data directory. 194 // is given a GUID, stored in this file in the app's data directory.
258 const FilePath guid_file_path = 195 const FilePath guid_file_path =
259 GetPath().Append(FILE_PATH_LITERAL("metrics_guid")); 196 GetPath().Append(FILE_PATH_LITERAL("metrics_guid"));
260 197
261 AwMetricsServiceClient::GetInstance()->Initialize( 198 AwMetricsServiceClient::GetInstance()->Initialize(
262 user_pref_service_.get(), 199 user_pref_service_.get(),
(...skipping 11 matching lines...) Expand all
274 if (!quota_manager_bridge_.get()) { 211 if (!quota_manager_bridge_.get()) {
275 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this); 212 quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this);
276 } 213 }
277 return quota_manager_bridge_.get(); 214 return quota_manager_bridge_.get();
278 } 215 }
279 216
280 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { 217 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() {
281 return form_database_service_.get(); 218 return form_database_service_.get();
282 } 219 }
283 220
284 data_reduction_proxy::DataReductionProxySettings*
285 AwBrowserContext::GetDataReductionProxySettings() {
286 return data_reduction_proxy_settings_.get();
287 }
288
289 data_reduction_proxy::DataReductionProxyIOData*
290 AwBrowserContext::GetDataReductionProxyIOData() {
291 return data_reduction_proxy_io_data_.get();
292 }
293
294 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { 221 AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() {
295 return url_request_context_getter_.get(); 222 return url_request_context_getter_.get();
296 } 223 }
297 224
298 AwMessagePortService* AwBrowserContext::GetMessagePortService() { 225 AwMessagePortService* AwBrowserContext::GetMessagePortService() {
299 if (!message_port_service_.get()) { 226 if (!message_port_service_.get()) {
300 message_port_service_.reset( 227 message_port_service_.reset(
301 native_factory_->CreateAwMessagePortService()); 228 native_factory_->CreateAwMessagePortService());
302 } 229 }
303 return message_port_service_.get(); 230 return message_port_service_.get();
304 } 231 }
305 232
306 // Create user pref service 233 // Create user pref service
307 void AwBrowserContext::InitUserPrefService() { 234 void AwBrowserContext::InitUserPrefService() {
308 user_prefs::PrefRegistrySyncable* pref_registry = 235 user_prefs::PrefRegistrySyncable* pref_registry =
309 new user_prefs::PrefRegistrySyncable(); 236 new user_prefs::PrefRegistrySyncable();
310 // We only use the autocomplete feature of Autofill, which is controlled via 237 // We only use the autocomplete feature of Autofill, which is controlled via
311 // the manager_delegate. We don't use the rest of Autofill, which is why it is 238 // the manager_delegate. We don't use the rest of Autofill, which is why it is
312 // hardcoded as disabled here. 239 // hardcoded as disabled here.
313 pref_registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, false); 240 pref_registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, false);
314 pref_registry->RegisterBooleanPref(kDataReductionProxyEnabled, false);
315 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry);
316 policy::URLBlacklistManager::RegisterProfilePrefs(pref_registry); 241 policy::URLBlacklistManager::RegisterProfilePrefs(pref_registry);
317 242
318 pref_registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string()); 243 pref_registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
319 pref_registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType, 244 pref_registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType,
320 std::string()); 245 std::string());
321 246
322 metrics::MetricsService::RegisterPrefs(pref_registry); 247 metrics::MetricsService::RegisterPrefs(pref_registry);
323 248
324 PrefServiceFactory pref_service_factory; 249 PrefServiceFactory pref_service_factory;
325 pref_service_factory.set_user_prefs(make_scoped_refptr( 250 pref_service_factory.set_user_prefs(make_scoped_refptr(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 364 }
440 365
441 void AwBrowserContext::RebuildTable( 366 void AwBrowserContext::RebuildTable(
442 const scoped_refptr<URLEnumerator>& enumerator) { 367 const scoped_refptr<URLEnumerator>& enumerator) {
443 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client 368 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client
444 // can change in the lifetime of this WebView and may not yet be set here. 369 // can change in the lifetime of this WebView and may not yet be set here.
445 // Therefore this initialization path is not used. 370 // Therefore this initialization path is not used.
446 enumerator->OnComplete(true); 371 enumerator->OnComplete(true);
447 } 372 }
448 373
449 void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() {
450 DCHECK(user_pref_service_.get());
451 DCHECK(GetDataReductionProxySettings());
452 data_reduction_proxy::DataReductionProxyService*
453 data_reduction_proxy_service =
454 GetDataReductionProxySettings()->data_reduction_proxy_service();
455 DCHECK(data_reduction_proxy_service);
456 if (data_reduction_proxy_service->compression_stats())
457 return;
458 // We don't care about commit_delay for now. It is just a dummy value.
459 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60);
460 data_reduction_proxy_service->EnableCompressionStatisticsLogging(
461 user_pref_service_.get(),
462 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
463 commit_delay);
464 }
465
466 } // namespace android_webview 374 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/aw_browser_context.h ('k') | android_webview/browser/net/aw_url_request_context_getter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698