blob: d559ffbd92e4629be2c993256d4c467b2f7db223 [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"
[email protected]c3cac952014-05-09 01:51:1811#include "base/threading/thread_checker.h"
12
[email protected]544246e2014-06-06 11:22:2813namespace base {
14class FilePath;
15}
16
[email protected]c3cac952014-05-09 01:51:1817namespace metrics {
asvitkinecbd420732014-08-26 22:15:4018class MetricsService;
blundellfecea528d2015-10-21 10:10:2219class MetricsServiceClient;
[email protected]c3cac952014-05-09 01:51:1820class MetricsStateManager;
21}
22
23namespace rappor {
24class RapporService;
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
37// client), RapporService 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
[email protected]4a55a712014-06-08 16:50:3445 // Returns the MetricsService, creating it if it hasn't been created yet (and
blundellfecea528d2015-10-21 10:10:2246 // additionally creating the MetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4047 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1848
blundellfecea528d2015-10-21 10:10:2249 // Returns the RapporService, creating it if it hasn't been created yet.
[email protected]c3cac952014-05-09 01:51:1850 rappor::RapporService* GetRapporService();
51
52 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4553 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1854
[email protected]544246e2014-06-06 11:22:2855 // Should be called when a plugin loading error occurs.
56 void OnPluginLoadingError(const base::FilePath& plugin_path);
57
blundell6eb91b7b2015-10-23 07:04:4358 // Some embedders use this method to notify the metrics system when a
59 // renderer process exits unexpectedly.
60 void OnRendererProcessCrash();
61
holte5a7ed7c2015-01-09 23:52:4662 // Update the managed services when permissions for recording/uploading
63 // metrics change.
64 void UpdatePermissions(bool may_record, bool may_upload);
65
anthonyvd40dd0302015-02-19 16:11:3466 // Update the managed services when permissions for uploading metrics change.
67 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4668
[email protected]c3cac952014-05-09 01:51:1869 private:
holte873fb7c92015-02-19 23:41:2670 // Update the managed services when permissions for recording/uploading
71 // metrics change.
72 void UpdateRapporService();
73
blundellfecea528d2015-10-21 10:10:2274 // Returns the MetricsServiceClient, creating it if it hasn't been
[email protected]4a55a712014-06-08 16:50:3475 // created yet (and additionally creating the MetricsService in that case).
blundellfecea528d2015-10-21 10:10:2276 metrics::MetricsServiceClient* GetMetricsServiceClient();
[email protected]4a55a712014-06-08 16:50:3477
[email protected]c3cac952014-05-09 01:51:1878 metrics::MetricsStateManager* GetMetricsStateManager();
79
holte585f4662015-06-18 19:13:5280 // Update which services are running to match current permissions.
81 void UpdateRunningServices();
82
blundellfecea528d2015-10-21 10:10:2283 // The client passed in from the embedder.
dcheng84c358e2016-04-26 07:05:5384 std::unique_ptr<MetricsServicesManagerClient> client_;
blundellfecea528d2015-10-21 10:10:2285
[email protected]c3cac952014-05-09 01:51:1886 // Ensures that all functions are called from the same thread.
87 base::ThreadChecker thread_checker_;
88
holte873fb7c92015-02-19 23:41:2689 // The current metrics reporting setting.
90 bool may_upload_;
91
92 // The current metrics recording setting.
93 bool may_record_;
94
blundellfecea528d2015-10-21 10:10:2295 // The MetricsServiceClient. Owns the MetricsService.
dcheng84c358e2016-04-26 07:05:5396 std::unique_ptr<metrics::MetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:1897
98 // The RapporService, for RAPPOR metric uploads.
dcheng84c358e2016-04-26 07:05:5399 std::unique_ptr<rappor::RapporService> rappor_service_;
[email protected]c3cac952014-05-09 01:51:18100
101 // The VariationsService, for server-side experiments infrastructure.
dcheng84c358e2016-04-26 07:05:53102 std::unique_ptr<variations::VariationsService> variations_service_;
[email protected]c3cac952014-05-09 01:51:18103
104 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
105};
106
blundell695d61f2015-10-21 11:25:53107} // namespace metrics_services_manager
108
109#endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_