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

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

Issue 2102023002: Add ContentSuggestionsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ContentSuggestionsServiceType; allow at most one provider per category 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/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"
14 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" 13 #include "components/ntp_snippets/proto/ntp_snippets.pb.h"
15 14
16 namespace { 15 namespace {
17 16
18 // dict.Get() specialization for base::Time values 17 // dict.Get() specialization for base::Time values
19 bool GetTimeValue(const base::DictionaryValue& dict, 18 bool GetTimeValue(const base::DictionaryValue& dict,
20 const std::string& key, 19 const std::string& key,
21 base::Time* time) { 20 base::Time* time) {
22 std::string time_value; 21 std::string time_value;
23 return dict.GetString(key, &time_value) && 22 return dict.GetString(key, &time_value) &&
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 source_proto->set_url(source.url.spec()); 238 source_proto->set_url(source.url.spec());
240 if (!source.publisher_name.empty()) 239 if (!source.publisher_name.empty())
241 source_proto->set_publisher_name(source.publisher_name); 240 source_proto->set_publisher_name(source.publisher_name);
242 if (source.amp_url.is_valid()) 241 if (source.amp_url.is_valid())
243 source_proto->set_amp_url(source.amp_url.spec()); 242 source_proto->set_amp_url(source.amp_url.spec());
244 } 243 }
245 244
246 return result; 245 return result;
247 } 246 }
248 247
249 std::unique_ptr<ContentSuggestion> NTPSnippet::ToContentSuggestion() const { 248 std::unique_ptr<ContentSuggestion> NTPSnippet::ToContentSuggestion(
249 const std::string& id) const {
250 std::unique_ptr<ContentSuggestion> result(new ContentSuggestion( 250 std::unique_ptr<ContentSuggestion> result(new ContentSuggestion(
251 id_, ContentSuggestionsProviderType::ARTICLES, 251 id, ContentSuggestionCategory::ARTICLE, best_source().url));
252 ContentSuggestionCategory::ARTICLE, best_source().url));
253 result->set_amp_url(best_source().amp_url); 252 result->set_amp_url(best_source().amp_url);
254 result->set_title(title_); 253 result->set_title(title_);
255 result->set_snippet_text(snippet_); 254 result->set_snippet_text(snippet_);
256 result->set_publish_date(publish_date_); 255 result->set_publish_date(publish_date_);
257 result->set_publisher_name(best_source().publisher_name); 256 result->set_publisher_name(best_source().publisher_name);
258 result->set_score(score_); 257 result->set_score(score_);
259 return result; 258 return result;
260 } 259 }
261 260
262 // static 261 // static
(...skipping 28 matching lines...) Expand all
291 best_source_index_ = i; 290 best_source_index_ = i;
292 if (!source.amp_url.is_empty()) { 291 if (!source.amp_url.is_empty()) {
293 // This is the best possible source, stop looking. 292 // This is the best possible source, stop looking.
294 break; 293 break;
295 } 294 }
296 } 295 }
297 } 296 }
298 } 297 }
299 298
300 } // namespace ntp_snippets 299 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698