Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / sync / notifier / mock_ack_handler.h
blob08f053925975834933566c3bedef14e1ce22d24c
1 // Copyright 2013 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_NOTIFIER_MOCK_ACK_HANDLER_H_
6 #define SYNC_NOTIFIER_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 "sync/base/sync_export.h"
14 #include "sync/internal_api/public/util/weak_handle.h"
15 #include "sync/notifier/ack_handler.h"
16 #include "sync/notifier/invalidation_util.h"
18 namespace syncer {
20 class Invalidation;
22 // This AckHandler implementation colaborates with the FakeInvalidationService
23 // to enable unit tests to assert that invalidations are being acked properly.
24 class SYNC_EXPORT MockAckHandler
25 : public AckHandler,
26 public base::SupportsWeakPtr<MockAckHandler> {
27 public:
28 MockAckHandler();
29 virtual ~MockAckHandler();
31 // Sets up some internal state to track this invalidation, and modifies it so
32 // that its Acknowledge() and Drop() methods will route back to us.
33 void RegisterInvalidation(Invalidation* invalidation);
35 // No one was listening for this invalidation, so no one will receive it or
36 // ack it. We keep track of it anyway to let tests make assertions about it.
37 void RegisterUnsentInvalidation(Invalidation* invalidation);
39 // Returns true if the specified invalidaition has been delivered, but has not
40 // been acknowledged yet.
41 bool IsUnacked(const Invalidation& invalidation) const;
43 // Returns true if the specified invalidation has been delivered and
44 // acknowledged.
45 bool IsAcknowledged(const Invalidation& invalidation) const;
47 // Returns true if the specified invalidation has been delivered and
48 // dropped.
49 bool IsDropped(const Invalidation& invalidation) const;
51 // Returns true if the specified invalidation was never delivered.
52 bool IsUnsent(const Invalidation& invalidation) const;
54 // Retruns true if all invalidations have been acked and all drops recovered.
55 bool AllInvalidationsAccountedFor() const;
57 // Implementation of AckHandler.
58 virtual void Acknowledge(
59 const invalidation::ObjectId& id,
60 const AckHandle& handle) OVERRIDE;
61 virtual void Drop(
62 const invalidation::ObjectId& id,
63 const AckHandle& handle) OVERRIDE;
65 private:
66 typedef std::vector<syncer::Invalidation> InvalidationVector;
67 typedef std::map<invalidation::ObjectId,
68 AckHandle,
69 ObjectIdLessThan> IdHandleMap;
71 WeakHandle<AckHandler> WeakHandleThis();
73 InvalidationVector unsent_invalidations_;
74 InvalidationVector unacked_invalidations_;
75 InvalidationVector acked_invalidations_;
76 InvalidationVector dropped_invalidations_;
78 IdHandleMap unrecovered_drop_events_;
81 } // namespace syncer
83 #endif // SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_