Fix Android sync regression as a result of https://codereview.chromium.org/1144543009
[chromium-blink-merge.git] / sync / test / mock_invalidation_tracker.h
blob9f0e5bd4496ea7c366673407305c70bc12b5bbff
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 SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_
6 #define SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_
8 #include <set>
10 #include "base/memory/scoped_ptr.h"
11 #include "sync/test/trackable_mock_invalidation.h"
13 namespace syncer {
15 // Instantiates and track the acknowledgement state of
16 // TrackableMockInvalidations.
17 class MockInvalidationTracker {
18 public:
19 // Builers to return new TrackableMockInvalidations associated with this
20 // object.
21 scoped_ptr<TrackableMockInvalidation> IssueUnknownVersionInvalidation();
22 scoped_ptr<TrackableMockInvalidation> IssueInvalidation(
23 int64 version,
24 const std::string& payload);
26 MockInvalidationTracker();
27 ~MockInvalidationTracker();
29 // Records the acknowledgement of the invalidation
30 // specified by the given ID.
31 void Acknowledge(int invaliation_id);
33 // Records the drop of the invalidation specified by the given ID.
34 void Drop(int invalidation_id);
36 // Returns true if the invalidation associated with the given ID is neither
37 // acknowledged nor dropped.
38 bool IsUnacked(int invalidation_id) const;
40 // Returns true if the invalidation associated with the given ID is
41 // acknowledged.
42 bool IsAcknowledged(int invalidation_id) const;
44 // Returns true if the invalidation associated with the given ID is dropped.
45 bool IsDropped(int invalidation_id) const;
47 // Returns true if all issued invalidations were acknowledged or dropped.
48 bool AllInvalidationsAccountedFor() const;
50 private:
51 // A counter used to assign strictly increasing IDs to each invalidation
52 // issued by this class.
53 int next_id_;
55 // Acknowledgements and drops are tracked by adding the IDs for the
56 // acknowledged or dropped items to the proper set. An invalidation may be
57 // both dropped and acknowledged if it represents the recovery from a drop
58 // event.
59 std::set<int> dropped_;
60 std::set<int> acknowledged_;
63 } // namespace syncer
65 #endif // SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_