content_suggestion.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2016 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. #include "components/ntp_snippets/content_suggestion.h"
  5. #include <utility>
  6. namespace ntp_snippets {
  7. bool ContentSuggestion::ID::operator==(const ID& rhs) const {
  8. return category_ == rhs.category_ &&
  9. id_within_category_ == rhs.id_within_category_;
  10. }
  11. bool ContentSuggestion::ID::operator!=(const ID& rhs) const {
  12. return !(*this == rhs);
  13. }
  14. ContentSuggestion::ContentSuggestion(const ID& id, const GURL& url)
  15. : id_(id), url_(url), score_(0), is_video_suggestion_(false) {}
  16. ContentSuggestion::ContentSuggestion(Category category,
  17. const std::string& id_within_category,
  18. const GURL& url)
  19. : id_(category, id_within_category),
  20. url_(url),
  21. score_(0),
  22. is_video_suggestion_(false) {}
  23. ContentSuggestion::ContentSuggestion(ContentSuggestion&&) = default;
  24. ContentSuggestion& ContentSuggestion::operator=(ContentSuggestion&&) = default;
  25. ContentSuggestion::~ContentSuggestion() = default;
  26. std::ostream& operator<<(std::ostream& os, const ContentSuggestion::ID& id) {
  27. os << id.category() << "|" << id.id_within_category();
  28. return os;
  29. }
  30. // static
  31. GURL ContentSuggestion::GetFaviconDomain(const GURL& favicon_url) {
  32. return favicon_url.GetWithEmptyPath();
  33. }
  34. void ContentSuggestion::set_reading_list_suggestion_extra(
  35. std::unique_ptr<ReadingListSuggestionExtra> reading_list_suggestion_extra) {
  36. DCHECK(id_.category().IsKnownCategory(KnownCategories::READING_LIST));
  37. reading_list_suggestion_extra_ = std::move(reading_list_suggestion_extra);
  38. }
  39. void ContentSuggestion::set_notification_extra(
  40. std::unique_ptr<NotificationExtra> notification_extra) {
  41. notification_extra_ = std::move(notification_extra);
  42. }
  43. } // namespace ntp_snippets