blob: e70d6489066c40e1278f51c593097ec4d3d2b647 [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 {
25class RapporService;
26}
27
blundell57bcfed2015-09-04 08:44:4528namespace variations {
[email protected]c3cac952014-05-09 01:51:1829class VariationsService;
30}
31
blundell695d61f2015-10-21 11:25:5332namespace metrics_services_manager {
33
34class MetricsServicesManagerClient;
35
blundellfecea528d2015-10-21 10:10:2236// 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]c3cac952014-05-09 01:51:1839class MetricsServicesManager {
40 public:
blundellfecea528d2015-10-21 10:10:2241 // Creates the MetricsServicesManager with the given client.
42 explicit MetricsServicesManager(
dcheng84c358e2016-04-26 07:05:5343 std::unique_ptr<MetricsServicesManagerClient> client);
[email protected]c3cac952014-05-09 01:51:1844 virtual ~MetricsServicesManager();
45
robliao4bee5d92016-09-15 14:37:3746 // 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]4a55a712014-06-08 16:50:3456 // Returns the MetricsService, creating it if it hasn't been created yet (and
blundellfecea528d2015-10-21 10:10:2257 // additionally creating the MetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4058 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1859
blundellfecea528d2015-10-21 10:10:2260 // Returns the RapporService, creating it if it hasn't been created yet.
[email protected]c3cac952014-05-09 01:51:1861 rappor::RapporService* GetRapporService();
62
63 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4564 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1865
[email protected]544246e2014-06-06 11:22:2866 // Should be called when a plugin loading error occurs.
67 void OnPluginLoadingError(const base::FilePath& plugin_path);
68
blundell6eb91b7b2015-10-23 07:04:4369 // Some embedders use this method to notify the metrics system when a
70 // renderer process exits unexpectedly.
71 void OnRendererProcessCrash();
72
holte5a7ed7c2015-01-09 23:52:4673 // Update the managed services when permissions for recording/uploading
74 // metrics change.
75 void UpdatePermissions(bool may_record, bool may_upload);
76
anthonyvd40dd0302015-02-19 16:11:3477 // Update the managed services when permissions for uploading metrics change.
78 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4679
[email protected]c3cac952014-05-09 01:51:1880 private:
holte873fb7c92015-02-19 23:41:2681 // Update the managed services when permissions for recording/uploading
82 // metrics change.
83 void UpdateRapporService();
84
blundellfecea528d2015-10-21 10:10:2285 // Returns the MetricsServiceClient, creating it if it hasn't been
[email protected]4a55a712014-06-08 16:50:3486 // created yet (and additionally creating the MetricsService in that case).
blundellfecea528d2015-10-21 10:10:2287 metrics::MetricsServiceClient* GetMetricsServiceClient();
[email protected]4a55a712014-06-08 16:50:3488
[email protected]c3cac952014-05-09 01:51:1889 metrics::MetricsStateManager* GetMetricsStateManager();
90
holte585f4662015-06-18 19:13:5291 // Update which services are running to match current permissions.
92 void UpdateRunningServices();
93
blundellfecea528d2015-10-21 10:10:2294 // The client passed in from the embedder.
dcheng84c358e2016-04-26 07:05:5395 std::unique_ptr<MetricsServicesManagerClient> client_;
blundellfecea528d2015-10-21 10:10:2296
[email protected]c3cac952014-05-09 01:51:1897 // Ensures that all functions are called from the same thread.
98 base::ThreadChecker thread_checker_;
99
holte873fb7c92015-02-19 23:41:26100 // The current metrics reporting setting.
101 bool may_upload_;
102
103 // The current metrics recording setting.
104 bool may_record_;
105
blundellfecea528d2015-10-21 10:10:22106 // The MetricsServiceClient. Owns the MetricsService.
dcheng84c358e2016-04-26 07:05:53107 std::unique_ptr<metrics::MetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:18108
109 // The RapporService, for RAPPOR metric uploads.
dcheng84c358e2016-04-26 07:05:53110 std::unique_ptr<rappor::RapporService> rappor_service_;
[email protected]c3cac952014-05-09 01:51:18111
112 // The VariationsService, for server-side experiments infrastructure.
dcheng84c358e2016-04-26 07:05:53113 std::unique_ptr<variations::VariationsService> variations_service_;
[email protected]c3cac952014-05-09 01:51:18114
115 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
116};
117
blundell695d61f2015-10-21 11:25:53118} // namespace metrics_services_manager
119
120#endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_