[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 1 | // 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 | |
asvitkine | 4c1d1ef | 2014-09-29 20:57:32 | [diff] [blame] | 8 | #include <stdint.h> |
dcheng | d99c42a | 2016-04-21 21:54:13 | [diff] [blame] | 9 | |
| 10 | #include <memory> |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 11 | #include <string> |
| 12 | |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 13 | #include "base/callback.h" |
erikwright | 65b58df | 2014-09-12 00:05:28 | [diff] [blame] | 14 | #include "base/strings/string16.h" |
gunsch | 7cbdcb2 | 2015-03-13 17:02:05 | [diff] [blame] | 15 | #include "base/time/time.h" |
rkaplow | 9c42082 | 2017-02-24 15:29:57 | [diff] [blame] | 16 | #include "components/metrics/metrics_log_uploader.h" |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 17 | #include "components/metrics/metrics_reporting_default_state.h" |
Steven Holte | f9d5ed6 | 2017-10-21 02:02:30 | [diff] [blame] | 18 | #include "third_party/metrics_proto/system_profile.pb.h" |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 19 | |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 20 | namespace base { |
| 21 | class FilePath; |
| 22 | } |
| 23 | |
holte | 7b74c62 | 2017-01-23 23:13:07 | [diff] [blame] | 24 | namespace ukm { |
| 25 | class UkmService; |
| 26 | } |
| 27 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 28 | namespace metrics { |
| 29 | |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 30 | class MetricsLogUploader; |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 31 | class MetricsService; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 32 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 33 | // An abstraction of operations that depend on the embedder's (e.g. Chrome) |
| 34 | // environment. |
| 35 | class MetricsServiceClient { |
| 36 | public: |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 37 | MetricsServiceClient(); |
| 38 | virtual ~MetricsServiceClient(); |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 39 | |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 40 | // 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 | |
holte | 7b74c62 | 2017-01-23 23:13:07 | [diff] [blame] | 46 | // Returns the UkmService instance that this client is associated with. |
| 47 | virtual ukm::UkmService* GetUkmService(); |
| 48 | |
[email protected] | 9d1b015 | 2014-07-09 18:53:22 | [diff] [blame] | 49 | // Registers the client id with other services (e.g. crash reporting), called |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 50 | // when metrics recording gets enabled. |
[email protected] | 9d1b015 | 2014-07-09 18:53:22 | [diff] [blame] | 51 | virtual void SetMetricsClientId(const std::string& client_id) = 0; |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 52 | |
asvitkine | 4c1d1ef | 2014-09-29 20:57:32 | [diff] [blame] | 53 | // Returns the product value to use in uploaded reports, which will be used to |
| 54 | // set the ChromeUserMetricsExtension.product field. See comments on that |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 55 | // field on why it's an int32_t rather than an enum. |
asvitkine | 4c1d1ef | 2014-09-29 20:57:32 | [diff] [blame] | 56 | virtual int32_t GetProduct() = 0; |
| 57 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 58 | // 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] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 70 | |
manzagop | a5d6688d | 2016-10-25 20:16:03 | [diff] [blame] | 71 | // 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 | |
manzagop | 14aff5d | 2016-11-23 17:27:00 | [diff] [blame] | 77 | // Called by the metrics service to record a clean shutdown. |
| 78 | virtual void OnLogCleanShutdown() {} |
| 79 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 80 | // 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. |
isherman | b670568 | 2015-08-29 00:01:00 | [diff] [blame] | 83 | virtual void CollectFinalMetricsForLog( |
| 84 | const base::Closure& done_callback) = 0; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 85 | |
holte | 567a16f2 | 2017-01-06 01:53:45 | [diff] [blame] | 86 | // Get the URL of the metrics server. |
| 87 | virtual std::string GetMetricsServerUrl(); |
| 88 | |
Carlos IL | 75b352f | 2017-11-07 01:43:02 | [diff] [blame] | 89 | // Get the fallback HTTP URL of the metrics server. |
| 90 | virtual std::string GetInsecureMetricsServerUrl(); |
| 91 | |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 92 | // Creates a MetricsLogUploader with the specified parameters (see comments on |
| 93 | // MetricsLogUploader for details). |
dcheng | d99c42a | 2016-04-21 21:54:13 | [diff] [blame] | 94 | virtual std::unique_ptr<MetricsLogUploader> CreateUploader( |
holte | 4ae63f5 | 2017-03-08 00:25:08 | [diff] [blame] | 95 | base::StringPiece server_url, |
Carlos IL | 75b352f | 2017-11-07 01:43:02 | [diff] [blame] | 96 | base::StringPiece insecure_server_url, |
holte | 4ae63f5 | 2017-03-08 00:25:08 | [diff] [blame] | 97 | base::StringPiece mime_type, |
rkaplow | 9c42082 | 2017-02-24 15:29:57 | [diff] [blame] | 98 | metrics::MetricsLogUploader::MetricServiceType service_type, |
holte | 035ec7fb | 2017-04-04 20:16:59 | [diff] [blame] | 99 | const MetricsLogUploader::UploadCallback& on_upload_complete) = 0; |
erikwright | 65b58df | 2014-09-12 00:05:28 | [diff] [blame] | 100 | |
gunsch | 7cbdcb2 | 2015-03-13 17:02:05 | [diff] [blame] | 101 | // Returns the standard interval between upload attempts. |
| 102 | virtual base::TimeDelta GetStandardUploadInterval() = 0; |
| 103 | |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 104 | // Called on plugin loading errors. |
| 105 | virtual void OnPluginLoadingError(const base::FilePath& plugin_path) {} |
blundell | 6eb91b7b | 2015-10-23 07:04:43 | [diff] [blame] | 106 | |
| 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() {} |
jwd | 421086f | 2016-03-21 14:40:42 | [diff] [blame] | 111 | |
| 112 | // Returns whether metrics reporting is managed by policy. |
| 113 | virtual bool IsReportingPolicyManaged(); |
| 114 | |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 115 | // Gets information about the default value for the metrics reporting checkbox |
| 116 | // shown during first-run. |
| 117 | virtual EnableMetricsDefault GetMetricsReportingDefaultState(); |
gayane | 0b46091c | 2016-04-07 21:01:05 | [diff] [blame] | 118 | |
| 119 | // Returns whether cellular logic is enabled for metrics reporting. |
| 120 | virtual bool IsUMACellularUploadLogicEnabled(); |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 121 | |
Steven Holte | 0221a1b | 2018-04-23 21:53:47 | [diff] [blame] | 122 | // 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(); |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 125 | |
Steven Holte | 0221a1b | 2018-04-23 21:53:47 | [diff] [blame] | 126 | // 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 White | b1f14345 | 2018-03-01 12:44:15 | [diff] [blame] | 129 | |
Travis Skare | 0cfa87d4 | 2018-04-13 00:06:26 | [diff] [blame] | 130 | // Returns whether UKM notification listeners were attached to all profiles. |
| 131 | virtual bool AreNotificationListenersEnabledOnAllProfiles(); |
| 132 | |
Tao Bai | 3fb32d1 | 2018-11-02 23:10:55 | [diff] [blame] | 133 | // 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 Weng | 3720265 | 2018-04-19 02:54:11 | [diff] [blame] | 135 | virtual std::string GetAppPackageName(); |
| 136 | |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 137 | // Sets the callback to run MetricsServiceManager::UpdateRunningServices. |
| 138 | void SetUpdateRunningServicesCallback(const base::Closure& callback); |
| 139 | |
holte | 1334c0aa | 2017-02-09 22:52:41 | [diff] [blame] | 140 | // 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] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | } // namespace metrics |
| 150 | |
| 151 | #endif // COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_ |