OLD | NEW |
| (Empty) |
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 | |
5 #ifndef SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_ | |
6 #define SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 #include <set> | |
12 #include <string> | |
13 | |
14 #include "sync/test/trackable_mock_invalidation.h" | |
15 | |
16 namespace syncer { | |
17 | |
18 // Instantiates and track the acknowledgement state of | |
19 // TrackableMockInvalidations. | |
20 class MockInvalidationTracker { | |
21 public: | |
22 // Builers to return new TrackableMockInvalidations associated with this | |
23 // object. | |
24 std::unique_ptr<TrackableMockInvalidation> IssueUnknownVersionInvalidation(); | |
25 std::unique_ptr<TrackableMockInvalidation> IssueInvalidation( | |
26 int64_t version, | |
27 const std::string& payload); | |
28 | |
29 MockInvalidationTracker(); | |
30 ~MockInvalidationTracker(); | |
31 | |
32 // Records the acknowledgement of the invalidation | |
33 // specified by the given ID. | |
34 void Acknowledge(int invaliation_id); | |
35 | |
36 // Records the drop of the invalidation specified by the given ID. | |
37 void Drop(int invalidation_id); | |
38 | |
39 // Returns true if the invalidation associated with the given ID is neither | |
40 // acknowledged nor dropped. | |
41 bool IsUnacked(int invalidation_id) const; | |
42 | |
43 // Returns true if the invalidation associated with the given ID is | |
44 // acknowledged. | |
45 bool IsAcknowledged(int invalidation_id) const; | |
46 | |
47 // Returns true if the invalidation associated with the given ID is dropped. | |
48 bool IsDropped(int invalidation_id) const; | |
49 | |
50 // Returns true if all issued invalidations were acknowledged or dropped. | |
51 bool AllInvalidationsAccountedFor() const; | |
52 | |
53 private: | |
54 // A counter used to assign strictly increasing IDs to each invalidation | |
55 // issued by this class. | |
56 int next_id_; | |
57 | |
58 // Acknowledgements and drops are tracked by adding the IDs for the | |
59 // acknowledged or dropped items to the proper set. An invalidation may be | |
60 // both dropped and acknowledged if it represents the recovery from a drop | |
61 // event. | |
62 std::set<int> dropped_; | |
63 std::set<int> acknowledged_; | |
64 }; | |
65 | |
66 } // namespace syncer | |
67 | |
68 #endif // SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_ | |
OLD | NEW |