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

Unified Diff: components/ntp_snippets/content_suggestions_provider.cc

Issue 2155243003: Use pipe as ID separator and add inverse functions for MakeUniqueID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@css-unittest
Patch Set: Fix category not initialized warning 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
« no previous file with comments | « components/ntp_snippets/content_suggestions_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..07947b860c71626564605cf121a2ececea7428b6 100644
--- a/components/ntp_snippets/content_suggestions_provider.cc
+++ b/components/ntp_snippets/content_suggestions_provider.cc
@@ -4,13 +4,15 @@
#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";
+const char kSeparator = '|';
} // namespace
@@ -20,6 +22,7 @@ ContentSuggestionsProvider::ContentSuggestionsProvider(
ContentSuggestionsProvider::~ContentSuggestionsProvider() {}
+// static
std::string ContentSuggestionsProvider::MakeUniqueID(
ContentSuggestionsCategory category,
const std::string& within_category_id) {
@@ -28,4 +31,27 @@ std::string ContentSuggestionsProvider::MakeUniqueID(
within_category_id.c_str());
}
+// static
+ContentSuggestionsCategory ContentSuggestionsProvider::GetCategoryFromUniqueID(
+ const std::string& unique_id) {
+ size_t colon_index = unique_id.find(kSeparator);
+ DCHECK_NE(std::string::npos, colon_index) << "Not a valid unique_id: "
+ << unique_id;
+ int category = -1;
+ 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);
+}
+
+// static
+std::string ContentSuggestionsProvider::GetWithinCategoryIDFromUniqueID(
+ const std::string& unique_id) {
+ size_t colon_index = unique_id.find(kSeparator);
+ DCHECK_NE(std::string::npos, colon_index) << "Not a valid unique_id: "
+ << unique_id;
+ return unique_id.substr(colon_index + 1);
+}
+
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/content_suggestions_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698