blob: f47346eb1bbfe8c6affd39e438358171b92f4ff2 [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.
35 enum MetricServiceType {
36 UMA,
37 UKM,
38 };
39
Luc Nguyen86136bb2023-04-25 20:31:5140 virtual ~MetricsLogUploader() = default;
[email protected]0d5a61a82014-05-31 22:28:3441
Jesse Doherty2eb49512019-01-18 17:53:2742 // Uploads a log with the specified |compressed_log_data|, a |log_hash| and
43 // |log_signature| for data validation, and |reporting_info|. |log_hash| is
44 // expected to be the hex-encoded SHA1 hash of the log data before compression
45 // and |log_signature| is expected to be a base64-encoded HMAC-SHA256
46 // signature of the log data before compression. When the server receives an
47 // upload it recomputes the hash and signature of the upload and compares it
48 // to the ones inlcuded in the upload. If there is a missmatched, the upload
49 // is flagged. If an Uploader implementation uploads to a server that doesn't
50 // do this validation then |log_hash| and |log_signature| can be ignored.
ishermana6727522015-08-06 22:28:4951 virtual void UploadLog(const std::string& compressed_log_data,
Steven Holte72428db2017-10-13 19:47:2252 const std::string& log_hash,
Jesse Doherty2eb49512019-01-18 17:53:2753 const std::string& log_signature,
Steven Holte72428db2017-10-13 19:47:2254 const ReportingInfo& reporting_info) = 0;
[email protected]0d5a61a82014-05-31 22:28:3455};
56
57} // namespace metrics
58
59#endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_