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 "components/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
);
30 namespace extensions
{
31 class MetricsPrivateGetIsCrashReportingEnabledFunction
;
32 class FileManagerPrivateIsUMAEnabledFunction
;
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 metrics::MetricsServiceAccessor
{
52 friend void component_updater::RegisterSwReporterComponent(
53 component_updater::ComponentUpdateService
* cus
);
54 friend bool prerender::IsOmniboxEnabled(Profile
* profile
);
55 friend class ChromeExtensionDownloaderFactory
;
56 friend class ChromeRenderMessageFilter
;
57 friend class ::CrashesDOMHandler
;
58 friend class DataReductionProxyChromeSettings
;
59 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction
;
60 friend class extensions::FileManagerPrivateIsUMAEnabledFunction
;
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
&);
67 friend class MetricsServicesManager
;
69 FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest
,
70 MetricsReportingEnabled
);
71 FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest
,
72 CrashReportingEnabled
);
74 // Returns true if prefs::kMetricsReportingEnabled is set.
75 // TODO(asvitkine): Consolidate the method in MetricsStateManager.
76 // TODO(asvitkine): This function does not report the correct value on
77 // Android and ChromeOS, see http://crbug.com/362192.
78 static bool IsMetricsReportingEnabled();
80 // Returns true if crash reporting is enabled. This is set at the platform
81 // level for Android and ChromeOS, and otherwise is the same as
82 // IsMetricsReportingEnabled for desktop Chrome.
83 static bool IsCrashReportingEnabled();
85 // Registers a field trial name and group to be used to annotate a UMA report
86 // with a particular Chrome configuration state. A UMA report will be
87 // annotated with this trial group if and only if all events in the report
88 // were created after the trial is registered. Only one group name may be
89 // registered at a time for a given trial name. Only the last group name that
90 // is registered for a given trial name will be recorded. The values passed
91 // in must not correspond to any real field trial in the code.
92 static bool RegisterSyntheticFieldTrial(const std::string
& trial_name
,
93 const std::string
& group_name
);
95 // Same as RegisterSyntheticFieldTrial above, but takes a hash for the trial
96 // name, rather than computing it from the string.
97 static bool RegisterSyntheticFieldTrialWithNameHash(
98 uint32_t trial_name_hash
,
99 const std::string
& group_name
);
101 DISALLOW_IMPLICIT_CONSTRUCTORS(ChromeMetricsServiceAccessor
);
104 #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_