| [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> |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 9 | #include <string> |
| [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" |
| 12 | |
| blundell | 0176f9a | 2015-10-01 09:09:35 | [diff] [blame^] | 13 | class PrefService; |
| 14 | |
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 15 | namespace metrics { |
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 16 | |
| [email protected] | 0129c27 | 2014-08-02 00:35:17 | [diff] [blame] | 17 | class MetricsService; |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 18 | |
| 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. |
| 22 | class MetricsServiceAccessor { |
| 23 | protected: |
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 24 | // Constructor declared as protected to enable inheritance. Descendants should |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 25 | // disallow instantiation. |
| 26 | MetricsServiceAccessor() {} |
| 27 | |
| blundell | 0176f9a | 2015-10-01 09:09:35 | [diff] [blame^] | 28 | // 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 | |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 44 | // 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] | bb5d189 | 2014-08-06 06:03:22 | [diff] [blame] | 52 | // See the comment on MetricsService::RegisterSyntheticFieldTrial for details. |
| blundell | dcd73e5 | 2015-09-29 14:09:50 | [diff] [blame] | 53 | 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( |
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 67 | MetricsService* metrics_service, |
| asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 68 | uint32_t trial_name_hash, |
| 69 | uint32_t group_name_hash); |
| [email protected] | 0129c27 | 2014-08-02 00:35:17 | [diff] [blame] | 70 | |
| [email protected] | 7edd78cd | 2014-05-23 22:31:45 | [diff] [blame] | 71 | private: |
| 72 | DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor); |
| 73 | }; |
| 74 | |
| asvitkine | c8fa43e9 | 2014-11-14 22:39:56 | [diff] [blame] | 75 | } // namespace metrics |
| 76 | |
| 77 | #endif // COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_ |