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> |
| 9 | |
Avi Drissman | 12be031 | 2023-01-11 09:16:09 | [diff] [blame] | 10 | #include "base/functional/callback.h" |
holte | 4ae63f5 | 2017-03-08 00:25:08 | [diff] [blame] | 11 | #include "base/strings/string_piece.h" |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 12 | |
| 13 | namespace metrics { |
| 14 | |
Steven Holte | 72428db | 2017-10-13 19:47:22 | [diff] [blame] | 15 | class ReportingInfo; |
| 16 | |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 17 | // MetricsLogUploader is an abstract base class for uploading UMA logs on behalf |
| 18 | // of MetricsService. |
| 19 | class MetricsLogUploader { |
| 20 | public: |
Luc Nguyen | 86136bb | 2023-04-25 20:31:51 | [diff] [blame] | 21 | // Type for OnUploadComplete callbacks. These callbacks will receive five |
| 22 | // parameters: |
| 23 | // - a response code, |
| 24 | // - a net error code, |
| 25 | // - a boolean specifying if the connection was secure (over HTTPS), |
| 26 | // - a boolean specifying if the log should be discarded regardless of |
| 27 | // response/error code, |
| 28 | // - a string specifying the reason why the log was forcibly discarded (or |
| 29 | // empty string if not). |
| 30 | using UploadCallback = |
| 31 | base::RepeatingCallback<void(int, int, bool, bool, base::StringPiece)>; |
holte | 035ec7fb | 2017-04-04 20:16:59 | [diff] [blame] | 32 | |
rkaplow | 9c42082 | 2017-02-24 15:29:57 | [diff] [blame] | 33 | // Possible service types. This should correspond to a type from |
| 34 | // DataUseUserData. |
Andrew Bregger | 8d5ba3e | 2023-05-22 19:49:33 | [diff] [blame^] | 35 | // TODO(crbug.com/1445151) Investigate cleaning up this enum if it isn't |
| 36 | // needed anymore. |
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, |
rkaplow | 9c42082 | 2017-02-24 15:29:57 | [diff] [blame] | 41 | }; |
| 42 | |
Luc Nguyen | 86136bb | 2023-04-25 20:31:51 | [diff] [blame] | 43 | virtual ~MetricsLogUploader() = default; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 44 | |
Jesse Doherty | 2eb4951 | 2019-01-18 17:53:27 | [diff] [blame] | 45 | // Uploads a log with the specified |compressed_log_data|, a |log_hash| and |
| 46 | // |log_signature| for data validation, and |reporting_info|. |log_hash| is |
| 47 | // expected to be the hex-encoded SHA1 hash of the log data before compression |
| 48 | // and |log_signature| is expected to be a base64-encoded HMAC-SHA256 |
| 49 | // signature of the log data before compression. When the server receives an |
| 50 | // upload it recomputes the hash and signature of the upload and compares it |
| 51 | // to the ones inlcuded in the upload. If there is a missmatched, the upload |
| 52 | // is flagged. If an Uploader implementation uploads to a server that doesn't |
| 53 | // do this validation then |log_hash| and |log_signature| can be ignored. |
isherman | a672752 | 2015-08-06 22:28:49 | [diff] [blame] | 54 | virtual void UploadLog(const std::string& compressed_log_data, |
Steven Holte | 72428db | 2017-10-13 19:47:22 | [diff] [blame] | 55 | const std::string& log_hash, |
Jesse Doherty | 2eb4951 | 2019-01-18 17:53:27 | [diff] [blame] | 56 | const std::string& log_signature, |
Steven Holte | 72428db | 2017-10-13 19:47:22 | [diff] [blame] | 57 | const ReportingInfo& reporting_info) = 0; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } // namespace metrics |
| 61 | |
| 62 | #endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_ |