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

Unified Diff: components/ntp_snippets/remote/remote_suggestions_provider.cc

Issue 2568033005: [NTP::SectionOrder] Replace CategoryFactory with a category ranker. (Closed)
Patch Set: Created 4 years 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/remote/remote_suggestions_provider.cc
diff --git a/components/ntp_snippets/remote/remote_suggestions_provider.cc b/components/ntp_snippets/remote/remote_suggestions_provider.cc
index 4ff354f6b697750382057030828db4b3d856afab..c35e680ea6a7d4ec3eaaf7d1b5cb8c62fea984bf 100644
--- a/components/ntp_snippets/remote/remote_suggestions_provider.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_provider.cc
@@ -29,6 +29,7 @@
#include "components/ntp_snippets/features.h"
#include "components/ntp_snippets/pref_names.h"
#include "components/ntp_snippets/remote/remote_suggestions_database.h"
+#include "components/ntp_snippets/section_rankers/section_ranker.h"
#include "components/ntp_snippets/switches.h"
#include "components/ntp_snippets/user_classifier.h"
#include "components/prefs/pref_registry_simple.h"
@@ -223,9 +224,9 @@ void CallWithEmptyResults(const FetchDoneCallback& callback,
RemoteSuggestionsProvider::RemoteSuggestionsProvider(
Observer* observer,
- CategoryFactory* category_factory,
PrefService* pref_service,
const std::string& application_language_code,
+ SectionRanker* section_ranker,
const UserClassifier* user_classifier,
NTPSnippetsScheduler* scheduler,
std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher,
@@ -233,12 +234,13 @@ RemoteSuggestionsProvider::RemoteSuggestionsProvider(
std::unique_ptr<image_fetcher::ImageDecoder> image_decoder,
std::unique_ptr<RemoteSuggestionsDatabase> database,
std::unique_ptr<RemoteSuggestionsStatusService> status_service)
- : ContentSuggestionsProvider(observer, category_factory),
+ : ContentSuggestionsProvider(observer),
state_(State::NOT_INITED),
pref_service_(pref_service),
articles_category_(
- category_factory->FromKnownCategory(KnownCategories::ARTICLES)),
+ Category::FromKnownCategory(KnownCategories::ARTICLES)),
application_language_code_(application_language_code),
+ section_ranker_(section_ranker),
user_classifier_(user_classifier),
scheduler_(scheduler),
snippets_fetcher_(std::move(snippets_fetcher)),
@@ -597,7 +599,10 @@ void RemoteSuggestionsProvider::OnDatabaseLoaded(
NTPSnippet::PtrVector to_delete;
for (std::unique_ptr<NTPSnippet>& snippet : snippets) {
Category snippet_category =
- category_factory()->FromRemoteCategory(snippet->remote_category_id());
+ Category::FromRemoteCategory(snippet->remote_category_id());
+ // The category is added to the ranker to enforce the order among remote
+ // categories.
+ section_ranker_->AppendCategoryIfNecessary(snippet_category);
Marc Treib 2016/12/13 12:22:42 Hm. This is one downside of the new design: Before
vitaliii 2016/12/14 08:59:38 Currently all non-registered categories are in the
Marc Treib 2016/12/14 10:24:30 Should it be some kind of error if someone tries t
tschumann 2016/12/15 13:05:20 We need to clearly handle the cases where a catego
vitaliii 2016/12/15 15:30:12 There are 2 places actually (the database does not
vitaliii 2016/12/15 15:30:12 Done. I do not understand why you are concerned a
tschumann 2016/12/15 18:23:13 Well, but when we start-up and load the categories
vitaliii 2016/12/16 08:15:43 Of course. We do this already in RemoteSuggestions
auto content_it = category_contents_.find(snippet_category);
// We should already know about the category.
if (content_it == category_contents_.end()) {
@@ -1291,7 +1296,9 @@ void RemoteSuggestionsProvider::RestoreCategoriesFromPrefs() {
dict->GetBoolean(kCategoryContentAllowFetchingMore,
&allow_fetching_more_results);
- Category category = category_factory()->FromIDValue(id);
+ Category category = Category::FromIDValue(id);
+ // The ranker may not persist the order of remote categories.
+ section_ranker_->AppendCategoryIfNecessary(category);
// TODO(tschumann): The following has a bad smell that category
// serialization / deserialization should not be done inside this
// class. We should move that into a central place that also knows how to
@@ -1312,12 +1319,11 @@ void RemoteSuggestionsProvider::StoreCategoriesToPrefs() {
for (const auto& entry : category_contents_) {
to_store.emplace_back(entry.first, &entry.second);
}
- // Sort them into the proper category order.
+ // The ranker may not persist the order, thus, it is stored by the provider.
Marc Treib 2016/12/13 12:22:42 Hm. Makes sense, but this is quite subtle. Do we h
vitaliii 2016/12/14 08:59:38 Done. We did not have a test for this (actually,
Marc Treib 2016/12/14 10:24:30 What exactly do you think didn't work before?
vitaliii 2016/12/15 15:30:12 I thought that remote categories were not register
tschumann 2016/12/15 18:23:13 another reason to consolidate that logic in a more
vitaliii 2016/12/16 08:15:43 Acknowledged.
std::sort(to_store.begin(), to_store.end(),
[this](const std::pair<Category, const CategoryContent*>& left,
const std::pair<Category, const CategoryContent*>& right) {
- return category_factory()->CompareCategories(left.first,
- right.first);
+ return section_ranker_->Compare(left.first, right.first);
});
// Convert the relevant info into a base::ListValue for storage.
base::ListValue list;

Powered by Google App Engine
This is Rietveld 408576698