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 13 namespace metrics { 14 15 class ReportingInfo; 16 17 // MetricsLogUploader is an abstract base class for uploading UMA logs on behalf 18 // of MetricsService. 19 class MetricsLogUploader { 20 public: 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)>; 32 33 // Possible service types. This should correspond to a type from 34 // DataUseUserData. 35 enum MetricServiceType { 36 UMA, 37 UKM, 38 }; 39 40 virtual ~MetricsLogUploader() = default; 41 42 // 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. 51 virtual void UploadLog(const std::string& compressed_log_data, 52 const std::string& log_hash, 53 const std::string& log_signature, 54 const ReportingInfo& reporting_info) = 0; 55 }; 56 57 } // namespace metrics 58 59 #endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_ 60