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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 2517363002: Decouple Metrics Initialization from IO Thread Initialization (Closed)
Patch Set: Fix Unit Test Created 4 years 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 "chrome/browser/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 int GetSwitchValueAsInt(const base::CommandLine& command_line, 244 int GetSwitchValueAsInt(const base::CommandLine& command_line,
245 const std::string& switch_name) { 245 const std::string& switch_name) {
246 int value; 246 int value;
247 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), 247 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
248 &value)) { 248 &value)) {
249 return 0; 249 return 0;
250 } 250 }
251 return value; 251 return value;
252 } 252 }
253 253
254 // This function is for forwarding metrics usage pref changes to the metrics
255 // service on the appropriate thread.
256 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread.
257 void UpdateMetricsUsagePrefsOnUIThread(
258 const std::string& service_name, int message_size, bool is_cellular) {
259 BrowserThread::PostTask(
260 BrowserThread::UI,
261 FROM_HERE,
262 base::Bind([](
263 const std::string& service_name, int message_size, bool is_cellular) {
264 // Some unit tests use IOThread but do not initialize MetricsService. In
265 // that case it's fine to skip the update.
266 auto metrics_service = g_browser_process->metrics_service();
267 if (metrics_service) {
268 metrics_service->UpdateMetricsUsagePrefs(
269 service_name, message_size, is_cellular);
270 }
271 }, service_name, message_size, is_cellular));
272 }
273
254 } // namespace 274 } // namespace
255 275
256 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { 276 class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
257 public: 277 public:
258 explicit SystemURLRequestContextGetter(IOThread* io_thread); 278 explicit SystemURLRequestContextGetter(IOThread* io_thread);
259 279
260 // Implementation for net::UrlRequestContextGetter. 280 // Implementation for net::UrlRequestContextGetter.
261 net::URLRequestContext* GetURLRequestContext() override; 281 net::URLRequestContext* GetURLRequestContext() override;
262 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() 282 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
263 const override; 283 const override;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (value) 418 if (value)
399 value->GetAsBoolean(&is_quic_allowed_by_policy_); 419 value->GetAsBoolean(&is_quic_allowed_by_policy_);
400 420
401 value = policy_service 421 value = policy_service
402 ->GetPolicies(policy::PolicyNamespace( 422 ->GetPolicies(policy::PolicyNamespace(
403 policy::POLICY_DOMAIN_CHROME, std::string())) 423 policy::POLICY_DOMAIN_CHROME, std::string()))
404 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); 424 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled);
405 if (value) 425 if (value)
406 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); 426 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_);
407 427
408 // Some unit tests use IOThread but do not initialize MetricsService. In that
409 // case it is fine not to have |metrics_data_use_forwarder_|.
410 if (g_browser_process->metrics_service()) {
411 // Callback for updating data use prefs should be obtained on UI thread.
412 metrics_data_use_forwarder_ =
413 g_browser_process->metrics_service()->GetDataUseForwardingCallback();
414 }
415
416 chrome_browser_net::SetGlobalSTHDistributor( 428 chrome_browser_net::SetGlobalSTHDistributor(
417 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); 429 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor()));
418 430
419 BrowserThread::SetDelegate(BrowserThread::IO, this); 431 BrowserThread::SetDelegate(BrowserThread::IO, this);
420 } 432 }
421 433
422 IOThread::~IOThread() { 434 IOThread::~IOThread() {
423 // This isn't needed for production code, but in tests, IOThread may 435 // This isn't needed for production code, but in tests, IOThread may
424 // be multiply constructed. 436 // be multiply constructed.
425 BrowserThread::SetDelegate(BrowserThread::IO, NULL); 437 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 #if BUILDFLAG(ANDROID_JAVA_UI) 536 #if BUILDFLAG(ANDROID_JAVA_UI)
525 globals_->external_data_use_observer.reset( 537 globals_->external_data_use_observer.reset(
526 new chrome::android::ExternalDataUseObserver( 538 new chrome::android::ExternalDataUseObserver(
527 globals_->data_use_aggregator.get(), 539 globals_->data_use_aggregator.get(),
528 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), 540 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
529 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); 541 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)));
530 #endif 542 #endif
531 543
532 globals_->system_network_delegate = 544 globals_->system_network_delegate =
533 globals_->data_use_ascriber->CreateNetworkDelegate( 545 globals_->data_use_ascriber->CreateNetworkDelegate(
534 std::move(chrome_network_delegate), metrics_data_use_forwarder_); 546 std::move(chrome_network_delegate),
547 base::Bind(&UpdateMetricsUsagePrefsOnUIThread));
535 548
536 globals_->host_resolver = CreateGlobalHostResolver(net_log_); 549 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
537 550
538 std::map<std::string, std::string> network_quality_estimator_params; 551 std::map<std::string, std::string> network_quality_estimator_params;
539 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, 552 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
540 &network_quality_estimator_params); 553 &network_quality_estimator_params);
541 554
542 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; 555 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider;
543 #if BUILDFLAG(ANDROID_JAVA_UI) 556 #if BUILDFLAG(ANDROID_JAVA_UI)
544 external_estimate_provider.reset( 557 external_estimate_provider.reset(
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1084
1072 context->set_job_factory( 1085 context->set_job_factory(
1073 globals->proxy_script_fetcher_url_request_job_factory.get()); 1086 globals->proxy_script_fetcher_url_request_job_factory.get());
1074 1087
1075 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 1088 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1076 // system URLRequestContext too. There's no reason this should be tied to a 1089 // system URLRequestContext too. There's no reason this should be tied to a
1077 // profile. 1090 // profile.
1078 return context; 1091 return context;
1079 } 1092 }
1080 1093
1081 const metrics::UpdateUsagePrefCallbackType& 1094 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() {
1082 IOThread::GetMetricsDataUseForwarder() { 1095 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread);
1083 return metrics_data_use_forwarder_;
1084 } 1096 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698