blob: e3e5b4dce2df66767de3d8863535a4f7f4e73bd7 [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
5#ifndef CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_
6#define CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_
7
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/threading/thread_checker.h"
holte585f4662015-06-18 19:13:5211#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]c3cac952014-05-09 01:51:1812
[email protected]037642f2014-05-29 20:40:5013class ChromeMetricsServiceClient;
[email protected]c3cac952014-05-09 01:51:1814class PrefService;
15
[email protected]544246e2014-06-06 11:22:2816namespace base {
17class FilePath;
18}
19
[email protected]c3cac952014-05-09 01:51:1820namespace metrics {
asvitkinecbd420732014-08-26 22:15:4021class MetricsService;
[email protected]c3cac952014-05-09 01:51:1822class MetricsStateManager;
23}
24
25namespace rappor {
26class RapporService;
27}
28
blundell57bcfed2015-09-04 08:44:4529namespace variations {
[email protected]c3cac952014-05-09 01:51:1830class VariationsService;
31}
32
33// MetricsServicesManager is a helper class that has ownership over the various
[email protected]037642f2014-05-29 20:40:5034// metrics-related services in Chrome: MetricsService (via its client),
35// RapporService and VariationsService.
[email protected]c3cac952014-05-09 01:51:1836class MetricsServicesManager {
37 public:
38 // Creates the MetricsServicesManager with the |local_state| prefs service.
39 explicit MetricsServicesManager(PrefService* local_state);
40 virtual ~MetricsServicesManager();
41
[email protected]4a55a712014-06-08 16:50:3442 // Returns the MetricsService, creating it if it hasn't been created yet (and
43 // additionally creating the ChromeMetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4044 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1845
46 // Returns the GetRapporService, creating it if it hasn't been created yet.
47 rappor::RapporService* GetRapporService();
48
49 // Returns the VariationsService, creating it if it hasn't been created yet.
blundell57bcfed2015-09-04 08:44:4550 variations::VariationsService* GetVariationsService();
[email protected]c3cac952014-05-09 01:51:1851
[email protected]544246e2014-06-06 11:22:2852 // Should be called when a plugin loading error occurs.
53 void OnPluginLoadingError(const base::FilePath& plugin_path);
54
holte5a7ed7c2015-01-09 23:52:4655 // Update the managed services when permissions for recording/uploading
56 // metrics change.
57 void UpdatePermissions(bool may_record, bool may_upload);
58
anthonyvd40dd0302015-02-19 16:11:3459 // Update the managed services when permissions for uploading metrics change.
60 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4661
[email protected]c3cac952014-05-09 01:51:1862 private:
holte873fb7c92015-02-19 23:41:2663 // Update the managed services when permissions for recording/uploading
64 // metrics change.
65 void UpdateRapporService();
66
[email protected]4a55a712014-06-08 16:50:3467 // Returns the ChromeMetricsServiceClient, creating it if it hasn't been
68 // created yet (and additionally creating the MetricsService in that case).
69 ChromeMetricsServiceClient* GetChromeMetricsServiceClient();
70
[email protected]c3cac952014-05-09 01:51:1871 metrics::MetricsStateManager* GetMetricsStateManager();
72
holte585f4662015-06-18 19:13:5273 // Retrieve the latest SafeBrowsing preferences state.
74 bool GetSafeBrowsingState();
75
76 // Update which services are running to match current permissions.
77 void UpdateRunningServices();
78
[email protected]c3cac952014-05-09 01:51:1879 // Ensures that all functions are called from the same thread.
80 base::ThreadChecker thread_checker_;
81
82 // Weak pointer to the local state prefs store.
83 PrefService* local_state_;
84
holte585f4662015-06-18 19:13:5285 // Subscription to SafeBrowsing service state changes.
86 scoped_ptr<SafeBrowsingService::StateSubscription> sb_state_subscription_;
holte873fb7c92015-02-19 23:41:2687
88 // The current metrics reporting setting.
89 bool may_upload_;
90
91 // The current metrics recording setting.
92 bool may_record_;
93
[email protected]c3cac952014-05-09 01:51:1894 // MetricsStateManager which is passed as a parameter to service constructors.
95 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_;
96
[email protected]037642f2014-05-29 20:40:5097 // Chrome embedder implementation of the MetricsServiceClient. Owns the
98 // MetricsService.
99 scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:18100
101 // The RapporService, for RAPPOR metric uploads.
102 scoped_ptr<rappor::RapporService> rappor_service_;
103
104 // The VariationsService, for server-side experiments infrastructure.
blundell57bcfed2015-09-04 08:44:45105 scoped_ptr<variations::VariationsService> variations_service_;
[email protected]c3cac952014-05-09 01:51:18106
107 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
108};
109
110#endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_