blob: 38c955cfde54163d25960086b08472f8ab913bf7 [file] [log] [blame]
[email protected]c3cac952014-05-09 01:51:181// 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
blundell695d61f2015-10-21 11:25:535#ifndef COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_
6#define COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_
[email protected]c3cac952014-05-09 01:51:187
dcheng84c358e2016-04-26 07:05:538#include <memory>
9
avi26062922015-12-26 00:14:1810#include "base/macros.h"
robliao4bee5d92016-09-15 14:37:3711#include "base/metrics/field_trial.h"
[email protected]c3cac952014-05-09 01:51:1812#include "base/threading/thread_checker.h"
13
[email protected]544246e2014-06-06 11:22:2814namespace base {
15class FilePath;
16}
17
[email protected]c3cac952014-05-09 01:51:1818namespace metrics {
asvitkinecbd420732014-08-26 22:15:4019class MetricsService;
blundellfecea528d2015-10-21 10:10:2220class MetricsServiceClient;
[email protected]c3cac952014-05-09 01:51:1821}
22
23namespace rappor {
nzolghadrd87a308d2016-12-07 15:45:5624class RapporServiceImpl;
[email protected]c3cac952014-05-09 01:51:1825}
26
holte7b74c622017-01-23 23:13:0727namespace ukm {
28class UkmService;
29}
30
blundell57bcfed2015-09-04 08:44:4531namespace variations {
[email protected]c3cac952014-05-09 01:51:1832class VariationsService;
33}
34
blundell695d61f2015-10-21 11:25:5335namespace metrics_services_manager {
36
37class MetricsServicesManagerClient;
38
blundellfecea528d2015-10-21 10:10:2239// MetricsServicesManager is a helper class for embedders that use the various
40// metrics-related services in a Chrome-like fashion: MetricsService (via its
nzolghadrd87a308d2016-12-07 15:45:5641// client), RapporServiceImpl and VariationsService.
[email protected]c3cac952014-05-09 01:51:1842class MetricsServicesManager {
43 public:
blundellfecea528d2015-10-21 10:10:2244 // Creates the MetricsServicesManager with the given client.
45 explicit MetricsServicesManager(
dcheng84c358e2016-04-26 07:05:5346 std::unique_ptr<MetricsServicesManagerClient> client);
[email protected]c3cac952014-05-09 01:51:1847 virtual ~MetricsServicesManager();
48
robliao4bee5d92016-09-15 14:37:3749 // Returns the preferred entropy provider used to seed persistent activities
50 // based on whether or not metrics reporting is permitted on this client.
51 //
52 // If there's consent to report metrics, this method returns an entropy
53 // provider that has a high source of entropy, partially based on the client
54 // ID. Otherwise, it returns an entropy provider that is based on a low
55 // entropy source.
56 std::unique_ptr<const base::FieldTrial::EntropyProvider>
57 CreateEntropyProvider();
58
[email protected]4a55a712014-06-08 16:50:3459 // Returns the MetricsService, creating it if it hasn't been created yet (and
blundellfecea528d2015-10-21 10:10:2260 // additionally creating the MetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4061 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1862
nzolghadrd87a308d2016-12-07 15:45:5663 // Returns the RapporServiceImpl, creating it if it hasn't been created yet.
64 rappor::RapporServiceImpl* GetRapporServiceImpl();
[email protected]c3cac952014-05-09 01:51:1865
holte7b74c622017-01-23 23:13:0766 // Returns the UkmService, creating it if it hasn't been created yet.
67 ukm::UkmService* GetUkmService();
68
[email protected]c3cac952014-05-09 01:51:1869 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4570 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1871
[email protected]544246e2014-06-06 11:22:2872 // Should be called when a plugin loading error occurs.
73 void OnPluginLoadingError(const base::FilePath& plugin_path);
74
blundell6eb91b7b2015-10-23 07:04:4375 // Some embedders use this method to notify the metrics system when a
76 // renderer process exits unexpectedly.
77 void OnRendererProcessCrash();
78
anthonyvd40dd0302015-02-19 16:11:3479 // Update the managed services when permissions for uploading metrics change.
80 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4681
Brian Whitec459cf52018-01-24 16:55:1482 // Gets the current state of metric reporting.
83 bool IsMetricsReportingEnabled() const;
84
Robert Liao5f1aeb92019-07-17 17:59:5185 // Gets the current state of metrics consent.
86 bool IsMetricsConsentGiven() const;
87
[email protected]c3cac952014-05-09 01:51:1888 private:
holte873fb7c92015-02-19 23:41:2689 // Update the managed services when permissions for recording/uploading
90 // metrics change.
nzolghadrd87a308d2016-12-07 15:45:5691 void UpdateRapporServiceImpl();
holte873fb7c92015-02-19 23:41:2692
blundellfecea528d2015-10-21 10:10:2293 // Returns the MetricsServiceClient, creating it if it hasn't been
[email protected]4a55a712014-06-08 16:50:3494 // created yet (and additionally creating the MetricsService in that case).
blundellfecea528d2015-10-21 10:10:2295 metrics::MetricsServiceClient* GetMetricsServiceClient();
[email protected]4a55a712014-06-08 16:50:3496
holte585f4662015-06-18 19:13:5297 // Update which services are running to match current permissions.
98 void UpdateRunningServices();
99
holte1334c0aa2017-02-09 22:52:41100 // Update the state of UkmService to match current permissions.
101 void UpdateUkmService();
102
Robert Kaplowc9986922017-09-29 02:05:49103 // Update the managed services when permissions for recording/uploading
104 // metrics change.
105 void UpdatePermissions(bool current_may_record,
106 bool current_consent_given,
107 bool current_may_upload);
108
blundellfecea528d2015-10-21 10:10:22109 // The client passed in from the embedder.
François Degrose1dc3bb2017-11-29 00:10:38110 const std::unique_ptr<MetricsServicesManagerClient> client_;
blundellfecea528d2015-10-21 10:10:22111
[email protected]c3cac952014-05-09 01:51:18112 // Ensures that all functions are called from the same thread.
113 base::ThreadChecker thread_checker_;
114
holte873fb7c92015-02-19 23:41:26115 // The current metrics reporting setting.
116 bool may_upload_;
117
118 // The current metrics recording setting.
119 bool may_record_;
120
Robert Kaplowc9986922017-09-29 02:05:49121 // The current metrics setting reflecting if consent was given.
122 bool consent_given_;
123
blundellfecea528d2015-10-21 10:10:22124 // The MetricsServiceClient. Owns the MetricsService.
dcheng84c358e2016-04-26 07:05:53125 std::unique_ptr<metrics::MetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:18126
nzolghadrd87a308d2016-12-07 15:45:56127 // The RapporServiceImpl, for RAPPOR metric uploads.
128 std::unique_ptr<rappor::RapporServiceImpl> rappor_service_;
[email protected]c3cac952014-05-09 01:51:18129
130 // The VariationsService, for server-side experiments infrastructure.
dcheng84c358e2016-04-26 07:05:53131 std::unique_ptr<variations::VariationsService> variations_service_;
[email protected]c3cac952014-05-09 01:51:18132
133 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
134};
135
blundell695d61f2015-10-21 11:25:53136} // namespace metrics_services_manager
137
138#endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_