Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: components/ntp_snippets/ntp_snippet.cc

Issue 2059203002: Add ContentSuggestion, ContentSuggestionCategory and ContentSuggestionProviderType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed ContentSuggestionProviderType to ContentSuggestionsProviderType Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/content_suggestions_provider_type.h>
Marc Treib 2016/06/27 12:25:36 Here too
Philipp Keck 2016/06/27 12:46:53 Done.
5 #include "components/ntp_snippets/ntp_snippet.h" 6 #include "components/ntp_snippets/ntp_snippet.h"
6 7
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/ntp_snippets/content_suggestion.h"
13 #include "components/ntp_snippets/content_suggestion_category.h"
11 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" 14 #include "components/ntp_snippets/proto/ntp_snippets.pb.h"
12 15
13 namespace { 16 namespace {
14 17
15 // dict.Get() specialization for base::Time values 18 // dict.Get() specialization for base::Time values
16 bool GetTimeValue(const base::DictionaryValue& dict, 19 bool GetTimeValue(const base::DictionaryValue& dict,
17 const std::string& key, 20 const std::string& key,
18 base::Time* time) { 21 base::Time* time) {
19 const base::DictionaryValue* time_value; 22 const base::DictionaryValue* time_value;
20 int seconds = 0, nanos = 0; 23 int seconds = 0, nanos = 0;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 source_proto->set_url(source.url.spec()); 246 source_proto->set_url(source.url.spec());
244 if (!source.publisher_name.empty()) 247 if (!source.publisher_name.empty())
245 source_proto->set_publisher_name(source.publisher_name); 248 source_proto->set_publisher_name(source.publisher_name);
246 if (source.amp_url.is_valid()) 249 if (source.amp_url.is_valid())
247 source_proto->set_amp_url(source.amp_url.spec()); 250 source_proto->set_amp_url(source.amp_url.spec());
248 } 251 }
249 252
250 return result; 253 return result;
251 } 254 }
252 255
256 std::unique_ptr<ContentSuggestion> NTPSnippet::ToContentSuggestion() const {
257 std::unique_ptr<ContentSuggestion> result(new ContentSuggestion(
258 id_, ContentSuggestionsProviderType::ARTICLES,
259 ContentSuggestionCategory::ARTICLE, best_source().url));
260 result->set_amp_url(best_source().amp_url);
261 result->set_title(title_);
262 result->set_snippet_text(snippet_);
263 result->set_publish_date(publish_date_);
264 result->set_publisher_name(best_source().publisher_name);
265 result->set_score(score_);
266 return result;
267 }
268
253 // static 269 // static
254 base::Time NTPSnippet::TimeFromJsonString(const std::string& timestamp_str) { 270 base::Time NTPSnippet::TimeFromJsonString(const std::string& timestamp_str) {
255 int64_t timestamp; 271 int64_t timestamp;
256 if (!base::StringToInt64(timestamp_str, &timestamp)) { 272 if (!base::StringToInt64(timestamp_str, &timestamp)) {
257 // Even if there's an error in the conversion, some garbage data may still 273 // Even if there's an error in the conversion, some garbage data may still
258 // be written to the output var, so reset it. 274 // be written to the output var, so reset it.
259 timestamp = 0; 275 timestamp = 0;
260 } 276 }
261 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(timestamp); 277 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(timestamp);
262 } 278 }
(...skipping 19 matching lines...) Expand all
282 best_source_index_ = i; 298 best_source_index_ = i;
283 if (!source.amp_url.is_empty()) { 299 if (!source.amp_url.is_empty()) {
284 // This is the best possible source, stop looking. 300 // This is the best possible source, stop looking.
285 break; 301 break;
286 } 302 }
287 } 303 }
288 } 304 }
289 } 305 }
290 306
291 } // namespace ntp_snippets 307 } // namespace ntp_snippets
OLDNEW
« components/ntp_snippets/content_suggestion.h ('K') | « components/ntp_snippets/ntp_snippet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698