| 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 // 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(const std::string& service_name, |
| 258 int message_size, |
| 259 bool is_cellular) { |
| 260 BrowserThread::PostTask( |
| 261 BrowserThread::UI, |
| 262 FROM_HERE, |
| 263 base::Bind([](const std::string& service_name, |
| 264 int message_size, |
| 265 bool is_cellular) { |
| 266 // Some unit tests use IOThread but do not initialize |
| 267 // MetricsService. In that case it's fine to skip the update. |
| 268 auto metrics_service = g_browser_process->metrics_service(); |
| 269 if (metrics_service) { |
| 270 metrics_service->UpdateMetricsUsagePrefs(service_name, |
| 271 message_size, |
| 272 is_cellular); |
| 273 } |
| 274 }, |
| 275 service_name, |
| 276 message_size, |
| 277 is_cellular)); |
| 278 } |
| 279 |
| 254 } // namespace | 280 } // namespace |
| 255 | 281 |
| 256 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { | 282 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| 257 public: | 283 public: |
| 258 explicit SystemURLRequestContextGetter(IOThread* io_thread); | 284 explicit SystemURLRequestContextGetter(IOThread* io_thread); |
| 259 | 285 |
| 260 // Implementation for net::UrlRequestContextGetter. | 286 // Implementation for net::UrlRequestContextGetter. |
| 261 net::URLRequestContext* GetURLRequestContext() override; | 287 net::URLRequestContext* GetURLRequestContext() override; |
| 262 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 288 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| 263 const override; | 289 const override; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 if (value) | 424 if (value) |
| 399 value->GetAsBoolean(&is_quic_allowed_by_policy_); | 425 value->GetAsBoolean(&is_quic_allowed_by_policy_); |
| 400 | 426 |
| 401 value = policy_service | 427 value = policy_service |
| 402 ->GetPolicies(policy::PolicyNamespace( | 428 ->GetPolicies(policy::PolicyNamespace( |
| 403 policy::POLICY_DOMAIN_CHROME, std::string())) | 429 policy::POLICY_DOMAIN_CHROME, std::string())) |
| 404 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); | 430 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); |
| 405 if (value) | 431 if (value) |
| 406 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); | 432 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); |
| 407 | 433 |
| 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( | 434 chrome_browser_net::SetGlobalSTHDistributor( |
| 417 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); | 435 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); |
| 418 | 436 |
| 419 BrowserThread::SetDelegate(BrowserThread::IO, this); | 437 BrowserThread::SetDelegate(BrowserThread::IO, this); |
| 420 } | 438 } |
| 421 | 439 |
| 422 IOThread::~IOThread() { | 440 IOThread::~IOThread() { |
| 423 // This isn't needed for production code, but in tests, IOThread may | 441 // This isn't needed for production code, but in tests, IOThread may |
| 424 // be multiply constructed. | 442 // be multiply constructed. |
| 425 BrowserThread::SetDelegate(BrowserThread::IO, NULL); | 443 BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 #if BUILDFLAG(ANDROID_JAVA_UI) | 542 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 525 globals_->external_data_use_observer.reset( | 543 globals_->external_data_use_observer.reset( |
| 526 new chrome::android::ExternalDataUseObserver( | 544 new chrome::android::ExternalDataUseObserver( |
| 527 globals_->data_use_aggregator.get(), | 545 globals_->data_use_aggregator.get(), |
| 528 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), | 546 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), |
| 529 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); | 547 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); |
| 530 #endif | 548 #endif |
| 531 | 549 |
| 532 globals_->system_network_delegate = | 550 globals_->system_network_delegate = |
| 533 globals_->data_use_ascriber->CreateNetworkDelegate( | 551 globals_->data_use_ascriber->CreateNetworkDelegate( |
| 534 std::move(chrome_network_delegate), metrics_data_use_forwarder_); | 552 std::move(chrome_network_delegate), GetMetricsDataUseForwarder()); |
| 535 | 553 |
| 536 globals_->host_resolver = CreateGlobalHostResolver(net_log_); | 554 globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
| 537 | 555 |
| 538 std::map<std::string, std::string> network_quality_estimator_params; | 556 std::map<std::string, std::string> network_quality_estimator_params; |
| 539 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, | 557 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, |
| 540 &network_quality_estimator_params); | 558 &network_quality_estimator_params); |
| 541 | 559 |
| 542 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; | 560 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; |
| 543 #if BUILDFLAG(ANDROID_JAVA_UI) | 561 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 544 external_estimate_provider.reset( | 562 external_estimate_provider.reset( |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 | 1089 |
| 1072 context->set_job_factory( | 1090 context->set_job_factory( |
| 1073 globals->proxy_script_fetcher_url_request_job_factory.get()); | 1091 globals->proxy_script_fetcher_url_request_job_factory.get()); |
| 1074 | 1092 |
| 1075 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 1093 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 1076 // system URLRequestContext too. There's no reason this should be tied to a | 1094 // system URLRequestContext too. There's no reason this should be tied to a |
| 1077 // profile. | 1095 // profile. |
| 1078 return context; | 1096 return context; |
| 1079 } | 1097 } |
| 1080 | 1098 |
| 1081 const metrics::UpdateUsagePrefCallbackType& | 1099 metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() { |
| 1082 IOThread::GetMetricsDataUseForwarder() { | 1100 return base::Bind(&UpdateMetricsUsagePrefsOnUIThread); |
| 1083 return metrics_data_use_forwarder_; | |
| 1084 } | 1101 } |
| OLD | NEW |