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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/ntp_snippet.cc
diff --git a/components/ntp_snippets/ntp_snippet.cc b/components/ntp_snippets/ntp_snippet.cc
index d7ca20c3392fd76c088a5de45aff7ebf92527627..c8b1b74be234ee65c6178032e940326b70e132b1 100644
--- a/components/ntp_snippets/ntp_snippet.cc
+++ b/components/ntp_snippets/ntp_snippet.cc
@@ -8,6 +8,9 @@
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "components/ntp_snippets/proto/ntp_snippets.pb.h"
+#include "components/ntp_snippets/snippet.h"
+#include "components/ntp_snippets/snippet_category.h"
+#include "components/ntp_snippets/snippet_provider_type.h"
namespace {
@@ -28,6 +31,11 @@ const char kAmpUrl[] = "ampUrl";
} // namespace
+// TODO IMPORTANT NOTE: This class will move to a sub-namespace and be renamed
+// ArticleSnippet. It will only be used for snippets from Chrome Reader.
+// When accessing snippets for all usages towards the UI, use the new "Snippet"
+// class through the "SnippetService" instead.
+
namespace ntp_snippets {
NTPSnippet::NTPSnippet(const std::string& id)
@@ -221,6 +229,20 @@ SnippetProto NTPSnippet::ToProto() const {
return result;
}
+std::unique_ptr<Snippet> NTPSnippet::ToSnippet() const {
+ std::unique_ptr<Snippet> result(new Snippet(
+ id_, SnippetProviderType::ARTICLES, SnippetCategory::ARTICLE));
+ result->set_url(best_source().url);
+ result->set_amp_url(best_source().amp_url);
+ result->set_title(title_);
+ result->set_text_extract(snippet_);
+ result->set_salient_image_url(salient_image_url_);
+ result->set_publish_date(publish_date_);
+ result->set_publisher_name(best_source().publisher_name);
+ result->set_score(score_);
+ return result;
+}
+
// static
base::Time NTPSnippet::TimeFromJsonString(const std::string& timestamp_str) {
int64_t timestamp;

Powered by Google App Engine
This is Rietveld 408576698