blob: 4fc66e45ee8793c5284eb68d18ba900ada6e1450 [file] [log] [blame]
[email protected]5bdaa2d2014-05-19 14:59:511// 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 COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
6#define COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
7
asvitkine4c1d1ef2014-09-29 20:57:328#include <stdint.h>
dchengd99c42a2016-04-21 21:54:139
10#include <memory>
[email protected]5bdaa2d2014-05-19 14:59:5111#include <string>
12
holte1334c0aa2017-02-09 22:52:4113#include "base/callback.h"
erikwright65b58df2014-09-12 00:05:2814#include "base/strings/string16.h"
gunsch7cbdcb22015-03-13 17:02:0515#include "base/time/time.h"
rkaplow9c420822017-02-24 15:29:5716#include "components/metrics/metrics_log_uploader.h"
gayanedaaf3a02016-06-15 16:30:2117#include "components/metrics/metrics_reporting_default_state.h"
Steven Holtef9d5ed62017-10-21 02:02:3018#include "third_party/metrics_proto/system_profile.pb.h"
[email protected]5bdaa2d2014-05-19 14:59:5119
blundellfecea528d2015-10-21 10:10:2220namespace base {
21class FilePath;
22}
23
holte7b74c622017-01-23 23:13:0724namespace ukm {
25class UkmService;
26}
27
[email protected]5bdaa2d2014-05-19 14:59:5128namespace metrics {
29
[email protected]0d5a61a82014-05-31 22:28:3430class MetricsLogUploader;
blundellfecea528d2015-10-21 10:10:2231class MetricsService;
[email protected]0d5a61a82014-05-31 22:28:3432
[email protected]5bdaa2d2014-05-19 14:59:5133// An abstraction of operations that depend on the embedder's (e.g. Chrome)
34// environment.
35class MetricsServiceClient {
36 public:
holte1334c0aa2017-02-09 22:52:4137 MetricsServiceClient();
38 virtual ~MetricsServiceClient();
[email protected]5bdaa2d2014-05-19 14:59:5139
blundellfecea528d2015-10-21 10:10:2240 // Returns the MetricsService instance that this client is associated with.
41 // With the exception of testing contexts, the returned instance must be valid
42 // for the lifetime of this object (typically, the embedder's client
43 // implementation will own the MetricsService instance being returned).
44 virtual MetricsService* GetMetricsService() = 0;
45
holte7b74c622017-01-23 23:13:0746 // Returns the UkmService instance that this client is associated with.
47 virtual ukm::UkmService* GetUkmService();
48
[email protected]9d1b0152014-07-09 18:53:2249 // Registers the client id with other services (e.g. crash reporting), called
[email protected]5bdaa2d2014-05-19 14:59:5150 // when metrics recording gets enabled.
[email protected]9d1b0152014-07-09 18:53:2251 virtual void SetMetricsClientId(const std::string& client_id) = 0;
[email protected]5bdaa2d2014-05-19 14:59:5152
asvitkine4c1d1ef2014-09-29 20:57:3253 // Returns the product value to use in uploaded reports, which will be used to
54 // set the ChromeUserMetricsExtension.product field. See comments on that
avi26062922015-12-26 00:14:1855 // field on why it's an int32_t rather than an enum.
asvitkine4c1d1ef2014-09-29 20:57:3256 virtual int32_t GetProduct() = 0;
57
[email protected]5bdaa2d2014-05-19 14:59:5158 // Returns the current application locale (e.g. "en-US").
59 virtual std::string GetApplicationLocale() = 0;
60
61 // Retrieves the brand code string associated with the install, returning
62 // false if no brand code is available.
63 virtual bool GetBrand(std::string* brand_code) = 0;
64
65 // Returns the release channel (e.g. stable, beta, etc) of the application.
66 virtual SystemProfileProto::Channel GetChannel() = 0;
67
68 // Returns the version of the application as a string.
69 virtual std::string GetVersionString() = 0;
[email protected]73929422014-05-22 08:19:0570
manzagopa5d6688d2016-10-25 20:16:0371 // Called by the metrics service when a new environment has been recorded.
72 // Takes the serialized environment as a parameter. The contents of
73 // |serialized_environment| are consumed by the call, but the caller maintains
74 // ownership.
75 virtual void OnEnvironmentUpdate(std::string* serialized_environment) {}
76
manzagop14aff5d2016-11-23 17:27:0077 // Called by the metrics service to record a clean shutdown.
78 virtual void OnLogCleanShutdown() {}
79
[email protected]4b4892b2014-05-22 15:06:1580 // Called prior to a metrics log being closed, allowing the client to collect
81 // extra histograms that will go in that log. Asynchronous API - the client
82 // implementation should call |done_callback| when complete.
ishermanb6705682015-08-29 00:01:0083 virtual void CollectFinalMetricsForLog(
84 const base::Closure& done_callback) = 0;
[email protected]0d5a61a82014-05-31 22:28:3485
holte567a16f22017-01-06 01:53:4586 // Get the URL of the metrics server.
87 virtual std::string GetMetricsServerUrl();
88
Carlos IL75b352f2017-11-07 01:43:0289 // Get the fallback HTTP URL of the metrics server.
90 virtual std::string GetInsecureMetricsServerUrl();
91
[email protected]0d5a61a82014-05-31 22:28:3492 // Creates a MetricsLogUploader with the specified parameters (see comments on
93 // MetricsLogUploader for details).
dchengd99c42a2016-04-21 21:54:1394 virtual std::unique_ptr<MetricsLogUploader> CreateUploader(
holte4ae63f52017-03-08 00:25:0895 base::StringPiece server_url,
Carlos IL75b352f2017-11-07 01:43:0296 base::StringPiece insecure_server_url,
holte4ae63f52017-03-08 00:25:0897 base::StringPiece mime_type,
rkaplow9c420822017-02-24 15:29:5798 metrics::MetricsLogUploader::MetricServiceType service_type,
holte035ec7fb2017-04-04 20:16:5999 const MetricsLogUploader::UploadCallback& on_upload_complete) = 0;
erikwright65b58df2014-09-12 00:05:28100
gunsch7cbdcb22015-03-13 17:02:05101 // Returns the standard interval between upload attempts.
102 virtual base::TimeDelta GetStandardUploadInterval() = 0;
103
blundellfecea528d2015-10-21 10:10:22104 // Called on plugin loading errors.
105 virtual void OnPluginLoadingError(const base::FilePath& plugin_path) {}
blundell6eb91b7b2015-10-23 07:04:43106
107 // Called on renderer crashes in some embedders (e.g., those that do not use
108 // //content and thus do not have //content's notification system available
109 // as a mechanism for observing renderer crashes).
110 virtual void OnRendererProcessCrash() {}
jwd421086f2016-03-21 14:40:42111
112 // Returns whether metrics reporting is managed by policy.
113 virtual bool IsReportingPolicyManaged();
114
gayanedaaf3a02016-06-15 16:30:21115 // Gets information about the default value for the metrics reporting checkbox
116 // shown during first-run.
117 virtual EnableMetricsDefault GetMetricsReportingDefaultState();
gayane0b46091c2016-04-07 21:01:05118
119 // Returns whether cellular logic is enabled for metrics reporting.
120 virtual bool IsUMACellularUploadLogicEnabled();
holte1334c0aa2017-02-09 22:52:41121
Steven Holte0221a1b2018-04-23 21:53:47122 // Returns true iff sync is in a state that allows UKM to be enabled.
123 // See //components/ukm/observers/sync_disable_observer.h for details.
124 virtual bool SyncStateAllowsUkm();
holte1334c0aa2017-02-09 22:52:41125
Steven Holte0221a1b2018-04-23 21:53:47126 // Returns true iff sync is in a state that allows UKM to capture extensions.
127 // See //components/ukm/observers/sync_disable_observer.h for details.
128 virtual bool SyncStateAllowsExtensionUkm();
Brian Whiteb1f143452018-03-01 12:44:15129
Travis Skare0cfa87d42018-04-13 00:06:26130 // Returns whether UKM notification listeners were attached to all profiles.
131 virtual bool AreNotificationListenersEnabledOnAllProfiles();
132
Tao Bai3fb32d12018-11-02 23:10:55133 // Gets Chrome's package name in Android Chrome, or the host app's package
134 // name in Android WebView, or an empty string on other platforms.
Shuo Weng37202652018-04-19 02:54:11135 virtual std::string GetAppPackageName();
136
holte1334c0aa2017-02-09 22:52:41137 // Sets the callback to run MetricsServiceManager::UpdateRunningServices.
138 void SetUpdateRunningServicesCallback(const base::Closure& callback);
139
holte1334c0aa2017-02-09 22:52:41140 // Notify MetricsServiceManager to UpdateRunningServices using callback.
141 void UpdateRunningServices();
142
143 private:
144 base::Closure update_running_services_;
145
146 DISALLOW_COPY_AND_ASSIGN(MetricsServiceClient);
[email protected]5bdaa2d2014-05-19 14:59:51147};
148
149} // namespace metrics
150
151#endif // COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_