Chromium Code Reviews| 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..5e8a3750bb04f52caad75cf5bcb9281aea00f978 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[] = "|"; |
|
Marc Treib
2016/07/19 12:31:11
Can you make this an actual char, rather than a st
Philipp Keck
2016/07/19 13:02:37
Done.
|
| } // namespace |
| @@ -28,4 +30,25 @@ std::string ContentSuggestionsProvider::MakeUniqueID( |
| within_category_id.c_str()); |
| } |
| +ContentSuggestionsCategory ContentSuggestionsProvider::GetCategoryFromUniqueID( |
|
Marc Treib
2016/07/19 12:31:11
Add
// static
above, also for the other method bel
Philipp Keck
2016/07/19 13:02:38
Done.
|
| + 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; |
| + 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(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 |