Revert of Merge apps/pref* to extensions/browser/pref* (patchset #1 of https://codere...
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_reporting_state.cc
bloba3a6bece05330971fddb563a271a55b5be0b0fb7
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
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/metrics_reporting_state.h"
7 #include "base/threading/thread_restrictions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/installer/util/google_update_settings.h"
10 #include "components/metrics/metrics_service.h"
12 bool ResolveMetricsReportingEnabled(bool enabled) {
13 // GoogleUpdateSettings touches the disk from the UI thread. MetricsService
14 // also calls GoogleUpdateSettings below. http://crbug/62626
15 base::ThreadRestrictions::ScopedAllowIO allow_io;
17 GoogleUpdateSettings::SetCollectStatsConsent(enabled);
18 bool update_pref = GoogleUpdateSettings::GetCollectStatsConsent();
20 if (enabled != update_pref)
21 DVLOG(1) << "Unable to set crash report status to " << enabled;
23 // Only change the pref if GoogleUpdateSettings::GetCollectStatsConsent
24 // succeeds.
25 enabled = update_pref;
27 MetricsService* metrics = g_browser_process->metrics_service();
28 if (metrics) {
29 if (enabled)
30 metrics->Start();
31 else
32 metrics->Stop();
35 return enabled;