OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include <utility> | |
6 | |
7 #include "base/strings/utf_string_conversions.h" | |
5 #include "components/ntp_snippets/content_suggestion.h" | 8 #include "components/ntp_snippets/content_suggestion.h" |
9 #include "components/ntp_snippets/remote/ntp_snippet.h" | |
6 | 10 |
7 namespace ntp_snippets { | 11 namespace ntp_snippets { |
8 | 12 |
9 bool ContentSuggestion::ID::operator==(const ID& rhs) const { | 13 bool ContentSuggestion::ID::operator==(const ID& rhs) const { |
10 return category_ == rhs.category_ && | 14 return category_ == rhs.category_ && |
11 id_within_category_ == rhs.id_within_category_; | 15 id_within_category_ == rhs.id_within_category_; |
12 } | 16 } |
13 | 17 |
14 bool ContentSuggestion::ID::operator!=(const ID& rhs) const { | 18 bool ContentSuggestion::ID::operator!=(const ID& rhs) const { |
15 return !(*this == rhs); | 19 return !(*this == rhs); |
16 } | 20 } |
17 | 21 |
18 ContentSuggestion::ContentSuggestion(const ID& id, const GURL& url) | 22 ContentSuggestion::ContentSuggestion(const ID& id, const GURL& url) |
19 : id_(id), url_(url), score_(0) {} | 23 : id_(id), url_(url), score_(0) {} |
20 | 24 |
21 ContentSuggestion::ContentSuggestion(Category category, | 25 ContentSuggestion::ContentSuggestion(Category category, |
22 const std::string& id_within_category, | 26 const std::string& id_within_category, |
23 const GURL& url) | 27 const GURL& url) |
24 : id_(category, id_within_category), url_(url), score_(0) {} | 28 : id_(category, id_within_category), url_(url), score_(0) {} |
25 | 29 |
30 ContentSuggestion ContentSuggestion::FromSnippet(Category category, | |
31 const NTPSnippet* snippet) { | |
vitaliii
2016/11/01 23:29:57
Why is this a pointer?
I guess a constant link wou
fhorschig
2016/11/02 05:05:27
Dropped. (see declaration).
| |
32 ContentSuggestion suggestion(category, snippet->id(), | |
33 snippet->best_source().url); | |
34 suggestion.set_amp_url(snippet->best_source().amp_url); | |
35 suggestion.set_title(base::UTF8ToUTF16(snippet->title())); | |
36 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet())); | |
37 suggestion.set_publish_date(snippet->publish_date()); | |
38 suggestion.set_publisher_name( | |
39 base::UTF8ToUTF16(snippet->best_source().publisher_name)); | |
40 suggestion.set_score(snippet->score()); | |
41 | |
42 return suggestion; | |
43 } | |
44 | |
26 ContentSuggestion::ContentSuggestion(ContentSuggestion&&) = default; | 45 ContentSuggestion::ContentSuggestion(ContentSuggestion&&) = default; |
27 | 46 |
28 ContentSuggestion& ContentSuggestion::operator=(ContentSuggestion&&) = default; | 47 ContentSuggestion& ContentSuggestion::operator=(ContentSuggestion&&) = default; |
29 | 48 |
30 ContentSuggestion::~ContentSuggestion() = default; | 49 ContentSuggestion::~ContentSuggestion() = default; |
31 | 50 |
32 std::ostream& operator<<(std::ostream& os, const ContentSuggestion::ID& id) { | 51 std::ostream& operator<<(std::ostream& os, const ContentSuggestion::ID& id) { |
33 os << id.category() << "|" << id.id_within_category(); | 52 os << id.category() << "|" << id.id_within_category(); |
34 return os; | 53 return os; |
35 } | 54 } |
36 | 55 |
37 } // namespace ntp_snippets | 56 } // namespace ntp_snippets |
OLD | NEW |