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

Side by Side Diff: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc

Issue 2595883002: [NTP::SectionOrder] Add a flag to choose 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" 5 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/common/channel_info.h" 22 #include "chrome/common/channel_info.h"
23 #include "chrome/common/chrome_features.h" 23 #include "chrome/common/chrome_features.h"
24 #include "components/bookmarks/browser/bookmark_model.h" 24 #include "components/bookmarks/browser/bookmark_model.h"
25 #include "components/browser_sync/profile_sync_service.h" 25 #include "components/browser_sync/profile_sync_service.h"
26 #include "components/image_fetcher/image_decoder.h" 26 #include "components/image_fetcher/image_decoder.h"
27 #include "components/image_fetcher/image_fetcher.h" 27 #include "components/image_fetcher/image_fetcher.h"
28 #include "components/image_fetcher/image_fetcher_impl.h" 28 #include "components/image_fetcher/image_fetcher_impl.h"
29 #include "components/keyed_service/content/browser_context_dependency_manager.h" 29 #include "components/keyed_service/content/browser_context_dependency_manager.h"
30 #include "components/keyed_service/core/service_access_type.h" 30 #include "components/keyed_service/core/service_access_type.h"
31 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" 31 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
32 #include "components/ntp_snippets/category_rankers/category_ranker.h"
33 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h "
32 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" 34 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
33 #include "components/ntp_snippets/content_suggestions_service.h" 35 #include "components/ntp_snippets/content_suggestions_service.h"
34 #include "components/ntp_snippets/features.h" 36 #include "components/ntp_snippets/features.h"
35 #include "components/ntp_snippets/ntp_snippets_constants.h" 37 #include "components/ntp_snippets/ntp_snippets_constants.h"
36 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" 38 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
37 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" 39 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h"
38 #include "components/ntp_snippets/remote/remote_suggestions_database.h" 40 #include "components/ntp_snippets/remote/remote_suggestions_database.h"
39 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 41 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
40 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" 42 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h"
41 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" 43 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h"
42 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" 44 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h"
43 #include "components/prefs/pref_service.h" 45 #include "components/prefs/pref_service.h"
44 #include "components/safe_json/safe_json_parser.h" 46 #include "components/safe_json/safe_json_parser.h"
45 #include "components/signin/core/browser/profile_oauth2_token_service.h" 47 #include "components/signin/core/browser/profile_oauth2_token_service.h"
46 #include "components/signin/core/browser/signin_manager.h" 48 #include "components/signin/core/browser/signin_manager.h"
47 #include "components/translate/core/browser/language_model.h" 49 #include "components/translate/core/browser/language_model.h"
50 #include "components/variations/variations_associated_data.h"
48 #include "components/version_info/version_info.h" 51 #include "components/version_info/version_info.h"
49 #include "content/public/browser/browser_context.h" 52 #include "content/public/browser/browser_context.h"
50 #include "content/public/browser/browser_thread.h" 53 #include "content/public/browser/browser_thread.h"
51 #include "content/public/browser/storage_partition.h" 54 #include "content/public/browser/storage_partition.h"
52 #include "google_apis/google_api_keys.h" 55 #include "google_apis/google_api_keys.h"
53 #include "net/url_request/url_request_context_getter.h" 56 #include "net/url_request/url_request_context_getter.h"
54 57
55 #if defined(OS_ANDROID) 58 #if defined(OS_ANDROID)
56 #include "chrome/browser/android/chrome_feature_list.h" 59 #include "chrome/browser/android/chrome_feature_list.h"
57 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" 60 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h"
(...skipping 10 matching lines...) Expand all
68 using offline_pages::OfflinePageModel; 71 using offline_pages::OfflinePageModel;
69 using offline_pages::OfflinePageModelFactory; 72 using offline_pages::OfflinePageModelFactory;
70 using physical_web::PhysicalWebDataSource; 73 using physical_web::PhysicalWebDataSource;
71 #endif // OS_ANDROID 74 #endif // OS_ANDROID
72 75
73 using bookmarks::BookmarkModel; 76 using bookmarks::BookmarkModel;
74 using content::BrowserThread; 77 using content::BrowserThread;
75 using history::HistoryService; 78 using history::HistoryService;
76 using image_fetcher::ImageFetcherImpl; 79 using image_fetcher::ImageFetcherImpl;
77 using ntp_snippets::BookmarkSuggestionsProvider; 80 using ntp_snippets::BookmarkSuggestionsProvider;
81 using ntp_snippets::CategoryRanker;
82 using ntp_snippets::ClickBasedCategoryRanker;
83 using ntp_snippets::ConstantCategoryRanker;
78 using ntp_snippets::ContentSuggestionsService; 84 using ntp_snippets::ContentSuggestionsService;
79 using ntp_snippets::ForeignSessionsSuggestionsProvider; 85 using ntp_snippets::ForeignSessionsSuggestionsProvider;
80 using ntp_snippets::NTPSnippetsFetcher; 86 using ntp_snippets::NTPSnippetsFetcher;
81 using ntp_snippets::NTPSnippetsScheduler; 87 using ntp_snippets::NTPSnippetsScheduler;
82 using ntp_snippets::RemoteSuggestionsDatabase; 88 using ntp_snippets::RemoteSuggestionsDatabase;
83 using ntp_snippets::RemoteSuggestionsProvider; 89 using ntp_snippets::RemoteSuggestionsProvider;
84 using ntp_snippets::RemoteSuggestionsStatusService; 90 using ntp_snippets::RemoteSuggestionsStatusService;
85 using ntp_snippets::TabDelegateSyncAdapter; 91 using ntp_snippets::TabDelegateSyncAdapter;
86 using suggestions::ImageDecoderImpl; 92 using suggestions::ImageDecoderImpl;
87 using syncer::SyncService; 93 using syncer::SyncService;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 void RegisterForeignSessionsProvider(SyncService* sync_service, 188 void RegisterForeignSessionsProvider(SyncService* sync_service,
183 ContentSuggestionsService* service, 189 ContentSuggestionsService* service,
184 PrefService* pref_service) { 190 PrefService* pref_service) {
185 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 191 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
186 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 192 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
187 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( 193 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>(
188 service, std::move(sync_adapter), pref_service); 194 service, std::move(sync_adapter), pref_service);
189 service->RegisterProvider(std::move(provider)); 195 service->RegisterProvider(std::move(provider));
190 } 196 }
191 197
198 std::unique_ptr<CategoryRanker> BuildCategoryRanker(PrefService* pref_service) {
199 std::string category_ranker_parameter = variations::GetVariationParamValue(
200 ntp_snippets::kStudyName, "category_ranker");
201
202 if (category_ranker_parameter.empty()) {
203 // Default, Enabled or Disabled.
204 return base::MakeUnique<ConstantCategoryRanker>();
205 }
206 if (category_ranker_parameter == "constant") {
207 return base::MakeUnique<ConstantCategoryRanker>();
208 }
209 if (category_ranker_parameter == "click_based") {
210 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service);
211 }
212
213 NOTREACHED() << "The category_ranker parameter value is "
214 << category_ranker_parameter;
215 return nullptr;
216 }
217
192 } // namespace 218 } // namespace
193 219
194 // static 220 // static
195 ContentSuggestionsServiceFactory* 221 ContentSuggestionsServiceFactory*
196 ContentSuggestionsServiceFactory::GetInstance() { 222 ContentSuggestionsServiceFactory::GetInstance() {
197 return base::Singleton<ContentSuggestionsServiceFactory>::get(); 223 return base::Singleton<ContentSuggestionsServiceFactory>::get();
198 } 224 }
199 225
200 // static 226 // static
201 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( 227 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // Create the ContentSuggestionsService. 262 // Create the ContentSuggestionsService.
237 State state = 263 State state =
238 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) 264 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature)
239 ? State::ENABLED 265 ? State::ENABLED
240 : State::DISABLED; 266 : State::DISABLED;
241 SigninManagerBase* signin_manager = 267 SigninManagerBase* signin_manager =
242 SigninManagerFactory::GetForProfile(profile); 268 SigninManagerFactory::GetForProfile(profile);
243 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 269 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
244 profile, ServiceAccessType::EXPLICIT_ACCESS); 270 profile, ServiceAccessType::EXPLICIT_ACCESS);
245 PrefService* pref_service = profile->GetPrefs(); 271 PrefService* pref_service = profile->GetPrefs();
246 auto category_ranker = 272 std::unique_ptr<CategoryRanker> category_ranker =
247 base::MakeUnique<ntp_snippets::ConstantCategoryRanker>(); 273 BuildCategoryRanker(pref_service);
248 auto* service = 274 auto* service =
249 new ContentSuggestionsService(state, signin_manager, history_service, 275 new ContentSuggestionsService(state, signin_manager, history_service,
250 pref_service, std::move(category_ranker)); 276 pref_service, std::move(category_ranker));
251 if (state == State::DISABLED) { 277 if (state == State::DISABLED) {
252 // Since we won't initialise the services, they won't get a chance to 278 // Since we won't initialise the services, they won't get a chance to
253 // unschedule their tasks. We do it explicitly here instead. 279 // unschedule their tasks. We do it explicitly here instead.
254 ClearScheduledTasks(); 280 ClearScheduledTasks();
255 return service; 281 return service;
256 } 282 }
257 283
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 language_model, pref_service, profile); 335 language_model, pref_service, profile);
310 } 336 }
311 337
312 if (base::FeatureList::IsEnabled( 338 if (base::FeatureList::IsEnabled(
313 ntp_snippets::kForeignSessionsSuggestionsFeature)) { 339 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
314 RegisterForeignSessionsProvider(sync_service, service, pref_service); 340 RegisterForeignSessionsProvider(sync_service, service, pref_service);
315 } 341 }
316 342
317 return service; 343 return service;
318 } 344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698