| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_ | 5 #ifndef COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_ |
| 6 #define COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_ | 6 #define COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "components/invalidation/ack_handler.h" | 13 #include "components/invalidation/ack_handler.h" |
| 14 #include "components/invalidation/invalidation_export.h" | 14 #include "components/invalidation/invalidation_export.h" |
| 15 #include "components/invalidation/invalidation_util.h" | 15 #include "components/invalidation/invalidation_util.h" |
| 16 | 16 |
| 17 namespace syncer { | 17 namespace syncer { |
| 18 | 18 |
| 19 class Invalidation; | 19 class Invalidation; |
| 20 | 20 |
| 21 // This AckHandler implementation colaborates with the FakeInvalidationService | 21 // This AckHandler implementation colaborates with the FakeInvalidationService |
| 22 // to enable unit tests to assert that invalidations are being acked properly. | 22 // to enable unit tests to assert that invalidations are being acked properly. |
| 23 class INVALIDATION_EXPORT MockAckHandler | 23 class INVALIDATION_EXPORT MockAckHandler |
| 24 : public AckHandler, | 24 : public AckHandler, |
| 25 public base::SupportsWeakPtr<MockAckHandler> { | 25 public base::SupportsWeakPtr<MockAckHandler> { |
| 26 public: | 26 public: |
| 27 MockAckHandler(); | 27 MockAckHandler(); |
| 28 virtual ~MockAckHandler(); | 28 ~MockAckHandler() override; |
| 29 | 29 |
| 30 // Sets up some internal state to track this invalidation, and modifies it so | 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. | 31 // that its Acknowledge() and Drop() methods will route back to us. |
| 32 void RegisterInvalidation(Invalidation* invalidation); | 32 void RegisterInvalidation(Invalidation* invalidation); |
| 33 | 33 |
| 34 // No one was listening for this invalidation, so no one will receive it or | 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. | 35 // ack it. We keep track of it anyway to let tests make assertions about it. |
| 36 void RegisterUnsentInvalidation(Invalidation* invalidation); | 36 void RegisterUnsentInvalidation(Invalidation* invalidation); |
| 37 | 37 |
| 38 // Returns true if the specified invalidaition has been delivered, but has not | 38 // Returns true if the specified invalidaition has been delivered, but has not |
| 39 // been acknowledged yet. | 39 // been acknowledged yet. |
| 40 bool IsUnacked(const Invalidation& invalidation) const; | 40 bool IsUnacked(const Invalidation& invalidation) const; |
| 41 | 41 |
| 42 // Returns true if the specified invalidation has been delivered and | 42 // Returns true if the specified invalidation has been delivered and |
| 43 // acknowledged. | 43 // acknowledged. |
| 44 bool IsAcknowledged(const Invalidation& invalidation) const; | 44 bool IsAcknowledged(const Invalidation& invalidation) const; |
| 45 | 45 |
| 46 // Returns true if the specified invalidation has been delivered and | 46 // Returns true if the specified invalidation has been delivered and |
| 47 // dropped. | 47 // dropped. |
| 48 bool IsDropped(const Invalidation& invalidation) const; | 48 bool IsDropped(const Invalidation& invalidation) const; |
| 49 | 49 |
| 50 // Returns true if the specified invalidation was never delivered. | 50 // Returns true if the specified invalidation was never delivered. |
| 51 bool IsUnsent(const Invalidation& invalidation) const; | 51 bool IsUnsent(const Invalidation& invalidation) const; |
| 52 | 52 |
| 53 // Retruns true if all invalidations have been acked and all drops recovered. | 53 // Retruns true if all invalidations have been acked and all drops recovered. |
| 54 bool AllInvalidationsAccountedFor() const; | 54 bool AllInvalidationsAccountedFor() const; |
| 55 | 55 |
| 56 // Implementation of AckHandler. | 56 // Implementation of AckHandler. |
| 57 virtual void Acknowledge( | 57 void Acknowledge(const invalidation::ObjectId& id, |
| 58 const invalidation::ObjectId& id, | 58 const AckHandle& handle) override; |
| 59 const AckHandle& handle) override; | 59 void Drop(const invalidation::ObjectId& id, const AckHandle& handle) override; |
| 60 virtual void Drop( | |
| 61 const invalidation::ObjectId& id, | |
| 62 const AckHandle& handle) override; | |
| 63 | 60 |
| 64 private: | 61 private: |
| 65 typedef std::vector<syncer::Invalidation> InvalidationVector; | 62 typedef std::vector<syncer::Invalidation> InvalidationVector; |
| 66 typedef std::map<invalidation::ObjectId, | 63 typedef std::map<invalidation::ObjectId, |
| 67 AckHandle, | 64 AckHandle, |
| 68 ObjectIdLessThan> IdHandleMap; | 65 ObjectIdLessThan> IdHandleMap; |
| 69 | 66 |
| 70 InvalidationVector unsent_invalidations_; | 67 InvalidationVector unsent_invalidations_; |
| 71 InvalidationVector unacked_invalidations_; | 68 InvalidationVector unacked_invalidations_; |
| 72 InvalidationVector acked_invalidations_; | 69 InvalidationVector acked_invalidations_; |
| 73 InvalidationVector dropped_invalidations_; | 70 InvalidationVector dropped_invalidations_; |
| 74 | 71 |
| 75 IdHandleMap unrecovered_drop_events_; | 72 IdHandleMap unrecovered_drop_events_; |
| 76 }; | 73 }; |
| 77 | 74 |
| 78 } // namespace syncer | 75 } // namespace syncer |
| 79 | 76 |
| 80 #endif // COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_ | 77 #endif // COMPONENTS_INVALIDATION_MOCK_ACK_HANDLER_H_ |
| OLD | NEW |