blob: c705745f44f208f9937bba87754aa036d2c763f6 [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
holte7b74c622017-01-23 23:13:0723namespace ukm {
24class UkmService;
25}
26
blundell57bcfed2015-09-04 08:44:4527namespace variations {
[email protected]c3cac952014-05-09 01:51:1828class VariationsService;
29}
30
blundell695d61f2015-10-21 11:25:5331namespace metrics_services_manager {
32
33class MetricsServicesManagerClient;
34
blundellfecea528d2015-10-21 10:10:2235// MetricsServicesManager is a helper class for embedders that use the various
36// metrics-related services in a Chrome-like fashion: MetricsService (via its
Alexei Svitkine2d966082021-02-04 23:25:0637// client) and VariationsService.
[email protected]c3cac952014-05-09 01:51:1838class MetricsServicesManager {
39 public:
blundellfecea528d2015-10-21 10:10:2240 // Creates the MetricsServicesManager with the given client.
41 explicit MetricsServicesManager(
dcheng84c358e2016-04-26 07:05:5342 std::unique_ptr<MetricsServicesManagerClient> client);
[email protected]c3cac952014-05-09 01:51:1843 virtual ~MetricsServicesManager();
44
robliao4bee5d92016-09-15 14:37:3745 // 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]4a55a712014-06-08 16:50:3455 // Returns the MetricsService, creating it if it hasn't been created yet (and
blundellfecea528d2015-10-21 10:10:2256 // additionally creating the MetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4057 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1858
holte7b74c622017-01-23 23:13:0759 // Returns the UkmService, creating it if it hasn't been created yet.
60 ukm::UkmService* GetUkmService();
61
[email protected]c3cac952014-05-09 01:51:1862 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4563 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1864
[email protected]544246e2014-06-06 11:22:2865 // Should be called when a plugin loading error occurs.
66 void OnPluginLoadingError(const base::FilePath& plugin_path);
67
blundell6eb91b7b2015-10-23 07:04:4368 // Some embedders use this method to notify the metrics system when a
69 // renderer process exits unexpectedly.
70 void OnRendererProcessCrash();
71
anthonyvd40dd0302015-02-19 16:11:3472 // Update the managed services when permissions for uploading metrics change.
73 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4674
Brian Whitec459cf52018-01-24 16:55:1475 // Gets the current state of metric reporting.
76 bool IsMetricsReportingEnabled() const;
77
Robert Liao5f1aeb92019-07-17 17:59:5178 // Gets the current state of metrics consent.
79 bool IsMetricsConsentGiven() const;
80
[email protected]c3cac952014-05-09 01:51:1881 private:
blundellfecea528d2015-10-21 10:10:2282 // Returns the MetricsServiceClient, creating it if it hasn't been
[email protected]4a55a712014-06-08 16:50:3483 // created yet (and additionally creating the MetricsService in that case).
blundellfecea528d2015-10-21 10:10:2284 metrics::MetricsServiceClient* GetMetricsServiceClient();
[email protected]4a55a712014-06-08 16:50:3485
holte585f4662015-06-18 19:13:5286 // Update which services are running to match current permissions.
87 void UpdateRunningServices();
88
holte1334c0aa2017-02-09 22:52:4189 // Update the state of UkmService to match current permissions.
90 void UpdateUkmService();
91
Robert Kaplowc9986922017-09-29 02:05:4992 // 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
blundellfecea528d2015-10-21 10:10:2298 // The client passed in from the embedder.
François Degrose1dc3bb2017-11-29 00:10:3899 const std::unique_ptr<MetricsServicesManagerClient> client_;
blundellfecea528d2015-10-21 10:10:22100
[email protected]c3cac952014-05-09 01:51:18101 // Ensures that all functions are called from the same thread.
102 base::ThreadChecker thread_checker_;
103
holte873fb7c92015-02-19 23:41:26104 // The current metrics reporting setting.
105 bool may_upload_;
106
107 // The current metrics recording setting.
108 bool may_record_;
109
Robert Kaplowc9986922017-09-29 02:05:49110 // The current metrics setting reflecting if consent was given.
111 bool consent_given_;
112
blundellfecea528d2015-10-21 10:10:22113 // The MetricsServiceClient. Owns the MetricsService.
dcheng84c358e2016-04-26 07:05:53114 std::unique_ptr<metrics::MetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:18115
[email protected]c3cac952014-05-09 01:51:18116 // The VariationsService, for server-side experiments infrastructure.
dcheng84c358e2016-04-26 07:05:53117 std::unique_ptr<variations::VariationsService> variations_service_;
[email protected]c3cac952014-05-09 01:51:18118
119 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
120};
121
blundell695d61f2015-10-21 11:25:53122} // namespace metrics_services_manager
123
124#endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_