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

Unified Diff: components/ntp_snippets/content_suggestions_provider.cc

Issue 2158883002: Change NTPSnippetsBridge to read from ContentSuggestionsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@offlinepagesprovider
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/content_suggestions_provider.cc
diff --git a/components/ntp_snippets/content_suggestions_provider.cc b/components/ntp_snippets/content_suggestions_provider.cc
index e4565e59d1c708b6f67650e3999940c5e44dd937..f40cdefdc40cfbe984b0467be09713813858bb6b 100644
--- a/components/ntp_snippets/content_suggestions_provider.cc
+++ b/components/ntp_snippets/content_suggestions_provider.cc
@@ -4,13 +4,14 @@
#include "components/ntp_snippets/content_suggestions_provider.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
namespace ntp_snippets {
namespace {
-const char kCombinedIDFormat[] = "%d:%s";
+const char kCombinedIDFormat[] = "%d|%s";
} // namespace
@@ -28,4 +29,25 @@ std::string ContentSuggestionsProvider::MakeUniqueID(
within_category_id.c_str());
}
+ContentSuggestionsCategory ContentSuggestionsProvider::GetCategoryFromUniqueID(
+ const std::string& unique_id) {
+ size_t colon_index = unique_id.find("|");
Marc Treib 2016/07/19 09:30:24 Make the pipe a constant? (kSeparator)
Philipp Keck 2016/07/19 12:21:50 Done.
+ DCHECK_NE(std::string::npos, colon_index) << "Not a valid unique_id: "
+ << unique_id;
+ int category;
+ DCHECK(base::StringToInt(unique_id.substr(0, colon_index), &category))
+ << "Non-numeric category part in unique_id: " << unique_id;
+ DCHECK(0 <= category && category < int(ContentSuggestionsCategory::COUNT))
+ << "Category does not exist: " << category;
+ return ContentSuggestionsCategory(category);
+}
+
+std::string ContentSuggestionsProvider::GetWithinCategoryIDFromUniqueID(
+ const std::string& unique_id) {
+ size_t colon_index = unique_id.find("|");
+ DCHECK_NE(std::string::npos, colon_index) << "Not a valid unique_id: "
+ << unique_id;
+ return unique_id.substr(colon_index + 1);
+}
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698