Index: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc |
diff --git a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc |
index d065de4d250d36d8efd9be9dead54f0f974f21d7..2d557411b5fd645124a26e3ba30b06ba1e64d25f 100644 |
--- a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc |
+++ b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc |
@@ -29,6 +29,8 @@ |
#include "components/keyed_service/content/browser_context_dependency_manager.h" |
#include "components/keyed_service/core/service_access_type.h" |
#include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
+#include "components/ntp_snippets/category_rankers/category_ranker.h" |
+#include "components/ntp_snippets/category_rankers/click_based_category_ranker.h" |
#include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
#include "components/ntp_snippets/content_suggestions_service.h" |
#include "components/ntp_snippets/features.h" |
@@ -46,6 +48,7 @@ |
#include "components/signin/core/browser/profile_oauth2_token_service.h" |
#include "components/signin/core/browser/signin_manager.h" |
#include "components/translate/core/browser/language_model.h" |
+#include "components/variations/variations_associated_data.h" |
#include "components/version_info/version_info.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
@@ -76,6 +79,10 @@ using content::BrowserThread; |
using history::HistoryService; |
using image_fetcher::ImageFetcherImpl; |
using ntp_snippets::BookmarkSuggestionsProvider; |
+using ntp_snippets::CategoryRanker; |
+using ntp_snippets::CategoryRankerChoice; |
+using ntp_snippets::ClickBasedCategoryRanker; |
+using ntp_snippets::ConstantCategoryRanker; |
using ntp_snippets::ContentSuggestionsService; |
using ntp_snippets::ForeignSessionsSuggestionsProvider; |
using ntp_snippets::NTPSnippetsFetcher; |
@@ -198,6 +205,20 @@ void RegisterForeignSessionsProvider(SyncService* sync_service, |
service->RegisterProvider(std::move(provider)); |
} |
+std::unique_ptr<CategoryRanker> BuildCategoryRanker(PrefService* pref_service) { |
+ CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker(); |
+ switch (choice) { |
+ case CategoryRankerChoice::CONSTANT: |
+ return base::MakeUnique<ConstantCategoryRanker>(); |
+ case CategoryRankerChoice::CLICK_BASED: |
+ return base::MakeUnique<ClickBasedCategoryRanker>(pref_service); |
+ default: |
+ NOTREACHED() << "The category ranker choice value is " |
+ << static_cast<int>(choice); |
+ } |
+ return nullptr; |
+} |
+ |
} // namespace |
// static |
@@ -252,8 +273,8 @@ KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( |
HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
profile, ServiceAccessType::EXPLICIT_ACCESS); |
PrefService* pref_service = profile->GetPrefs(); |
- auto category_ranker = |
- base::MakeUnique<ntp_snippets::ConstantCategoryRanker>(); |
+ std::unique_ptr<CategoryRanker> category_ranker = |
+ BuildCategoryRanker(pref_service); |
auto* service = |
new ContentSuggestionsService(state, signin_manager, history_service, |
pref_service, std::move(category_ranker)); |