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

Unified Diff: components/ntp_snippets/content_suggestions_provider.cc

Issue 2187233002: Add ContentSuggestionsCategoryFactory; Store categories as ints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 07947b860c71626564605cf121a2ececea7428b6..532c6fa53e0fb9e17ed2f6e32762fef336f69d63 100644
--- a/components/ntp_snippets/content_suggestions_provider.cc
+++ b/components/ntp_snippets/content_suggestions_provider.cc
@@ -6,6 +6,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
+#include "components/ntp_snippets/content_suggestions_category_factory.h"
namespace ntp_snippets {
@@ -17,21 +18,18 @@ const char kSeparator = '|';
} // namespace
ContentSuggestionsProvider::ContentSuggestionsProvider(
- const std::vector<ContentSuggestionsCategory>& provided_categories)
- : provided_categories_(provided_categories) {}
+ ContentSuggestionsCategoryFactory* category_factory)
+ : category_factory_(category_factory) {}
ContentSuggestionsProvider::~ContentSuggestionsProvider() {}
-// static
std::string ContentSuggestionsProvider::MakeUniqueID(
ContentSuggestionsCategory category,
const std::string& within_category_id) {
- return base::StringPrintf(kCombinedIDFormat,
- static_cast<int>(category),
+ return base::StringPrintf(kCombinedIDFormat, category.id(),
within_category_id.c_str());
}
-// static
ContentSuggestionsCategory ContentSuggestionsProvider::GetCategoryFromUniqueID(
const std::string& unique_id) {
size_t colon_index = unique_id.find(kSeparator);
@@ -40,12 +38,9 @@ ContentSuggestionsCategory ContentSuggestionsProvider::GetCategoryFromUniqueID(
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);
+ return category_factory_->FromIDValue(category);
}
-// static
std::string ContentSuggestionsProvider::GetWithinCategoryIDFromUniqueID(
const std::string& unique_id) {
size_t colon_index = unique_id.find(kSeparator);
« no previous file with comments | « components/ntp_snippets/content_suggestions_provider.h ('k') | components/ntp_snippets/content_suggestions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698