Get foreground tab on Android
[chromium-blink-merge.git] / sync / notifier / mock_ack_handler.h
blob665955892bfd60803b1e429db781694471ae4d4b
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 <vector>
10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h"
12 #include "sync/base/sync_export.h"
13 #include "sync/internal_api/public/util/weak_handle.h"
14 #include "sync/notifier/ack_handler.h"
16 namespace syncer {
18 class Invalidation;
20 // This AckHandler implementation colaborates with the FakeInvalidationService
21 // to enable unit tests to assert that invalidations are being acked properly.
22 class MockAckHandler
23 : public AckHandler,
24 public base::SupportsWeakPtr<MockAckHandler> {
25 public:
26 MockAckHandler();
27 virtual ~MockAckHandler();
29 // Sets up some internal state to track this invalidation, and modifies it so
30 // that its Acknowledge() and Drop() methods will route back to us.
31 void RegisterInvalidation(Invalidation* invalidation);
33 // No one was listening for this invalidation, so no one will receive it or
34 // ack it. We keep track of it anyway to let tests make assertions about it.
35 void RegisterUnsentInvalidation(Invalidation* invalidation);
37 // Returns true if the specified invalidaition has been delivered, but has not
38 // been acknowledged yet.
39 bool IsUnacked(const Invalidation& invalidation) const;
41 // Returns true if the specified invalidation was never delivered.
42 bool IsUnsent(const Invalidation& invalidation) const;
44 // Implementation of AckHandler.
45 virtual void Acknowledge(
46 const invalidation::ObjectId& id,
47 const AckHandle& handle) OVERRIDE;
48 virtual void Drop(
49 const invalidation::ObjectId& id,
50 const AckHandle& handle) OVERRIDE;
52 private:
53 typedef std::vector<syncer::Invalidation> InvalidationVector;
55 WeakHandle<AckHandler> WeakHandleThis();
57 InvalidationVector unsent_invalidations_;
58 InvalidationVector unacked_invalidations_;
59 InvalidationVector acked_invalidations_;
62 } // namespace syncer
64 #endif // SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_