blob: e4edf7b95d96a68c5fc6a3c0259c6f033395ba8a [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2014 The Chromium Authors
[email protected]0d5a61a82014-05-31 22:28:342// 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 Drissman12be0312023-01-11 09:16:0910#include "base/functional/callback.h"
holte4ae63f52017-03-08 00:25:0811#include "base/strings/string_piece.h"
[email protected]0d5a61a82014-05-31 22:28:3412
13namespace metrics {
14
Steven Holte72428db2017-10-13 19:47:2215class ReportingInfo;
16
[email protected]0d5a61a82014-05-31 22:28:3417// MetricsLogUploader is an abstract base class for uploading UMA logs on behalf
18// of MetricsService.
19class MetricsLogUploader {
20 public:
Luc Nguyen86136bb2023-04-25 20:31:5121 // 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)>;
holte035ec7fb2017-04-04 20:16:5932
rkaplow9c420822017-02-24 15:29:5733 // Possible service types. This should correspond to a type from
34 // DataUseUserData.
Andrew Bregger8d5ba3e2023-05-22 19:49:3335 // TODO(crbug.com/1445151) Investigate cleaning up this enum if it isn't
36 // needed anymore.
rkaplow9c420822017-02-24 15:29:5737 enum MetricServiceType {
38 UMA,
39 UKM,
Andrew Bregger8d5ba3e2023-05-22 19:49:3340 STRUCTURED_METRICS,
rkaplow9c420822017-02-24 15:29:5741 };
42
Luc Nguyen86136bb2023-04-25 20:31:5143 virtual ~MetricsLogUploader() = default;
[email protected]0d5a61a82014-05-31 22:28:3444
Jesse Doherty2eb49512019-01-18 17:53:2745 // 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.
ishermana6727522015-08-06 22:28:4954 virtual void UploadLog(const std::string& compressed_log_data,
Steven Holte72428db2017-10-13 19:47:2255 const std::string& log_hash,
Jesse Doherty2eb49512019-01-18 17:53:2756 const std::string& log_signature,
Steven Holte72428db2017-10-13 19:47:2257 const ReportingInfo& reporting_info) = 0;
[email protected]0d5a61a82014-05-31 22:28:3458};
59
60} // namespace metrics
61
62#endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_