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

Unified Diff: components/ntp_snippets/content_suggestions_provider.cc

Issue 2355393002: New snippets now replace old snippets and do not merge (Closed)
Patch Set: Marc's comments Created 4 years, 3 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 dd8b88339a71e7fcc8c76dae647a167587c5b385..67b97d802ffef4ae0e244cc9148dc25ad492a3d3 100644
--- a/components/ntp_snippets/content_suggestions_provider.cc
+++ b/components/ntp_snippets/content_suggestions_provider.cc
@@ -4,19 +4,10 @@
#include "components/ntp_snippets/content_suggestions_provider.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/stringprintf.h"
#include "components/ntp_snippets/category_factory.h"
namespace ntp_snippets {
-namespace {
-
-const char kCombinedIDFormat[] = "%d|%s";
-const char kSeparator = '|';
-
-} // namespace
-
ContentSuggestionsProvider::ContentSuggestionsProvider(
Observer* observer,
CategoryFactory* category_factory)
@@ -27,27 +18,17 @@ ContentSuggestionsProvider::~ContentSuggestionsProvider() {}
std::string ContentSuggestionsProvider::MakeUniqueID(
Category category,
const std::string& within_category_id) const {
- return base::StringPrintf(kCombinedIDFormat, category.id(),
- within_category_id.c_str());
+ return category_factory()->MakeUniqueID(category, within_category_id);
}
Category ContentSuggestionsProvider::GetCategoryFromUniqueID(
const std::string& unique_id) const {
- 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;
- bool ret = base::StringToInt(unique_id.substr(0, colon_index), &category);
- DCHECK(ret) << "Non-numeric category part in unique_id: " << unique_id;
- return category_factory_->FromIDValue(category);
+ return category_factory()->GetCategoryFromUniqueID(unique_id);
}
std::string ContentSuggestionsProvider::GetWithinCategoryIDFromUniqueID(
const std::string& unique_id) const {
- 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);
+ return category_factory()->GetWithinCategoryIDFromUniqueID(unique_id);
}
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698