blob: 8d34675b5fe692141c6eee3c937976570bbec88e [file] [log] [blame]
[email protected]7edd78cd2014-05-23 22:31:451// 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.
4
asvitkinec8fa43e92014-11-14 22:39:565#ifndef COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_
6#define COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_
[email protected]7edd78cd2014-05-23 22:31:457
[email protected]bb5d1892014-08-06 06:03:228#include <stdint.h>
blundelldcd73e52015-09-29 14:09:509#include <string>
[email protected]0129c272014-08-02 00:35:1710
[email protected]7edd78cd2014-05-23 22:31:4511#include "base/macros.h"
12
blundell0176f9a2015-10-01 09:09:3513class PrefService;
14
asvitkinecbd420732014-08-26 22:15:4015namespace metrics {
asvitkinec8fa43e92014-11-14 22:39:5616
[email protected]0129c272014-08-02 00:35:1717class MetricsService;
[email protected]7edd78cd2014-05-23 22:31:4518
19// This class limits and documents access to metrics service helper methods.
20// These methods are protected so each user has to inherit own program-specific
21// specialization and enable access there by declaring friends.
22class MetricsServiceAccessor {
23 protected:
asvitkinecbd420732014-08-26 22:15:4024 // Constructor declared as protected to enable inheritance. Descendants should
[email protected]7edd78cd2014-05-23 22:31:4525 // disallow instantiation.
26 MetricsServiceAccessor() {}
27
blundell0176f9a2015-10-01 09:09:3528 // Returns whether metrics reporting is enabled, using the value of the
29 // kMetricsReportingEnabled pref in |pref_service| to determine whether user
30 // has enabled reporting.
31 // NOTE: This method currently does not return the correct value on ChromeOS
32 // and Android due to http://crbug.com/362192 and http://crbug.com/532084. See
33 // ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled().
34 static bool IsMetricsReportingEnabled(PrefService* pref_service);
35
36 // Returns whether metrics reporting is enabled, using the value of
37 // |enabled_in_prefs| to determine whether the user has enabled reporting.
38 // Exists because kMetricsReportingEnabled is currently not used on all
39 // platforms.
40 // TODO(gayane): Consolidate metric prefs on all platforms and eliminate this
41 // method. http://crbug.com/362192, http://crbug.com/532084
42 static bool IsMetricsReportingEnabledWithPrefValue(bool enabled_in_prefs);
43
blundelldcd73e52015-09-29 14:09:5044 // Registers a field trial name and group with |metrics_service| (if not
45 // null), to be used to annotate a UMA report with a particular configuration
46 // state. A UMA report will be annotated with this trial group if and only if
47 // all events in the report were created after the trial is registered. Only
48 // one group name may be registered at a time for a given trial name. Only the
49 // last group name that is registered for a given trial name will be recorded.
50 // The values passed in must not correspond to any real field trial in the
51 // code. Returns true on success.
[email protected]bb5d1892014-08-06 06:03:2252 // See the comment on MetricsService::RegisterSyntheticFieldTrial for details.
blundelldcd73e52015-09-29 14:09:5053 static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service,
54 const std::string& trial_name,
55 const std::string& group_name);
56
57 // Same as RegisterSyntheticFieldTrial above, but takes in the trial name as a
58 // hash rather than computing the hash from the string.
59 static bool RegisterSyntheticFieldTrialWithNameHash(
60 MetricsService* metrics_service,
61 uint32_t trial_name_hash,
62 const std::string& group_name);
63
64 // Same as RegisterSyntheticFieldTrial above, but takes in the trial and group
65 // names as hashes rather than computing those hashes from the strings.
66 static bool RegisterSyntheticFieldTrialWithNameAndGroupHash(
asvitkinec8fa43e92014-11-14 22:39:5667 MetricsService* metrics_service,
asvitkinecbd420732014-08-26 22:15:4068 uint32_t trial_name_hash,
69 uint32_t group_name_hash);
[email protected]0129c272014-08-02 00:35:1770
[email protected]7edd78cd2014-05-23 22:31:4571 private:
72 DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor);
73};
74
asvitkinec8fa43e92014-11-14 22:39:5675} // namespace metrics
76
77#endif // COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_