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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/io_thread.cc
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 662c9e7b349f2cd1359adea8257f4aa60cd90f37..044f45a9f8139d1e0614236a3d37e7c1461fa0f4 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -251,6 +251,26 @@ int GetSwitchValueAsInt(const base::CommandLine& command_line,
return value;
}
+// This function is for forwarding metrics usage pref changes to the metrics
+// service on the appropriate thread.
+// TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread.
+void UpdateMetricsUsagePrefsOnUIThread(
+ const std::string& service_name, int message_size, bool is_cellular) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind([](
+ const std::string& service_name, int message_size, bool is_cellular) {
+ // Some unit tests use IOThread but do not initialize MetricsService. In
+ // that case it's fine to skip the update.
+ auto metrics_service = g_browser_process->metrics_service();
+ if (metrics_service) {
+ metrics_service->UpdateMetricsUsagePrefs(
+ service_name, message_size, is_cellular);
+ }
+ }, service_name, message_size, is_cellular));
+}
+
} // namespace
class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
@@ -405,14 +425,6 @@ IOThread::IOThread(
if (value)
value->GetAsBoolean(&http_09_on_non_default_ports_enabled_);
- // Some unit tests use IOThread but do not initialize MetricsService. In that
- // case it is fine not to have |metrics_data_use_forwarder_|.
- if (g_browser_process->metrics_service()) {
- // Callback for updating data use prefs should be obtained on UI thread.
- metrics_data_use_forwarder_ =
- g_browser_process->metrics_service()->GetDataUseForwardingCallback();
- }
-
chrome_browser_net::SetGlobalSTHDistributor(
std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor()));
@@ -531,7 +543,8 @@ void IOThread::Init() {
globals_->system_network_delegate =
globals_->data_use_ascriber->CreateNetworkDelegate(
- std::move(chrome_network_delegate), metrics_data_use_forwarder_);
+ std::move(chrome_network_delegate),
+ base::Bind(&UpdateMetricsUsagePrefsOnUIThread));
globals_->host_resolver = CreateGlobalHostResolver(net_log_);
@@ -1078,7 +1091,6 @@ net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext(
return context;
}
-const metrics::UpdateUsagePrefCallbackType&
-IOThread::GetMetricsDataUseForwarder() {
- return metrics_data_use_forwarder_;
+metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() {
+ return base::Bind(&UpdateMetricsUsagePrefsOnUIThread);
}

Powered by Google App Engine
This is Rietveld 408576698