[email protected] | c3cac95 | 2014-05-09 01:51:18 | [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 | |
blundell | 695d61f | 2015-10-21 11:25:53 | [diff] [blame] | 5 | #ifndef COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_ |
| 6 | #define COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_ |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 7 | |
dcheng | 84c358e | 2016-04-26 07:05:53 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 10 | #include "base/macros.h" |
robliao | 4bee5d9 | 2016-09-15 14:37:37 | [diff] [blame] | 11 | #include "base/metrics/field_trial.h" |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 12 | #include "base/threading/thread_checker.h" |
| 13 | |
[email protected] | 544246e | 2014-06-06 11:22:28 | [diff] [blame] | 14 | namespace base { |
| 15 | class FilePath; |
| 16 | } |
| 17 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 18 | namespace metrics { |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 19 | class MetricsService; |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 20 | class MetricsServiceClient; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 21 | } |
| 22 | |
holte | 7b74c62 | 2017-01-23 23:13:07 | [diff] [blame] | 23 | namespace ukm { |
| 24 | class UkmService; |
| 25 | } |
| 26 | |
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame] | 27 | namespace variations { |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 28 | class VariationsService; |
| 29 | } |
| 30 | |
blundell | 695d61f | 2015-10-21 11:25:53 | [diff] [blame] | 31 | namespace metrics_services_manager { |
| 32 | |
| 33 | class MetricsServicesManagerClient; |
| 34 | |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 35 | // MetricsServicesManager is a helper class for embedders that use the various |
| 36 | // metrics-related services in a Chrome-like fashion: MetricsService (via its |
Alexei Svitkine | 2d96608 | 2021-02-04 23:25:06 | [diff] [blame] | 37 | // client) and VariationsService. |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 38 | class MetricsServicesManager { |
| 39 | public: |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 40 | // Creates the MetricsServicesManager with the given client. |
| 41 | explicit MetricsServicesManager( |
dcheng | 84c358e | 2016-04-26 07:05:53 | [diff] [blame] | 42 | std::unique_ptr<MetricsServicesManagerClient> client); |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 43 | virtual ~MetricsServicesManager(); |
| 44 | |
robliao | 4bee5d9 | 2016-09-15 14:37:37 | [diff] [blame] | 45 | // Returns the preferred entropy provider used to seed persistent activities |
| 46 | // based on whether or not metrics reporting is permitted on this client. |
| 47 | // |
| 48 | // If there's consent to report metrics, this method returns an entropy |
| 49 | // provider that has a high source of entropy, partially based on the client |
| 50 | // ID. Otherwise, it returns an entropy provider that is based on a low |
| 51 | // entropy source. |
| 52 | std::unique_ptr<const base::FieldTrial::EntropyProvider> |
| 53 | CreateEntropyProvider(); |
| 54 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 55 | // Returns the MetricsService, creating it if it hasn't been created yet (and |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 56 | // additionally creating the MetricsServiceClient in that case). |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 57 | metrics::MetricsService* GetMetricsService(); |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 58 | |
holte | 7b74c62 | 2017-01-23 23:13:07 | [diff] [blame] | 59 | // Returns the UkmService, creating it if it hasn't been created yet. |
| 60 | ukm::UkmService* GetUkmService(); |
| 61 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 62 | // Returns the VariationsService, creating it if it hasn't been created yet. |
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame] | 63 | variations::VariationsService* GetVariationsService(); |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 64 | |
[email protected] | 544246e | 2014-06-06 11:22:28 | [diff] [blame] | 65 | // Should be called when a plugin loading error occurs. |
| 66 | void OnPluginLoadingError(const base::FilePath& plugin_path); |
| 67 | |
blundell | 6eb91b7b | 2015-10-23 07:04:43 | [diff] [blame] | 68 | // Some embedders use this method to notify the metrics system when a |
| 69 | // renderer process exits unexpectedly. |
| 70 | void OnRendererProcessCrash(); |
| 71 | |
anthonyvd | 40dd030 | 2015-02-19 16:11:34 | [diff] [blame] | 72 | // Update the managed services when permissions for uploading metrics change. |
| 73 | void UpdateUploadPermissions(bool may_upload); |
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 74 | |
Brian White | c459cf5 | 2018-01-24 16:55:14 | [diff] [blame] | 75 | // Gets the current state of metric reporting. |
| 76 | bool IsMetricsReportingEnabled() const; |
| 77 | |
Robert Liao | 5f1aeb9 | 2019-07-17 17:59:51 | [diff] [blame] | 78 | // Gets the current state of metrics consent. |
| 79 | bool IsMetricsConsentGiven() const; |
| 80 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 81 | private: |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 82 | // Returns the MetricsServiceClient, creating it if it hasn't been |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 83 | // created yet (and additionally creating the MetricsService in that case). |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 84 | metrics::MetricsServiceClient* GetMetricsServiceClient(); |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 85 | |
holte | 585f466 | 2015-06-18 19:13:52 | [diff] [blame] | 86 | // Update which services are running to match current permissions. |
| 87 | void UpdateRunningServices(); |
| 88 | |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 89 | // Update the state of UkmService to match current permissions. |
| 90 | void UpdateUkmService(); |
| 91 | |
Robert Kaplow | c998692 | 2017-09-29 02:05:49 | [diff] [blame] | 92 | // Update the managed services when permissions for recording/uploading |
| 93 | // metrics change. |
| 94 | void UpdatePermissions(bool current_may_record, |
| 95 | bool current_consent_given, |
| 96 | bool current_may_upload); |
| 97 | |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 98 | // The client passed in from the embedder. |
François Degros | e1dc3bb | 2017-11-29 00:10:38 | [diff] [blame] | 99 | const std::unique_ptr<MetricsServicesManagerClient> client_; |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 100 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 101 | // Ensures that all functions are called from the same thread. |
| 102 | base::ThreadChecker thread_checker_; |
| 103 | |
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame] | 104 | // The current metrics reporting setting. |
| 105 | bool may_upload_; |
| 106 | |
| 107 | // The current metrics recording setting. |
| 108 | bool may_record_; |
| 109 | |
Robert Kaplow | c998692 | 2017-09-29 02:05:49 | [diff] [blame] | 110 | // The current metrics setting reflecting if consent was given. |
| 111 | bool consent_given_; |
| 112 | |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 113 | // The MetricsServiceClient. Owns the MetricsService. |
dcheng | 84c358e | 2016-04-26 07:05:53 | [diff] [blame] | 114 | std::unique_ptr<metrics::MetricsServiceClient> metrics_service_client_; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 115 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 116 | // The VariationsService, for server-side experiments infrastructure. |
dcheng | 84c358e | 2016-04-26 07:05:53 | [diff] [blame] | 117 | std::unique_ptr<variations::VariationsService> variations_service_; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 118 | |
| 119 | DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); |
| 120 | }; |
| 121 | |
blundell | 695d61f | 2015-10-21 11:25:53 | [diff] [blame] | 122 | } // namespace metrics_services_manager |
| 123 | |
| 124 | #endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_ |