xref: /aosp_15_r20/external/cronet/components/metrics/test/test_metrics_log_uploader.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 : public MetricsLogUploader {
16  public:
17   explicit TestMetricsLogUploader(
18       const MetricsLogUploader::UploadCallback& on_upload_complete);
19 
20   TestMetricsLogUploader(const TestMetricsLogUploader&) = delete;
21   TestMetricsLogUploader& operator=(const TestMetricsLogUploader&) = delete;
22 
23   ~TestMetricsLogUploader() override;
24 
25   // Mark the current upload complete with the given response code.
26   void CompleteUpload(int response_code, bool force_discard = false);
27 
28   // Check if UploadLog has been called.
is_uploading()29   bool is_uploading() const { return is_uploading_; }
30 
reporting_info()31   const ReportingInfo& reporting_info() const { return last_reporting_info_; }
32 
AsWeakPtr()33   base::WeakPtr<TestMetricsLogUploader> AsWeakPtr() {
34     return weak_ptr_factory_.GetWeakPtr();
35   }
36 
37  private:
38   // MetricsLogUploader:
39   void UploadLog(const std::string& compressed_log_data,
40                  const LogMetadata& log_metadata,
41                  const std::string& log_hash,
42                  const std::string& log_signature,
43                  const ReportingInfo& reporting_info) override;
44 
45   const MetricsLogUploader::UploadCallback on_upload_complete_;
46   ReportingInfo last_reporting_info_;
47   bool is_uploading_;
48   base::WeakPtrFactory<TestMetricsLogUploader> weak_ptr_factory_{this};
49 };
50 
51 }  // namespace metrics
52 
53 #endif  // COMPONENTS_METRICS_TEST_TEST_METRICS_LOG_UPLOADER_H_
54