blob: 4aff260e874f2aaa1ce907b73f509468014cb7f7 [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
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/threading/thread_checker.h"
[email protected]c3cac952014-05-09 01:51:1811
[email protected]544246e2014-06-06 11:22:2812namespace base {
13class FilePath;
14}
15
[email protected]c3cac952014-05-09 01:51:1816namespace metrics {
asvitkinecbd420732014-08-26 22:15:4017class MetricsService;
blundellfecea528d2015-10-21 10:10:2218class MetricsServiceClient;
[email protected]c3cac952014-05-09 01:51:1819class MetricsStateManager;
20}
21
22namespace rappor {
23class RapporService;
24}
25
blundell57bcfed2015-09-04 08:44:4526namespace variations {
[email protected]c3cac952014-05-09 01:51:1827class VariationsService;
28}
29
blundell695d61f2015-10-21 11:25:5330namespace metrics_services_manager {
31
32class MetricsServicesManagerClient;
33
blundellfecea528d2015-10-21 10:10:2234// MetricsServicesManager is a helper class for embedders that use the various
35// metrics-related services in a Chrome-like fashion: MetricsService (via its
36// client), RapporService and VariationsService.
[email protected]c3cac952014-05-09 01:51:1837class MetricsServicesManager {
38 public:
blundellfecea528d2015-10-21 10:10:2239 // Creates the MetricsServicesManager with the given client.
40 explicit MetricsServicesManager(
41 scoped_ptr<MetricsServicesManagerClient> client);
[email protected]c3cac952014-05-09 01:51:1842 virtual ~MetricsServicesManager();
43
[email protected]4a55a712014-06-08 16:50:3444 // Returns the MetricsService, creating it if it hasn't been created yet (and
blundellfecea528d2015-10-21 10:10:2245 // additionally creating the MetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4046 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1847
blundellfecea528d2015-10-21 10:10:2248 // Returns the RapporService, creating it if it hasn't been created yet.
[email protected]c3cac952014-05-09 01:51:1849 rappor::RapporService* GetRapporService();
50
51 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4552 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1853
[email protected]544246e2014-06-06 11:22:2854 // Should be called when a plugin loading error occurs.
55 void OnPluginLoadingError(const base::FilePath& plugin_path);
56
blundell6eb91b7b2015-10-23 07:04:4357 // Some embedders use this method to notify the metrics system when a
58 // renderer process exits unexpectedly.
59 void OnRendererProcessCrash();
60
holte5a7ed7c2015-01-09 23:52:4661 // Update the managed services when permissions for recording/uploading
62 // metrics change.
63 void UpdatePermissions(bool may_record, bool may_upload);
64
anthonyvd40dd0302015-02-19 16:11:3465 // Update the managed services when permissions for uploading metrics change.
66 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4667
[email protected]c3cac952014-05-09 01:51:1868 private:
holte873fb7c92015-02-19 23:41:2669 // Update the managed services when permissions for recording/uploading
70 // metrics change.
71 void UpdateRapporService();
72
blundellfecea528d2015-10-21 10:10:2273 // Returns the MetricsServiceClient, creating it if it hasn't been
[email protected]4a55a712014-06-08 16:50:3474 // created yet (and additionally creating the MetricsService in that case).
blundellfecea528d2015-10-21 10:10:2275 metrics::MetricsServiceClient* GetMetricsServiceClient();
[email protected]4a55a712014-06-08 16:50:3476
[email protected]c3cac952014-05-09 01:51:1877 metrics::MetricsStateManager* GetMetricsStateManager();
78
holte585f4662015-06-18 19:13:5279 // Update which services are running to match current permissions.
80 void UpdateRunningServices();
81
blundellfecea528d2015-10-21 10:10:2282 // The client passed in from the embedder.
83 scoped_ptr<MetricsServicesManagerClient> client_;
84
[email protected]c3cac952014-05-09 01:51:1885 // Ensures that all functions are called from the same thread.
86 base::ThreadChecker thread_checker_;
87
holte873fb7c92015-02-19 23:41:2688 // The current metrics reporting setting.
89 bool may_upload_;
90
91 // The current metrics recording setting.
92 bool may_record_;
93
blundellfecea528d2015-10-21 10:10:2294 // The MetricsServiceClient. Owns the MetricsService.
95 scoped_ptr<metrics::MetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:1896
97 // The RapporService, for RAPPOR metric uploads.
98 scoped_ptr<rappor::RapporService> rappor_service_;
99
100 // The VariationsService, for server-side experiments infrastructure.
blundell57bcfed2015-09-04 08:44:45101 scoped_ptr<variations::VariationsService> variations_service_;
[email protected]c3cac952014-05-09 01:51:18102
103 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
104};
105
blundell695d61f2015-10-21 11:25:53106} // namespace metrics_services_manager
107
108#endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_