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/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/common/pref_names.h"
10 #include "components/metrics/metrics_service.h"
11 #include "components/variations/metrics_util.h"
13 #if defined(OS_CHROMEOS)
14 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 bool ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() {
20 const PrefService
* local_state
= g_browser_process
->local_state();
22 const PrefService::Preference
* uma_pref
=
23 local_state
->FindPreference(prefs::kMetricsReportingEnabled
);
25 bool success
= uma_pref
->GetValue()->GetAsBoolean(&result
);
32 bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() {
33 #if defined(GOOGLE_CHROME_BUILD)
34 #if defined(OS_CHROMEOS)
35 bool reporting_enabled
= false;
36 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
38 return reporting_enabled
;
39 #elif defined(OS_ANDROID)
40 // Android has its own settings for metrics / crash uploading.
41 const PrefService
* prefs
= g_browser_process
->local_state();
42 return prefs
->GetBoolean(prefs::kCrashReportingEnabled
);
44 return ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
52 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
53 const std::string
& trial_name
,
54 const std::string
& group_name
) {
55 return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name
),
60 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash(
61 uint32_t trial_name_hash
,
62 const std::string
& group_name
) {
63 return MetricsServiceAccessor::RegisterSyntheticFieldTrial(
64 g_browser_process
->metrics_service(),
66 metrics::HashName(group_name
));