| 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
|
|
|