[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / components / invalidation / mock_ack_handler.h
blob8afcb4fa8d01de4fa0a151aaa349023123eb0e7d
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_INVALIDATION_MOCK_ACK_HANDLER_H_
6 #define COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_
8 #include <map>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/invalidation/ack_handler.h"
14 #include "components/invalidation/invalidation_export.h"
15 #include "components/invalidation/invalidation_util.h"
17 namespace syncer {
19 class Invalidation;
21 // This AckHandler implementation colaborates with the FakeInvalidationService
22 // to enable unit tests to assert that invalidations are being acked properly.
23 class INVALIDATION_EXPORT MockAckHandler
24 : public AckHandler,
25 public base::SupportsWeakPtr<MockAckHandler> {
26 public:
27 MockAckHandler();
28 ~MockAckHandler() override;
30 // Sets up some internal state to track this invalidation, and modifies it so
31 // that its Acknowledge() and Drop() methods will route back to us.
32 void RegisterInvalidation(Invalidation* invalidation);
34 // No one was listening for this invalidation, so no one will receive it or
35 // ack it. We keep track of it anyway to let tests make assertions about it.
36 void RegisterUnsentInvalidation(Invalidation* invalidation);
38 // Returns true if the specified invalidaition has been delivered, but has not
39 // been acknowledged yet.
40 bool IsUnacked(const Invalidation& invalidation) const;
42 // Returns true if the specified invalidation has been delivered and
43 // acknowledged.
44 bool IsAcknowledged(const Invalidation& invalidation) const;
46 // Returns true if the specified invalidation has been delivered and
47 // dropped.
48 bool IsDropped(const Invalidation& invalidation) const;
50 // Returns true if the specified invalidation was never delivered.
51 bool IsUnsent(const Invalidation& invalidation) const;
53 // Retruns true if all invalidations have been acked and all drops recovered.
54 bool AllInvalidationsAccountedFor() const;
56 // Implementation of AckHandler.
57 void Acknowledge(const invalidation::ObjectId& id,
58 const AckHandle& handle) override;
59 void Drop(const invalidation::ObjectId& id, const AckHandle& handle) override;
61 private:
62 typedef std::vector<syncer::Invalidation> InvalidationVector;
63 typedef std::map<invalidation::ObjectId,
64 AckHandle,
65 ObjectIdLessThan> IdHandleMap;
67 InvalidationVector unsent_invalidations_;
68 InvalidationVector unacked_invalidations_;
69 InvalidationVector acked_invalidations_;
70 InvalidationVector dropped_invalidations_;
72 IdHandleMap unrecovered_drop_events_;
75 } // namespace syncer
77 #endif // COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_