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