QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_metrics_service_accessor.cc
blob546ac0cd507f474792942a9f3990c0bfcd9c81b5
1 // Copyright 2014 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/chrome_metrics_service_accessor.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/metrics/metrics_services_manager.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/metrics/metrics_service.h"
14 #include "components/variations/metrics_util.h"
16 #if defined(OS_CHROMEOS)
17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #endif
20 // static
21 // TODO(asvitkine): This function does not report the correct value on Android,
22 // see http://crbug.com/362192.
23 bool ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() {
24 // If the user permits metrics reporting with the checkbox in the
25 // prefs, we turn on recording. We disable metrics completely for
26 // non-official builds, or when field trials are forced.
27 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
28 switches::kForceFieldTrials)) {
29 return false;
32 bool enabled = false;
33 #if defined(GOOGLE_CHROME_BUILD)
34 #if defined(OS_CHROMEOS)
35 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
36 &enabled);
37 #else
38 enabled = g_browser_process->local_state()->
39 GetBoolean(prefs::kMetricsReportingEnabled);
40 #endif // #if defined(OS_CHROMEOS)
41 #endif // defined(GOOGLE_CHROME_BUILD)
42 return enabled;
45 bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() {
46 #if defined(GOOGLE_CHROME_BUILD)
47 #if defined(OS_ANDROID)
48 // Android has its own settings for metrics / crash uploading.
49 const PrefService* prefs = g_browser_process->local_state();
50 return prefs->GetBoolean(prefs::kCrashReportingEnabled);
51 #else
52 return ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
53 #endif
54 #else
55 return false;
56 #endif
59 // static
60 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
61 const std::string& trial_name,
62 const std::string& group_name) {
63 return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name),
64 group_name);
67 // static
68 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash(
69 uint32_t trial_name_hash,
70 const std::string& group_name) {
71 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial(
72 g_browser_process->metrics_service(),
73 trial_name_hash,
74 metrics::HashName(group_name));