| [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 | |
| asvitkine | 6a1c881 | 2016-08-01 22:37:01 | [diff] [blame] | 44 | // Registers a field trial name and set of groups with |metrics_service| (if |
| 45 | // not null), to be used to annotate a UMA report with a particular |
| 46 | // configuration state. Returns true on success. |
| 47 | // See the comment on MetricsService::RegisterSyntheticMultiGroupFieldTrial() |
| 48 | // for details. |
| 49 | static bool RegisterSyntheticMultiGroupFieldTrial( |
| 50 | MetricsService* metrics_service, |
| thestig | 345fc9c5 | 2017-03-23 22:35:24 | [diff] [blame^] | 51 | base::StringPiece trial_name, |
| asvitkine | 6a1c881 | 2016-08-01 22:37:01 | [diff] [blame] | 52 | const std::vector<uint32_t>& group_name_hashes); |
| 53 | |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 54 | // Same as RegisterSyntheticFieldTrial above, but takes in the trial name as a |
| 55 | // hash rather than computing the hash from the string. |
| 56 | static bool RegisterSyntheticFieldTrialWithNameHash( |
| 57 | MetricsService* metrics_service, |
| 58 | uint32_t trial_name_hash, |
| thestig | 345fc9c5 | 2017-03-23 22:35:24 | [diff] [blame^] | 59 | base::StringPiece group_name); |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 60 | |
| 61 | // Same as RegisterSyntheticFieldTrial above, but takes in the trial and group |
| 62 | // names as hashes rather than computing those hashes from the strings. |
| 63 | static bool RegisterSyntheticFieldTrialWithNameAndGroupHash( |
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 64 | MetricsService* metrics_service, |
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 65 | uint32_t trial_name_hash, |
| 66 | uint32_t group_name_hash); |
| [email protected] | 0129c27 | 2014-08-02 00:35:17 | [diff] [blame] | 67 | |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 68 | private: |
| 69 | DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor); |
| 70 | }; |
| 71 | |
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 72 | } // namespace metrics |
| 73 | |
| 74 | #endif // COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_ |