Chromium Code Reviews| 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 "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 Loading... | |
| 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 void MetricsDataUseForwarderCallback( | |
| 255 const std::string& service_name, int message_size, bool is_cellular) { | |
| 256 BrowserThread::PostTask( | |
| 257 BrowserThread::UI, | |
| 258 FROM_HERE, | |
| 259 base::Bind([]( | |
| 260 const std::string& service_name, int message_size, bool is_cellular) { | |
| 261 // Some unit tests use IOThread but do not initialize MetricsService. In | |
| 262 // that case it's fine to skip the callback. | |
| 263 auto metrics_service = g_browser_process->metrics_service(); | |
| 264 if (metrics_service) { | |
| 265 metrics::UpdateUsagePrefCallbackType callback = | |
| 266 metrics_service->GetDataUseForwardingCallback(); | |
|
Alexei Svitkine (slow)
2016/11/28 23:04:18
If you're doing like this, then maybe you don't ne
robliao
2016/11/29 18:17:43
Because we're doing a IO->UI hop, if we wanted to
Alexei Svitkine (slow)
2016/11/29 18:34:33
Sorry, let me clarify - I'm not suggesting to save
robliao
2016/11/30 02:22:46
Gotcha. That works for me. I didn't know if you fo
| |
| 267 if (!callback.is_null()) | |
| 268 callback.Run(service_name, message_size, is_cellular); | |
| 269 } | |
| 270 }, service_name, message_size, is_cellular)); | |
| 271 } | |
| 272 | |
| 254 } // namespace | 273 } // namespace |
| 255 | 274 |
| 256 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { | 275 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| 257 public: | 276 public: |
| 258 explicit SystemURLRequestContextGetter(IOThread* io_thread); | 277 explicit SystemURLRequestContextGetter(IOThread* io_thread); |
| 259 | 278 |
| 260 // Implementation for net::UrlRequestContextGetter. | 279 // Implementation for net::UrlRequestContextGetter. |
| 261 net::URLRequestContext* GetURLRequestContext() override; | 280 net::URLRequestContext* GetURLRequestContext() override; |
| 262 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 281 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| 263 const override; | 282 const override; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 if (value) | 417 if (value) |
| 399 value->GetAsBoolean(&is_quic_allowed_by_policy_); | 418 value->GetAsBoolean(&is_quic_allowed_by_policy_); |
| 400 | 419 |
| 401 value = policy_service | 420 value = policy_service |
| 402 ->GetPolicies(policy::PolicyNamespace( | 421 ->GetPolicies(policy::PolicyNamespace( |
| 403 policy::POLICY_DOMAIN_CHROME, std::string())) | 422 policy::POLICY_DOMAIN_CHROME, std::string())) |
| 404 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); | 423 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); |
| 405 if (value) | 424 if (value) |
| 406 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); | 425 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); |
| 407 | 426 |
| 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( | 427 chrome_browser_net::SetGlobalSTHDistributor( |
| 417 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); | 428 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); |
| 418 | 429 |
| 419 BrowserThread::SetDelegate(BrowserThread::IO, this); | 430 BrowserThread::SetDelegate(BrowserThread::IO, this); |
| 420 } | 431 } |
| 421 | 432 |
| 422 IOThread::~IOThread() { | 433 IOThread::~IOThread() { |
| 423 // This isn't needed for production code, but in tests, IOThread may | 434 // This isn't needed for production code, but in tests, IOThread may |
| 424 // be multiply constructed. | 435 // be multiply constructed. |
| 425 BrowserThread::SetDelegate(BrowserThread::IO, NULL); | 436 BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 #if BUILDFLAG(ANDROID_JAVA_UI) | 535 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 525 globals_->external_data_use_observer.reset( | 536 globals_->external_data_use_observer.reset( |
| 526 new chrome::android::ExternalDataUseObserver( | 537 new chrome::android::ExternalDataUseObserver( |
| 527 globals_->data_use_aggregator.get(), | 538 globals_->data_use_aggregator.get(), |
| 528 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), | 539 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), |
| 529 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); | 540 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); |
| 530 #endif | 541 #endif |
| 531 | 542 |
| 532 globals_->system_network_delegate = | 543 globals_->system_network_delegate = |
| 533 globals_->data_use_ascriber->CreateNetworkDelegate( | 544 globals_->data_use_ascriber->CreateNetworkDelegate( |
| 534 std::move(chrome_network_delegate), metrics_data_use_forwarder_); | 545 std::move(chrome_network_delegate), |
| 546 base::Bind(&MetricsDataUseForwarderCallback)); | |
| 535 | 547 |
| 536 globals_->host_resolver = CreateGlobalHostResolver(net_log_); | 548 globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
| 537 | 549 |
| 538 std::map<std::string, std::string> network_quality_estimator_params; | 550 std::map<std::string, std::string> network_quality_estimator_params; |
| 539 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, | 551 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, |
| 540 &network_quality_estimator_params); | 552 &network_quality_estimator_params); |
| 541 | 553 |
| 542 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; | 554 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; |
| 543 #if BUILDFLAG(ANDROID_JAVA_UI) | 555 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 544 external_estimate_provider.reset( | 556 external_estimate_provider.reset( |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 std::move(job_factory); | 1082 std::move(job_factory); |
| 1071 | 1083 |
| 1072 context->set_job_factory( | 1084 context->set_job_factory( |
| 1073 globals->proxy_script_fetcher_url_request_job_factory.get()); | 1085 globals->proxy_script_fetcher_url_request_job_factory.get()); |
| 1074 | 1086 |
| 1075 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 1087 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 1076 // system URLRequestContext too. There's no reason this should be tied to a | 1088 // system URLRequestContext too. There's no reason this should be tied to a |
| 1077 // profile. | 1089 // profile. |
| 1078 return context; | 1090 return context; |
| 1079 } | 1091 } |
| 1080 | |
| 1081 const metrics::UpdateUsagePrefCallbackType& | |
| 1082 IOThread::GetMetricsDataUseForwarder() { | |
| 1083 return metrics_data_use_forwarder_; | |
| 1084 } | |
| OLD | NEW |