blob: 546ac0cd507f474792942a9f3990c0bfcd9c81b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/metrics_services_manager.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/variations/metrics_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#endif
// static
// TODO(asvitkine): This function does not report the correct value on Android,
// see http://crbug.com/362192.
bool ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() {
// If the user permits metrics reporting with the checkbox in the
// prefs, we turn on recording. We disable metrics completely for
// non-official builds, or when field trials are forced.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceFieldTrials)) {
return false;
}
bool enabled = false;
#if defined(GOOGLE_CHROME_BUILD)
#if defined(OS_CHROMEOS)
chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
&enabled);
#else
enabled = g_browser_process->local_state()->
GetBoolean(prefs::kMetricsReportingEnabled);
#endif // #if defined(OS_CHROMEOS)
#endif // defined(GOOGLE_CHROME_BUILD)
return enabled;
}
bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() {
#if defined(GOOGLE_CHROME_BUILD)
#if defined(OS_ANDROID)
// Android has its own settings for metrics / crash uploading.
const PrefService* prefs = g_browser_process->local_state();
return prefs->GetBoolean(prefs::kCrashReportingEnabled);
#else
return ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
#endif
#else
return false;
#endif
}
// static
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
const std::string& trial_name,
const std::string& group_name) {
return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name),
group_name);
}
// static
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash(
uint32_t trial_name_hash,
const std::string& group_name) {
return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial(
g_browser_process->metrics_service(),
trial_name_hash,
metrics::HashName(group_name));
}
|