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

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

Issue 2517363002: Decouple Metrics Initialization from IO Thread Initialization (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/io_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/debug/leak_tracker.h" 15 #include "base/debug/leak_tracker.h"
16 #include "base/environment.h" 16 #include "base/environment.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/logging.h"
19 #include "base/macros.h" 18 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
21 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
22 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
23 #include "base/stl_util.h" 22 #include "base/stl_util.h"
24 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
26 #include "base/strings/string_split.h" 25 #include "base/strings/string_split.h"
27 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
28 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (value) 397 if (value)
399 value->GetAsBoolean(&is_quic_allowed_by_policy_); 398 value->GetAsBoolean(&is_quic_allowed_by_policy_);
400 399
401 value = policy_service 400 value = policy_service
402 ->GetPolicies(policy::PolicyNamespace( 401 ->GetPolicies(policy::PolicyNamespace(
403 policy::POLICY_DOMAIN_CHROME, std::string())) 402 policy::POLICY_DOMAIN_CHROME, std::string()))
404 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); 403 .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled);
405 if (value) 404 if (value)
406 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); 405 value->GetAsBoolean(&http_09_on_non_default_ports_enabled_);
407 406
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( 407 chrome_browser_net::SetGlobalSTHDistributor(
417 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); 408 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor()));
418 409
419 BrowserThread::SetDelegate(BrowserThread::IO, this); 410 BrowserThread::SetDelegate(BrowserThread::IO, this);
420 } 411 }
421 412
422 IOThread::~IOThread() { 413 IOThread::~IOThread() {
423 // This isn't needed for production code, but in tests, IOThread may 414 // This isn't needed for production code, but in tests, IOThread may
424 // be multiply constructed. 415 // be multiply constructed.
425 BrowserThread::SetDelegate(BrowserThread::IO, NULL); 416 BrowserThread::SetDelegate(BrowserThread::IO, NULL);
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1062
1072 context->set_job_factory( 1063 context->set_job_factory(
1073 globals->proxy_script_fetcher_url_request_job_factory.get()); 1064 globals->proxy_script_fetcher_url_request_job_factory.get());
1074 1065
1075 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 1066 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1076 // system URLRequestContext too. There's no reason this should be tied to a 1067 // system URLRequestContext too. There's no reason this should be tied to a
1077 // profile. 1068 // profile.
1078 return context; 1069 return context;
1079 } 1070 }
1080 1071
1072 void IOThread::InitMetricsDataUseForwarder() {
1073 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1074 #if DCHECK_IS_ON()
1075 metrics_data_use_forwarder_set_ = true;
1076 #endif
1077 // Some unit tests use IOThread but do not initialize MetricsService. In that
1078 // case it is fine not to have |metrics_data_use_forwarder_|.
1079 if (g_browser_process->metrics_service()) {
1080 // Callback for updating data use prefs should be obtained on UI thread.
1081 metrics_data_use_forwarder_ =
1082 g_browser_process->metrics_service()->GetDataUseForwardingCallback();
1083 }
1084 }
1085
1081 const metrics::UpdateUsagePrefCallbackType& 1086 const metrics::UpdateUsagePrefCallbackType&
1082 IOThread::GetMetricsDataUseForwarder() { 1087 IOThread::GetMetricsDataUseForwarder() {
1088 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1089 #if DCHECK_IS_ON()
Alexei Svitkine (slow) 2016/11/22 16:29:46 Nit: I'd remove these ifdefs. I think the readabi
robliao 2016/11/22 18:02:37 Let's keep them for now. 4 bytes saved here and th
mmenke 2016/11/22 18:09:06 Why is this even needed? Can't we just do DCHECK(
robliao 2016/11/22 18:10:27 metrics_data_use_forwarder_ will be null/empty on
mmenke 2016/11/22 18:20:58 I don't think that's document in either io_thread.
robliao 2016/11/22 19:00:57 Done and done.
1090 DCHECK(metrics_data_use_forwarder_set_);
1091 #endif
1083 return metrics_data_use_forwarder_; 1092 return metrics_data_use_forwarder_;
1084 } 1093 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698