topic_and_domains.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2022 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_BROWSING_TOPICS_TOPIC_AND_DOMAINS_H_
  5. #define COMPONENTS_BROWSING_TOPICS_TOPIC_AND_DOMAINS_H_
  6. #include <set>
  7. #include "base/types/strong_alias.h"
  8. #include "base/values.h"
  9. #include "components/browsing_topics/common/common_types.h"
  10. namespace browsing_topics {
  11. // Contains a topic and a set of hashed domains that has observed the associated
  12. // topic (i.e. the Topics API was used within the domains's context, and the
  13. // page is related to that topic.)
  14. class TopicAndDomains {
  15. public:
  16. TopicAndDomains();
  17. TopicAndDomains(Topic topic, std::set<HashedDomain> hashed_domains);
  18. TopicAndDomains(const TopicAndDomains&) = delete;
  19. TopicAndDomains& operator=(const TopicAndDomains&) = delete;
  20. TopicAndDomains(TopicAndDomains&&);
  21. TopicAndDomains& operator=(TopicAndDomains&&);
  22. ~TopicAndDomains();
  23. // Serialization functions for storing in prefs.
  24. static TopicAndDomains FromDictValue(const base::Value::Dict& dict_value);
  25. base::Value::Dict ToDictValue() const;
  26. void ClearDomain(const HashedDomain& domain);
  27. bool IsValid() const { return topic_ != Topic(0); }
  28. const Topic& topic() const { return topic_; }
  29. const std::set<HashedDomain>& hashed_domains() const {
  30. return hashed_domains_;
  31. }
  32. private:
  33. Topic topic_{0};
  34. std::set<HashedDomain> hashed_domains_;
  35. };
  36. } // namespace browsing_topics
  37. #endif // COMPONENTS_BROWSING_TOPICS_TOPIC_AND_DOMAINS_H_