1 // Copyright 2017 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_TEST_TEST_METRICS_LOG_UPLOADER_H_ 6 #define COMPONENTS_METRICS_TEST_TEST_METRICS_LOG_UPLOADER_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "components/metrics/metrics_log.h" 10 #include "components/metrics/metrics_log_uploader.h" 11 #include "third_party/metrics_proto/reporting_info.pb.h" 12 13 namespace metrics { 14 15 class TestMetricsLogUploader 16 : public MetricsLogUploader, 17 public base::SupportsWeakPtr<TestMetricsLogUploader> { 18 public: 19 explicit TestMetricsLogUploader( 20 const MetricsLogUploader::UploadCallback& on_upload_complete); 21 22 TestMetricsLogUploader(const TestMetricsLogUploader&) = delete; 23 TestMetricsLogUploader& operator=(const TestMetricsLogUploader&) = delete; 24 25 ~TestMetricsLogUploader() override; 26 27 // Mark the current upload complete with the given response code. 28 void CompleteUpload(int response_code, bool force_discard = false); 29 30 // Check if UploadLog has been called. is_uploading()31 bool is_uploading() const { return is_uploading_; } 32 reporting_info()33 const ReportingInfo& reporting_info() const { return last_reporting_info_; } 34 35 private: 36 // MetricsLogUploader: 37 void UploadLog(const std::string& compressed_log_data, 38 const LogMetadata& log_metadata, 39 const std::string& log_hash, 40 const std::string& log_signature, 41 const ReportingInfo& reporting_info) override; 42 43 const MetricsLogUploader::UploadCallback on_upload_complete_; 44 ReportingInfo last_reporting_info_; 45 bool is_uploading_; 46 }; 47 48 } // namespace metrics 49 50 #endif // COMPONENTS_METRICS_TEST_TEST_METRICS_LOG_UPLOADER_H_ 51