Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / sync / notifier / mock_ack_handler.h
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.
4
5 #ifndef SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_
6 #define SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_
7
8 #include <map>
9 #include <vector>
10
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"
17
18 namespace syncer {
19
20 class Invalidation;
21
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();
30
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);
34
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);
38
39   // Returns true if the specified invalidaition has been delivered, but has not
40   // been acknowledged yet.
41   bool IsUnacked(const Invalidation& invalidation) const;
42
43   // Returns true if the specified invalidation has been delivered and
44   // acknowledged.
45   bool IsAcknowledged(const Invalidation& invalidation) const;
46
47   // Returns true if the specified invalidation has been delivered and
48   // dropped.
49   bool IsDropped(const Invalidation& invalidation) const;
50
51   // Returns true if the specified invalidation was never delivered.
52   bool IsUnsent(const Invalidation& invalidation) const;
53
54   // Retruns true if all invalidations have been acked and all drops recovered.
55   bool AllInvalidationsAccountedFor() const;
56
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;
64
65  private:
66   typedef std::vector<syncer::Invalidation> InvalidationVector;
67   typedef std::map<invalidation::ObjectId,
68                    AckHandle,
69                    ObjectIdLessThan> IdHandleMap;
70
71   WeakHandle<AckHandler> WeakHandleThis();
72
73   InvalidationVector unsent_invalidations_;
74   InvalidationVector unacked_invalidations_;
75   InvalidationVector acked_invalidations_;
76   InvalidationVector dropped_invalidations_;
77
78   IdHandleMap unrecovered_drop_events_;
79 };
80
81 }  // namespace syncer
82
83 #endif  // SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_