blob: 5b9a106d7f7e0137d3f4d8b6345059565f6d4b22 [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>
Helmut Januschkaff1c3ec2024-04-25 19:38:329#include <string_view>
[email protected]0d5a61a82014-05-31 22:28:3410
Avi Drissman12be0312023-01-11 09:16:0911#include "base/functional/callback.h"
Nikf305e362023-11-09 19:52:0512#include "components/metrics/metrics_log.h"
[email protected]0d5a61a82014-05-31 22:28:3413
14namespace metrics {
15
Steven Holte72428db2017-10-13 19:47:2216class ReportingInfo;
17
[email protected]0d5a61a82014-05-31 22:28:3418// MetricsLogUploader is an abstract base class for uploading UMA logs on behalf
19// of MetricsService.
20class MetricsLogUploader {
21 public:
Caitlin Fischer0adeaa312023-07-20 13:15:2822 // Type for OnUploadComplete callbacks. These callbacks receive five
Luc Nguyen86136bb2023-04-25 20:31:5123 // 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 Januschkaff1c3ec2024-04-25 19:38:3232 base::RepeatingCallback<void(int, int, bool, bool, std::string_view)>;
holte035ec7fb2017-04-04 20:16:5933
Alexei Svitkine68437642024-10-24 20:27:1134 // 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.
rkaplow9c420822017-02-24 15:29:5737 enum MetricServiceType {
38 UMA,
39 UKM,
Andrew Bregger8d5ba3e2023-05-22 19:49:3340 STRUCTURED_METRICS,
Jay Zhoud216a512024-09-25 19:25:3241 DWA,
rkaplow9c420822017-02-24 15:29:5742 };
43
Luc Nguyen86136bb2023-04-25 20:31:5144 virtual ~MetricsLogUploader() = default;
[email protected]0d5a61a82014-05-31 22:28:3445
Jesse Doherty2eb49512019-01-18 17:53:2746 // 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 Fischer0adeaa312023-07-20 13:15:2848 // 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.
ishermana6727522015-08-06 22:28:4956 virtual void UploadLog(const std::string& compressed_log_data,
Nikf305e362023-11-09 19:52:0557 const LogMetadata& log_metadata,
Steven Holte72428db2017-10-13 19:47:2258 const std::string& log_hash,
Jesse Doherty2eb49512019-01-18 17:53:2759 const std::string& log_signature,
Steven Holte72428db2017-10-13 19:47:2260 const ReportingInfo& reporting_info) = 0;
[email protected]0d5a61a82014-05-31 22:28:3461};
62
63} // namespace metrics
64
65#endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_