OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/ntp_snippets/ntp_snippet.h" | 5 #include "components/ntp_snippets/ntp_snippet.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "components/ntp_snippets/content_suggestion.h" | 11 #include "components/ntp_snippets/content_suggestion.h" |
12 #include "components/ntp_snippets/content_suggestion_category.h" | 12 #include "components/ntp_snippets/content_suggestion_category.h" |
13 #include "components/ntp_snippets/content_suggestions_provider_type.h" | 13 #include "components/ntp_snippets/content_suggestions_provider.h" |
14 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" | 14 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // dict.Get() specialization for base::Time values | 18 // dict.Get() specialization for base::Time values |
19 bool GetTimeValue(const base::DictionaryValue& dict, | 19 bool GetTimeValue(const base::DictionaryValue& dict, |
20 const std::string& key, | 20 const std::string& key, |
21 base::Time* time) { | 21 base::Time* time) { |
22 std::string time_value; | 22 std::string time_value; |
23 return dict.GetString(key, &time_value) && | 23 return dict.GetString(key, &time_value) && |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 source_proto->set_publisher_name(source.publisher_name); | 241 source_proto->set_publisher_name(source.publisher_name); |
242 if (source.amp_url.is_valid()) | 242 if (source.amp_url.is_valid()) |
243 source_proto->set_amp_url(source.amp_url.spec()); | 243 source_proto->set_amp_url(source.amp_url.spec()); |
244 } | 244 } |
245 | 245 |
246 return result; | 246 return result; |
247 } | 247 } |
248 | 248 |
249 std::unique_ptr<ContentSuggestion> NTPSnippet::ToContentSuggestion() const { | 249 std::unique_ptr<ContentSuggestion> NTPSnippet::ToContentSuggestion() const { |
250 std::unique_ptr<ContentSuggestion> result(new ContentSuggestion( | 250 std::unique_ptr<ContentSuggestion> result(new ContentSuggestion( |
251 id_, ContentSuggestionsProviderType::ARTICLES, | 251 ContentSuggestionsProvider::MakeUniqueID( |
| 252 ContentSuggestionCategory::ARTICLE, id_), |
252 ContentSuggestionCategory::ARTICLE, best_source().url)); | 253 ContentSuggestionCategory::ARTICLE, best_source().url)); |
253 result->set_amp_url(best_source().amp_url); | 254 result->set_amp_url(best_source().amp_url); |
254 result->set_title(title_); | 255 result->set_title(title_); |
255 result->set_snippet_text(snippet_); | 256 result->set_snippet_text(snippet_); |
256 result->set_publish_date(publish_date_); | 257 result->set_publish_date(publish_date_); |
257 result->set_publisher_name(best_source().publisher_name); | 258 result->set_publisher_name(best_source().publisher_name); |
258 result->set_score(score_); | 259 result->set_score(score_); |
259 return result; | 260 return result; |
260 } | 261 } |
261 | 262 |
(...skipping 29 matching lines...) Expand all Loading... |
291 best_source_index_ = i; | 292 best_source_index_ = i; |
292 if (!source.amp_url.is_empty()) { | 293 if (!source.amp_url.is_empty()) { |
293 // This is the best possible source, stop looking. | 294 // This is the best possible source, stop looking. |
294 break; | 295 break; |
295 } | 296 } |
296 } | 297 } |
297 } | 298 } |
298 } | 299 } |
299 | 300 |
300 } // namespace ntp_snippets | 301 } // namespace ntp_snippets |
OLD | NEW |