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

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: Remove Offline Pages from SnippetCategory and SnippetProviderType Created 4 years, 6 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/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" 10 #include "components/ntp_snippets/proto/ntp_snippets.pb.h"
11 #include "components/ntp_snippets/snippet.h"
12 #include "components/ntp_snippets/snippet_category.h"
13 #include "components/ntp_snippets/snippet_provider_type.h"
11 14
12 namespace { 15 namespace {
13 16
14 const char kScore[] = "score"; 17 const char kScore[] = "score";
15 const char kContentInfo[] = "contentInfo"; 18 const char kContentInfo[] = "contentInfo";
16 19
17 const char kId[] = "url"; 20 const char kId[] = "url";
18 const char kTitle[] = "title"; 21 const char kTitle[] = "title";
19 const char kSalientImageUrl[] = "thumbnailUrl"; 22 const char kSalientImageUrl[] = "thumbnailUrl";
20 const char kSnippet[] = "snippet"; 23 const char kSnippet[] = "snippet";
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 source_proto->set_url(source.url.spec()); 217 source_proto->set_url(source.url.spec());
215 if (!source.publisher_name.empty()) 218 if (!source.publisher_name.empty())
216 source_proto->set_publisher_name(source.publisher_name); 219 source_proto->set_publisher_name(source.publisher_name);
217 if (source.amp_url.is_valid()) 220 if (source.amp_url.is_valid())
218 source_proto->set_amp_url(source.amp_url.spec()); 221 source_proto->set_amp_url(source.amp_url.spec());
219 } 222 }
220 223
221 return result; 224 return result;
222 } 225 }
223 226
227 std::unique_ptr<Snippet> NTPSnippet::ToSnippet() const {
228 std::unique_ptr<Snippet> result(
229 new Snippet(id_, SnippetProviderType::ARTICLES, SnippetCategory::ARTICLE,
230 best_source().url));
231 result->set_amp_url(best_source().amp_url);
232 result->set_title(title_);
233 result->set_text_extract(snippet_);
234 result->set_publish_date(publish_date_);
235 result->set_publisher_name(best_source().publisher_name);
236 result->set_score(score_);
237 return result;
238 }
239
224 // static 240 // static
225 base::Time NTPSnippet::TimeFromJsonString(const std::string& timestamp_str) { 241 base::Time NTPSnippet::TimeFromJsonString(const std::string& timestamp_str) {
226 int64_t timestamp; 242 int64_t timestamp;
227 if (!base::StringToInt64(timestamp_str, &timestamp)) { 243 if (!base::StringToInt64(timestamp_str, &timestamp)) {
228 // Even if there's an error in the conversion, some garbage data may still 244 // Even if there's an error in the conversion, some garbage data may still
229 // be written to the output var, so reset it. 245 // be written to the output var, so reset it.
230 timestamp = 0; 246 timestamp = 0;
231 } 247 }
232 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(timestamp); 248 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(timestamp);
233 } 249 }
(...skipping 19 matching lines...) Expand all
253 best_source_index_ = i; 269 best_source_index_ = i;
254 if (!source.amp_url.is_empty()) { 270 if (!source.amp_url.is_empty()) {
255 // This is the best possible source, stop looking. 271 // This is the best possible source, stop looking.
256 break; 272 break;
257 } 273 }
258 } 274 }
259 } 275 }
260 } 276 }
261 277
262 } // namespace ntp_snippets 278 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698