1 // Copyright 2014 The Chromium Authors 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 10 #include "base/functional/callback.h" 11 #include "base/strings/string_piece.h" 12 #include "components/metrics/metrics_log.h" 13 14 namespace metrics { 15 16 class ReportingInfo; 17 18 // MetricsLogUploader is an abstract base class for uploading UMA logs on behalf 19 // of MetricsService. 20 class MetricsLogUploader { 21 public: 22 // Type for OnUploadComplete callbacks. These callbacks receive five 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 = 32 base::RepeatingCallback<void(int, int, bool, bool, base::StringPiece)>; 33 34 // Possible service types. This should correspond to a type from 35 // DataUseUserData. 36 // TODO(crbug.com/40912258) Investigate cleaning up this enum if it isn't 37 // needed anymore. 38 enum MetricServiceType { 39 UMA, 40 UKM, 41 STRUCTURED_METRICS, 42 }; 43 44 virtual ~MetricsLogUploader() = default; 45 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 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. 56 virtual void UploadLog(const std::string& compressed_log_data, 57 const LogMetadata& log_metadata, 58 const std::string& log_hash, 59 const std::string& log_signature, 60 const ReportingInfo& reporting_info) = 0; 61 }; 62 63 } // namespace metrics 64 65 #endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_ 66