Invalidate scans when the host volume is unmounted.
[chromium-blink-merge.git] / components / rappor / test_rappor_service.h
blob8ca22a374e18d62ec2420c2b5d071a31d8967499
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.
5 #ifndef COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_
6 #define COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_
8 #include <string>
10 #include "base/prefs/testing_pref_service.h"
11 #include "components/rappor/rappor_service.h"
12 #include "components/rappor/test_log_uploader.h"
14 namespace rappor {
16 // This class provides a simple instance that can be instantiated by tests
17 // and examined to check that metrics were recorded. It assumes the most
18 // permissive settings so that any metric can be recorded.
19 class TestRapporService : public RapporService {
20 public:
21 TestRapporService();
23 ~TestRapporService() override;
25 // Gets the number of reports that would be uploaded by this service.
26 // This also clears the internal map of metrics as a biproduct, so if
27 // comparing numbers of reports, the comparison should be from the last time
28 // GetReportsCount() was called (not from the beginning of the test).
29 int GetReportsCount();
31 // Gets the reports proto that would be uploaded.
32 // This clears the internal map of metrics.
33 void GetReports(RapporReports* reports);
35 // Loads the cohort from TestingPrefService.
36 int32_t LoadCohortForTesting();
38 // Loads the secret from TestingPrefService.
39 std::string LoadSecretForTesting();
41 void set_is_incognito(bool is_incognito) { is_incognito_ = is_incognito; }
43 TestingPrefServiceSimple* test_prefs() { return &test_prefs_; }
45 TestLogUploader* test_uploader() { return test_uploader_; }
47 base::TimeDelta next_rotation() { return next_rotation_; }
49 protected:
50 // Cancels the next call to OnLogInterval.
51 void CancelNextLogRotation() override;
53 // Schedules the next call to OnLogInterval.
54 void ScheduleNextLogRotation(base::TimeDelta interval) override;
56 private:
57 TestingPrefServiceSimple test_prefs_;
59 // Holds a weak ref to the uploader_ object.
60 TestLogUploader* test_uploader_;
62 // The last scheduled log rotation.
63 base::TimeDelta next_rotation_;
65 // Sets this to true to mock incognito state.
66 bool is_incognito_;
68 DISALLOW_COPY_AND_ASSIGN(TestRapporService);
71 } // namespace rappor
73 #endif // COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_