blob: 72ec3f797ff4d0a6f11961349a13bcf7f42806d5 [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"
holte873fb7c92015-02-19 23:41:2610#include "base/prefs/pref_change_registrar.h"
[email protected]c3cac952014-05-09 01:51:1811#include "base/threading/thread_checker.h"
holtece6a45c2015-02-14 01:41:4512#include "components/rappor/rappor_service.h"
[email protected]c3cac952014-05-09 01:51:1813
[email protected]037642f2014-05-29 20:40:5014class ChromeMetricsServiceClient;
[email protected]c3cac952014-05-09 01:51:1815class PrefService;
16
[email protected]544246e2014-06-06 11:22:2817namespace base {
18class FilePath;
19}
20
[email protected]c3cac952014-05-09 01:51:1821namespace metrics {
asvitkinecbd420732014-08-26 22:15:4022class MetricsService;
[email protected]c3cac952014-05-09 01:51:1823class MetricsStateManager;
24}
25
26namespace rappor {
27class RapporService;
28}
29
30namespace chrome_variations {
31class VariationsService;
32}
33
34// MetricsServicesManager is a helper class that has ownership over the various
[email protected]037642f2014-05-29 20:40:5035// metrics-related services in Chrome: MetricsService (via its client),
36// RapporService and VariationsService.
[email protected]c3cac952014-05-09 01:51:1837class MetricsServicesManager {
38 public:
39 // Creates the MetricsServicesManager with the |local_state| prefs service.
40 explicit MetricsServicesManager(PrefService* local_state);
41 virtual ~MetricsServicesManager();
42
[email protected]4a55a712014-06-08 16:50:3443 // Returns the MetricsService, creating it if it hasn't been created yet (and
44 // additionally creating the ChromeMetricsServiceClient in that case).
asvitkinecbd420732014-08-26 22:15:4045 metrics::MetricsService* GetMetricsService();
[email protected]c3cac952014-05-09 01:51:1846
47 // Returns the GetRapporService, creating it if it hasn't been created yet.
48 rappor::RapporService* GetRapporService();
49
50 // Returns the VariationsService, creating it if it hasn't been created yet.
51 chrome_variations::VariationsService* GetVariationsService();
52
[email protected]544246e2014-06-06 11:22:2853 // Should be called when a plugin loading error occurs.
54 void OnPluginLoadingError(const base::FilePath& plugin_path);
55
holte5a7ed7c2015-01-09 23:52:4656 // Update the managed services when permissions for recording/uploading
57 // metrics change.
58 void UpdatePermissions(bool may_record, bool may_upload);
59
anthonyvd40dd0302015-02-19 16:11:3460 // Update the managed services when permissions for uploading metrics change.
61 void UpdateUploadPermissions(bool may_upload);
holte5a7ed7c2015-01-09 23:52:4662
holtece6a45c2015-02-14 01:41:4563 // Returns true iff Rappor reporting is enabled.
64 bool IsRapporEnabled(bool metrics_enabled) const;
65
66 // Returns the recording level for Rappor metrics.
67 rappor::RecordingLevel GetRapporRecordingLevel(bool metrics_enabled) const;
68
[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
[email protected]4a55a712014-06-08 16:50:3474 // Returns the ChromeMetricsServiceClient, creating it if it hasn't been
75 // created yet (and additionally creating the MetricsService in that case).
76 ChromeMetricsServiceClient* GetChromeMetricsServiceClient();
77
[email protected]c3cac952014-05-09 01:51:1878 metrics::MetricsStateManager* GetMetricsStateManager();
79
[email protected]c3cac952014-05-09 01:51:1880 // Ensures that all functions are called from the same thread.
81 base::ThreadChecker thread_checker_;
82
83 // Weak pointer to the local state prefs store.
84 PrefService* local_state_;
85
holte873fb7c92015-02-19 23:41:2686 // A change registrar for local_state_;
87 PrefChangeRegistrar pref_change_registrar_;
88
89 // The current metrics reporting setting.
90 bool may_upload_;
91
92 // The current metrics recording setting.
93 bool may_record_;
94
[email protected]c3cac952014-05-09 01:51:1895 // MetricsStateManager which is passed as a parameter to service constructors.
96 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_;
97
[email protected]037642f2014-05-29 20:40:5098 // Chrome embedder implementation of the MetricsServiceClient. Owns the
99 // MetricsService.
100 scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_;
[email protected]c3cac952014-05-09 01:51:18101
102 // The RapporService, for RAPPOR metric uploads.
103 scoped_ptr<rappor::RapporService> rappor_service_;
104
105 // The VariationsService, for server-side experiments infrastructure.
106 scoped_ptr<chrome_variations::VariationsService> variations_service_;
107
108 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
109};
110
111#endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_