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