topic_invalidation_map.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_PUBLIC_TOPIC_INVALIDATION_MAP_H_
  5. #define COMPONENTS_INVALIDATION_PUBLIC_TOPIC_INVALIDATION_MAP_H_
  6. #include <map>
  7. #include <memory>
  8. #include <vector>
  9. #include "components/invalidation/public/invalidation.h"
  10. #include "components/invalidation/public/invalidation_export.h"
  11. #include "components/invalidation/public/invalidation_util.h"
  12. #include "components/invalidation/public/single_topic_invalidation_set.h"
  13. namespace base {
  14. class ListValue;
  15. } // namespace base
  16. namespace invalidation {
  17. // A set of notifications with some helper methods to organize them by Topic
  18. // and version number.
  19. class INVALIDATION_EXPORT TopicInvalidationMap {
  20. public:
  21. TopicInvalidationMap();
  22. TopicInvalidationMap(const TopicInvalidationMap& other);
  23. TopicInvalidationMap& operator=(const TopicInvalidationMap& other);
  24. ~TopicInvalidationMap();
  25. // Returns set of Topics for which at least one invalidation is present.
  26. TopicSet GetTopics() const;
  27. // Returns true if this map contains no invalidations.
  28. bool Empty() const;
  29. // Returns true if both maps contain the same set of invalidations.
  30. bool operator==(const TopicInvalidationMap& other) const;
  31. // Inserts a new invalidation into this map.
  32. void Insert(const Invalidation& invalidation);
  33. // Returns a new map containing the subset of invaliations from this map
  34. // whose topic were in the specified |topics|.
  35. // TODO(crbug.com/1029698): replace all usages with the version below and
  36. // remove this method.
  37. TopicInvalidationMap GetSubsetWithTopics(const Topics& topics) const;
  38. // Returns a new map containing the subset of invaliations from this map
  39. // whose topic were in the specified |topics|.
  40. TopicInvalidationMap GetSubsetWithTopics(const TopicSet& topics) const;
  41. // Returns the subset of invalidations with Topic matching |topic|.
  42. const SingleTopicInvalidationSet& ForTopic(Topic topic) const;
  43. // Returns the contents of this map in a single vector.
  44. void GetAllInvalidations(std::vector<Invalidation>* out) const;
  45. // Call Acknowledge() on all contained Invalidations.
  46. void AcknowledgeAll() const;
  47. // Serialize this map to a value. Used to expose value on
  48. // chrome://invalidations page.
  49. std::unique_ptr<base::ListValue> ToValue() const;
  50. private:
  51. explicit TopicInvalidationMap(
  52. const std::map<Topic, SingleTopicInvalidationSet>& map);
  53. std::map<Topic, SingleTopicInvalidationSet> map_;
  54. };
  55. } // namespace invalidation
  56. #endif // COMPONENTS_INVALIDATION_PUBLIC_TOPIC_INVALIDATION_MAP_H_