blob: 912bf9ac541deff62e97df790a2dbf753fe809a6 [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:1821class MetricsStateManager;
22}
23
24namespace rappor {
nzolghadrd87a308d2016-12-07 15:45:5625class RapporServiceImpl;
[email protected]c3cac952014-05-09 01:51:1826}
27
holte7b74c622017-01-23 23:13:0728namespace ukm {
29class UkmService;
30}
31
blundell57bcfed2015-09-04 08:44:4532namespace variations {
[email protected]c3cac952014-05-09 01:51:1833class VariationsService;
34}
35
blundell695d61f2015-10-21 11:25:5336namespace metrics_services_manager {
37
38class MetricsServicesManagerClient;
39
blundellfecea528d2015-10-21 10:10:2240// MetricsServicesManager is a helper class for embedders that use the various
41// metrics-related services in a Chrome-like fashion: MetricsService (via its
nzolghadrd87a308d2016-12-07 15:45:5642// client), RapporServiceImpl and VariationsService.
[email protected]c3cac952014-05-09 01:51:1843class MetricsServicesManager {
44 public:
blundellfecea528d2015-10-21 10:10:2245 // Creates the MetricsServicesManager with the given client.
46 explicit MetricsServicesManager(
dcheng84c358e2016-04-26 07:05:5347 std::unique_ptr<MetricsServicesManagerClient> client);
[email protected]c3cac952014-05-09 01:51:1848 virtual ~MetricsServicesManager();
49
robliao4bee5d92016-09-15 14:37:3750 // Returns the preferred entropy provider used to seed persistent activities
51 // based on whether or not metrics reporting is permitted on this client.
52 //
53 // If there's consent to report metrics, this method returns an entropy
54 // provider that has a high source of entropy, partially based on the client
55 // ID. Otherwise, it returns an entropy provider that is based on a low
56 // entropy source.
57 std::unique_ptr<const base::FieldTrial::EntropyProvider>
58 CreateEntropyProvider();
59
[email protected]4a55a712014-06-08 16:50:3460 // Returns the MetricsService, creating it if it hasn't been created yet (and
blundellfecea528d2015-10-21 10:10:2261 // additionally creating the MetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4062 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1863
nzolghadrd87a308d2016-12-07 15:45:5664 // Returns the RapporServiceImpl, creating it if it hasn't been created yet.
65 rappor::RapporServiceImpl* GetRapporServiceImpl();
[email protected]c3cac952014-05-09 01:51:1866
holte7b74c622017-01-23 23:13:0767 // Returns the UkmService, creating it if it hasn't been created yet.
68 ukm::UkmService* GetUkmService();
69
[email protected]c3cac952014-05-09 01:51:1870 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4571 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1872
[email protected]544246e2014-06-06 11:22:2873 // Should be called when a plugin loading error occurs.
74 void OnPluginLoadingError(const base::FilePath& plugin_path);
75
blundell6eb91b7b2015-10-23 07:04:4376 // Some embedders use this method to notify the metrics system when a
77 // renderer process exits unexpectedly.
78 void OnRendererProcessCrash();
79
anthonyvd40dd0302015-02-19 16:11:3480 // Update the managed services when permissions for uploading metrics change.
81 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4682
Brian Whitec459cf52018-01-24 16:55:1483 // Gets the current state of metric reporting.
84 bool IsMetricsReportingEnabled() const;
85
[email protected]c3cac952014-05-09 01:51:1886 private:
holte873fb7c92015-02-19 23:41:2687 // Update the managed services when permissions for recording/uploading
88 // metrics change.
nzolghadrd87a308d2016-12-07 15:45:5689 void UpdateRapporServiceImpl();
holte873fb7c92015-02-19 23:41:2690
blundellfecea528d2015-10-21 10:10:2291 // Returns the MetricsServiceClient, creating it if it hasn't been
[email protected]4a55a712014-06-08 16:50:3492 // created yet (and additionally creating the MetricsService in that case).
blundellfecea528d2015-10-21 10:10:2293 metrics::MetricsServiceClient* GetMetricsServiceClient();
[email protected]4a55a712014-06-08 16:50:3494
[email protected]c3cac952014-05-09 01:51:1895 metrics::MetricsStateManager* GetMetricsStateManager();
96
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_