Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 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_LOG_UPLOADER_H_ |
| 6 | #define COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_ |
| 7 | |
| 8 | #include <string> |
Helmut Januschka | ff1c3ec | 2024-04-25 19:38:32 | [diff] [blame] | 9 | #include <string_view> |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 10 | |
Avi Drissman | 12be031 | 2023-01-11 09:16:09 | [diff] [blame] | 11 | #include "base/functional/callback.h" |
Nik | f305e36 | 2023-11-09 19:52:05 | [diff] [blame] | 12 | #include "components/metrics/metrics_log.h" |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 13 | |
| 14 | namespace metrics { |
| 15 | |
Steven Holte | 72428db | 2017-10-13 19:47:22 | [diff] [blame] | 16 | class ReportingInfo; |
| 17 | |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 18 | // MetricsLogUploader is an abstract base class for uploading UMA logs on behalf |
| 19 | // of MetricsService. |
| 20 | class MetricsLogUploader { |
| 21 | public: |
Caitlin Fischer | 0adeaa31 | 2023-07-20 13:15:28 | [diff] [blame] | 22 | // Type for OnUploadComplete callbacks. These callbacks receive five |
Luc Nguyen | 86136bb | 2023-04-25 20:31:51 | [diff] [blame] | 23 | // parameters: |
| 24 | // - a response code, |
| 25 | // - a net error code, |
| 26 | // - a boolean specifying if the connection was secure (over HTTPS), |
| 27 | // - a boolean specifying if the log should be discarded regardless of |
| 28 | // response/error code, |
| 29 | // - a string specifying the reason why the log was forcibly discarded (or |
| 30 | // empty string if not). |
| 31 | using UploadCallback = |
Helmut Januschka | ff1c3ec | 2024-04-25 19:38:32 | [diff] [blame] | 32 | base::RepeatingCallback<void(int, int, bool, bool, std::string_view)>; |
holte | 035ec7fb | 2017-04-04 20:16:59 | [diff] [blame] | 33 | |
Alexei Svitkine | 6843764 | 2024-10-24 20:27:11 | [diff] [blame] | 34 | // Possible service types. This is used during the upload process for |
| 35 | // determining which server to upload to and by metrics providers when adding |
| 36 | // data to logs. |
rkaplow | 9c42082 | 2017-02-24 15:29:57 | [diff] [blame] | 37 | enum MetricServiceType { |
| 38 | UMA, |
| 39 | UKM, |
Andrew Bregger | 8d5ba3e | 2023-05-22 19:49:33 | [diff] [blame] | 40 | STRUCTURED_METRICS, |
Jay Zhou | d216a51 | 2024-09-25 19:25:32 | [diff] [blame] | 41 | DWA, |
rkaplow | 9c42082 | 2017-02-24 15:29:57 | [diff] [blame] | 42 | }; |
| 43 | |
Luc Nguyen | 86136bb | 2023-04-25 20:31:51 | [diff] [blame] | 44 | virtual ~MetricsLogUploader() = default; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 45 | |
Jesse Doherty | 2eb4951 | 2019-01-18 17:53:27 | [diff] [blame] | 46 | // Uploads a log with the specified |compressed_log_data|, a |log_hash| and |
| 47 | // |log_signature| for data validation, and |reporting_info|. |log_hash| is |
Caitlin Fischer | 0adeaa31 | 2023-07-20 13:15:28 | [diff] [blame] | 48 | // expected to be the hex-encoded SHA1 hash of the log data before |
| 49 | // compression, and |log_signature| is expected to be a base64-encoded |
| 50 | // HMAC-SHA256 signature of the log data before compression. When the server |
| 51 | // receives an upload, it recomputes the hash and signature of the upload and |
| 52 | // compares it to the ones included in the upload. If there is a mismatch, the |
| 53 | // upload is flagged. If an Uploader implementation uploads to a server that |
| 54 | // doesn't do this validation, then |log_hash| and |log_signature| can be |
| 55 | // ignored. |
isherman | a672752 | 2015-08-06 22:28:49 | [diff] [blame] | 56 | virtual void UploadLog(const std::string& compressed_log_data, |
Nik | f305e36 | 2023-11-09 19:52:05 | [diff] [blame] | 57 | const LogMetadata& log_metadata, |
Steven Holte | 72428db | 2017-10-13 19:47:22 | [diff] [blame] | 58 | const std::string& log_hash, |
Jesse Doherty | 2eb4951 | 2019-01-18 17:53:27 | [diff] [blame] | 59 | const std::string& log_signature, |
Steven Holte | 72428db | 2017-10-13 19:47:22 | [diff] [blame] | 60 | const ReportingInfo& reporting_info) = 0; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace metrics |
| 64 | |
| 65 | #endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_ |