metrics_log_uploader.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_
  5. #define COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "base/strings/string_piece.h"
  9. namespace metrics {
  10. class ReportingInfo;
  11. // MetricsLogUploader is an abstract base class for uploading UMA logs on behalf
  12. // of MetricsService.
  13. class MetricsLogUploader {
  14. public:
  15. // Type for OnUploadComplete callbacks. These callbacks will receive three
  16. // parameters: A response code, a net error code, and a boolean specifying
  17. // if the connection was secure (over HTTPS).
  18. using UploadCallback = base::RepeatingCallback<void(int, int, bool)>;
  19. // Possible service types. This should correspond to a type from
  20. // DataUseUserData.
  21. enum MetricServiceType {
  22. UMA,
  23. UKM,
  24. };
  25. virtual ~MetricsLogUploader() {}
  26. // Uploads a log with the specified |compressed_log_data|, a |log_hash| and
  27. // |log_signature| for data validation, and |reporting_info|. |log_hash| is
  28. // expected to be the hex-encoded SHA1 hash of the log data before compression
  29. // and |log_signature| is expected to be a base64-encoded HMAC-SHA256
  30. // signature of the log data before compression. When the server receives an
  31. // upload it recomputes the hash and signature of the upload and compares it
  32. // to the ones inlcuded in the upload. If there is a missmatched, the upload
  33. // is flagged. If an Uploader implementation uploads to a server that doesn't
  34. // do this validation then |log_hash| and |log_signature| can be ignored.
  35. virtual void UploadLog(const std::string& compressed_log_data,
  36. const std::string& log_hash,
  37. const std::string& log_signature,
  38. const ReportingInfo& reporting_info) = 0;
  39. };
  40. } // namespace metrics
  41. #endif // COMPONENTS_METRICS_METRICS_LOG_UPLOADER_H_