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 #ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
6 #define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
11 #include "base/gtest_prod_util.h"
12 #include "base/macros.h"
13 #include "chrome/browser/metrics/metrics_reporting_state.h"
14 #include "chrome/browser/metrics/metrics_service_accessor.h"
16 class ChromeExtensionDownloaderFactory;
21 class CrashesDOMHandler;
22 class FlashDOMHandler;
25 namespace component_updater {
26 class ComponentUpdateService;
27 void RegisterSwReporterComponent(ComponentUpdateService* cus,
31 namespace extensions {
32 class MetricsPrivateGetIsCrashReportingEnabledFunction;
36 bool IsOmniboxEnabled(Profile* profile);
39 namespace system_logs {
40 class ChromeInternalLogSource;
44 class BrowserOptionsHandler;
47 // This class limits and documents access to metrics service helper methods.
48 // Since these methods are private, each user has to be explicitly declared
49 // as a 'friend' below.
50 class ChromeMetricsServiceAccessor : public MetricsServiceAccessor {
52 friend void component_updater::RegisterSwReporterComponent(
53 component_updater::ComponentUpdateService* cus,
55 friend bool prerender::IsOmniboxEnabled(Profile* profile);
56 friend class ChromeExtensionDownloaderFactory;
57 friend class ChromeRenderMessageFilter;
58 friend class ::CrashesDOMHandler;
59 friend class DataReductionProxyChromeSettings;
60 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction;
61 friend class ::FlashDOMHandler;
62 friend class system_logs::ChromeInternalLogSource;
63 friend class UmaSessionStats;
64 friend class options::BrowserOptionsHandler;
65 friend void InitiateMetricsReportingChange(
66 bool, const OnMetricsReportingCallbackType&);
68 FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
69 MetricsReportingEnabled);
70 FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
71 CrashReportingEnabled);
73 // Returns true if prefs::kMetricsReportingEnabled is set.
74 // TODO(asvitkine): Consolidate the method in MetricsStateManager.
75 // TODO(asvitkine): This function does not report the correct value on
76 // Android and ChromeOS, see http://crbug.com/362192.
77 static bool IsMetricsReportingEnabled();
79 // Returns true if crash reporting is enabled. This is set at the platform
80 // level for Android and ChromeOS, and otherwise is the same as
81 // IsMetricsReportingEnabled for desktop Chrome.
82 static bool IsCrashReportingEnabled();
84 // Registers a field trial name and group to be used to annotate a UMA report
85 // with a particular Chrome configuration state. A UMA report will be
86 // annotated with this trial group if and only if all events in the report
87 // were created after the trial is registered. Only one group name may be
88 // registered at a time for a given trial name. Only the last group name that
89 // is registered for a given trial name will be recorded. The values passed
90 // in must not correspond to any real field trial in the code.
91 static bool RegisterSyntheticFieldTrial(const std::string& trial_name,
92 const std::string& group_name);
94 // Same as RegisterSyntheticFieldTrial above, but takes a hash for the trial
95 // name, rather than computing it from the string.
96 static bool RegisterSyntheticFieldTrialWithNameHash(
97 uint32_t trial_name_hash,
98 const std::string& group_name);
100 DISALLOW_IMPLICIT_CONSTRUCTORS(ChromeMetricsServiceAccessor);
103 #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_