| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 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. | ||||
| 4 | |||||
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 5 | #ifndef COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_ |
| 6 | #define COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_ | ||||
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 7 | |
| [email protected] | bb5d189 | 2014-08-06 06:03:22 | [diff] [blame] | 8 | #include <stdint.h> |
| asvitkine | 6a1c881 | 2016-08-01 22:37:01 | [diff] [blame] | 9 | #include <vector> |
| [email protected] | 0129c27 | 2014-08-02 00:35:17 | [diff] [blame] | 10 | |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 11 | #include "base/macros.h" |
| thestig | 345fc9c5 | 2017-03-23 22:35:24 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 13 | |
| blundell | 0176f9a | 2015-10-01 09:09:35 | [diff] [blame] | 14 | class PrefService; |
| 15 | |||||
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 16 | namespace metrics { |
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 17 | |
| [email protected] | 0129c27 | 2014-08-02 00:35:17 | [diff] [blame] | 18 | class MetricsService; |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 19 | |
| 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. | ||||
| 23 | class MetricsServiceAccessor { | ||||
| 24 | protected: | ||||
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 25 | // Constructor declared as protected to enable inheritance. Descendants should |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 26 | // disallow instantiation. |
| 27 | MetricsServiceAccessor() {} | ||||
| 28 | |||||
| blundell | 0176f9a | 2015-10-01 09:09:35 | [diff] [blame] | 29 | // 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. | ||||
| blundell | 0176f9a | 2015-10-01 09:09:35 | [diff] [blame] | 32 | static bool IsMetricsReportingEnabled(PrefService* pref_service); |
| 33 | |||||
| blundell | 0176f9a | 2015-10-01 09:09:35 | [diff] [blame] | 34 | |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 35 | // 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 | ||||
| asvitkine | 6a1c881 | 2016-08-01 22:37:01 | [diff] [blame] | 37 | // state. Returns true on success. |
| 38 | // See the comment on MetricsService::RegisterSyntheticFieldTrial() for | ||||
| 39 | // details. | ||||
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 40 | static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service, |
| thestig | 345fc9c5 | 2017-03-23 22:35:24 | [diff] [blame] | 41 | base::StringPiece trial_name, |
| 42 | base::StringPiece group_name); | ||||
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 43 | |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 44 | // 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( | ||||
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 47 | MetricsService* metrics_service, |
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 48 | uint32_t trial_name_hash, |
| 49 | uint32_t group_name_hash); | ||||
| [email protected] | 0129c27 | 2014-08-02 00:35:17 | [diff] [blame] | 50 | |
| Scott Violet | 4607316b | 2018-01-23 21:40:34 | [diff] [blame] | 51 | // 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] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 58 | private: |
| 59 | DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor); | ||||
| 60 | }; | ||||
| 61 | |||||
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 62 | } // namespace metrics |
| 63 | |||||
| 64 | #endif // COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_ | ||||