fake_ack_handler.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.
  4. #ifndef COMPONENTS_INVALIDATION_IMPL_FAKE_ACK_HANDLER_H_
  5. #define COMPONENTS_INVALIDATION_IMPL_FAKE_ACK_HANDLER_H_
  6. #include <map>
  7. #include <vector>
  8. #include "base/compiler_specific.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "components/invalidation/public/ack_handler.h"
  11. #include "components/invalidation/public/invalidation_export.h"
  12. #include "components/invalidation/public/invalidation_util.h"
  13. namespace invalidation {
  14. class Invalidation;
  15. // This AckHandler implementation colaborates with the FakeInvalidationService
  16. // to enable unit tests to assert that invalidations are being acked properly.
  17. class INVALIDATION_EXPORT FakeAckHandler
  18. : public AckHandler,
  19. public base::SupportsWeakPtr<FakeAckHandler> {
  20. public:
  21. FakeAckHandler();
  22. ~FakeAckHandler() override;
  23. // Sets up some internal state to track this invalidation, and modifies it so
  24. // that its Acknowledge() and Drop() methods will route back to us.
  25. void RegisterInvalidation(Invalidation* invalidation);
  26. // No one was listening for this invalidation, so no one will receive it or
  27. // ack it. We keep track of it anyway to let tests make assertions about it.
  28. void RegisterUnsentInvalidation(Invalidation* invalidation);
  29. // Returns true if the specified invalidaition has been delivered, but has not
  30. // been acknowledged yet.
  31. bool IsUnacked(const Invalidation& invalidation) const;
  32. // Returns true if the specified invalidation has been delivered and
  33. // acknowledged.
  34. bool IsAcknowledged(const Invalidation& invalidation) const;
  35. // Returns true if the specified invalidation has been delivered and
  36. // dropped.
  37. bool IsDropped(const Invalidation& invalidation) const;
  38. // Returns true if the specified invalidation was never delivered.
  39. bool IsUnsent(const Invalidation& invalidation) const;
  40. // Retruns true if all invalidations have been acked and all drops recovered.
  41. bool AllInvalidationsAccountedFor() const;
  42. // Implementation of AckHandler.
  43. void Acknowledge(const Topic& topic, const AckHandle& handle) override;
  44. void Drop(const Topic& topic, const AckHandle& handle) override;
  45. private:
  46. typedef std::vector<Invalidation> InvalidationVector;
  47. InvalidationVector unsent_invalidations_;
  48. InvalidationVector unacked_invalidations_;
  49. InvalidationVector acked_invalidations_;
  50. InvalidationVector dropped_invalidations_;
  51. std::map<Topic, AckHandle> unrecovered_drop_events_;
  52. };
  53. } // namespace invalidation
  54. #endif // COMPONENTS_INVALIDATION_IMPL_FAKE_ACK_HANDLER_H_