blob: e6b247b98541f2dc3f2d7d276ecff293dc99a0e5 [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>
asvitkine6a1c8812016-08-01 22:37:019#include <vector>
[email protected]0129c272014-08-02 00:35:1710
[email protected]7edd78cd2014-05-23 22:31:4511#include "base/macros.h"
thestig345fc9c52017-03-23 22:35:2412#include "base/strings/string_piece.h"
[email protected]7edd78cd2014-05-23 22:31:4513
blundell0176f9a2015-10-01 09:09:3514class PrefService;
15
asvitkinecbd420732014-08-26 22:15:4016namespace metrics {
asvitkinec8fa43e92014-11-14 22:39:5617
[email protected]0129c272014-08-02 00:35:1718class MetricsService;
[email protected]7edd78cd2014-05-23 22:31:4519
20// This class limits and documents access to metrics service helper methods.
21// These methods are protected so each user has to inherit own program-specific
22// specialization and enable access there by declaring friends.
23class MetricsServiceAccessor {
24 protected:
asvitkinecbd420732014-08-26 22:15:4025 // Constructor declared as protected to enable inheritance. Descendants should
[email protected]7edd78cd2014-05-23 22:31:4526 // disallow instantiation.
27 MetricsServiceAccessor() {}
28
blundell0176f9a2015-10-01 09:09:3529 // Returns whether metrics reporting is enabled, using the value of the
30 // kMetricsReportingEnabled pref in |pref_service| to determine whether user
31 // has enabled reporting.
blundell0176f9a2015-10-01 09:09:3532 static bool IsMetricsReportingEnabled(PrefService* pref_service);
33
blundell0176f9a2015-10-01 09:09:3534
blundelldcd73e52015-09-29 14:09:5035 // Registers a field trial name and group with |metrics_service| (if not
36 // null), to be used to annotate a UMA report with a particular configuration
asvitkine6a1c8812016-08-01 22:37:0137 // state. Returns true on success.
38 // See the comment on MetricsService::RegisterSyntheticFieldTrial() for
39 // details.
blundelldcd73e52015-09-29 14:09:5040 static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service,
thestig345fc9c52017-03-23 22:35:2441 base::StringPiece trial_name,
42 base::StringPiece group_name);
blundelldcd73e52015-09-29 14:09:5043
blundelldcd73e52015-09-29 14:09:5044 // Same as RegisterSyntheticFieldTrial above, but takes in the trial and group
45 // names as hashes rather than computing those hashes from the strings.
46 static bool RegisterSyntheticFieldTrialWithNameAndGroupHash(
asvitkinec8fa43e92014-11-14 22:39:5647 MetricsService* metrics_service,
asvitkinecbd420732014-08-26 22:15:4048 uint32_t trial_name_hash,
49 uint32_t group_name_hash);
[email protected]0129c272014-08-02 00:35:1750
Scott Violet4607316b2018-01-23 21:40:3451 // IsMetricsReportingEnabled() in non-official builds unconditionally returns
52 // false. This results in different behavior for tests running in official vs
53 // non-official builds. To get consistent behavior call this with true, which
54 // forces non-official builds to look at the prefs value official builds look
55 // at.
56 static void SetForceIsMetricsReportingEnabledPrefLookup(bool value);
57
[email protected]7edd78cd2014-05-23 22:31:4558 private:
59 DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor);
60};
61
asvitkinec8fa43e92014-11-14 22:39:5662} // namespace metrics
63
64#endif // COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_