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..2d7ea7ac1ae49d57ce58c7cbf2c6820869e8a1e9 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,9 @@ using content::BrowserThread; |
using history::HistoryService; |
using image_fetcher::ImageFetcherImpl; |
using ntp_snippets::BookmarkSuggestionsProvider; |
+using ntp_snippets::CategoryRanker; |
+using ntp_snippets::ClickBasedCategoryRanker; |
+using ntp_snippets::ConstantCategoryRanker; |
using ntp_snippets::ContentSuggestionsService; |
using ntp_snippets::ForeignSessionsSuggestionsProvider; |
using ntp_snippets::NTPSnippetsFetcher; |
@@ -198,6 +204,26 @@ void RegisterForeignSessionsProvider(SyncService* sync_service, |
service->RegisterProvider(std::move(provider)); |
} |
+std::unique_ptr<CategoryRanker> BuildCategoryRanker(PrefService* pref_service) { |
+ std::string category_ranker_parameter = variations::GetVariationParamValue( |
jkrcal
2016/12/22 10:06:01
Can you use variations::GetVariationParamValueByFe
vitaliii
2016/12/22 13:11:37
Done.
|
+ ntp_snippets::kStudyName, "category_ranker"); |
+ |
+ if (category_ranker_parameter.empty()) { |
+ // Default, Enabled or Disabled. |
+ return base::MakeUnique<ConstantCategoryRanker>(); |
+ } |
+ if (category_ranker_parameter == "constant") { |
jkrcal
2016/12/22 10:06:01
Do we need this option? I would have just
- Defa
tschumann
2016/12/22 10:31:26
i like the idea of using the strings in less place
vitaliii
2016/12/22 13:11:37
I think - yes.
1) I treat all of "Default", "Enab
vitaliii
2016/12/22 13:11:37
Done.
jkrcal
2016/12/22 13:39:15
Makes sense. Ack.
|
+ return base::MakeUnique<ConstantCategoryRanker>(); |
+ } |
+ if (category_ranker_parameter == "click_based") { |
+ return base::MakeUnique<ClickBasedCategoryRanker>(pref_service); |
+ } |
+ |
+ NOTREACHED() << "The category_ranker parameter value is " |
+ << category_ranker_parameter; |
+ return nullptr; |
+} |
+ |
} // namespace |
// static |
@@ -252,8 +278,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)); |