OLD | NEW |
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 Loading... |
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/persistent_scheduler.h" | 39 #include "components/ntp_snippets/remote/persistent_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_impl.h" | 41 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.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/remote/scheduling_remote_suggestions_provider.
h" | 43 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider.
h" |
42 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" | 44 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" |
43 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" | 45 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" |
44 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
45 #include "components/safe_json/safe_json_parser.h" | 47 #include "components/safe_json/safe_json_parser.h" |
46 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
47 #include "components/signin/core/browser/signin_manager.h" | 49 #include "components/signin/core/browser/signin_manager.h" |
48 #include "components/translate/core/browser/language_model.h" | 50 #include "components/translate/core/browser/language_model.h" |
| 51 #include "components/variations/variations_associated_data.h" |
49 #include "components/version_info/version_info.h" | 52 #include "components/version_info/version_info.h" |
50 #include "content/public/browser/browser_context.h" | 53 #include "content/public/browser/browser_context.h" |
51 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
52 #include "content/public/browser/storage_partition.h" | 55 #include "content/public/browser/storage_partition.h" |
53 #include "google_apis/google_api_keys.h" | 56 #include "google_apis/google_api_keys.h" |
54 #include "net/url_request/url_request_context_getter.h" | 57 #include "net/url_request/url_request_context_getter.h" |
55 | 58 |
56 #if defined(OS_ANDROID) | 59 #if defined(OS_ANDROID) |
57 #include "chrome/browser/android/chrome_feature_list.h" | 60 #include "chrome/browser/android/chrome_feature_list.h" |
58 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" | 61 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" |
(...skipping 10 matching lines...) Expand all Loading... |
69 using offline_pages::OfflinePageModel; | 72 using offline_pages::OfflinePageModel; |
70 using offline_pages::OfflinePageModelFactory; | 73 using offline_pages::OfflinePageModelFactory; |
71 using physical_web::PhysicalWebDataSource; | 74 using physical_web::PhysicalWebDataSource; |
72 #endif // OS_ANDROID | 75 #endif // OS_ANDROID |
73 | 76 |
74 using bookmarks::BookmarkModel; | 77 using bookmarks::BookmarkModel; |
75 using content::BrowserThread; | 78 using content::BrowserThread; |
76 using history::HistoryService; | 79 using history::HistoryService; |
77 using image_fetcher::ImageFetcherImpl; | 80 using image_fetcher::ImageFetcherImpl; |
78 using ntp_snippets::BookmarkSuggestionsProvider; | 81 using ntp_snippets::BookmarkSuggestionsProvider; |
| 82 using ntp_snippets::CategoryRanker; |
| 83 using ntp_snippets::CategoryRankerChoice; |
| 84 using ntp_snippets::ClickBasedCategoryRanker; |
| 85 using ntp_snippets::ConstantCategoryRanker; |
79 using ntp_snippets::ContentSuggestionsService; | 86 using ntp_snippets::ContentSuggestionsService; |
80 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 87 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
81 using ntp_snippets::NTPSnippetsFetcher; | 88 using ntp_snippets::NTPSnippetsFetcher; |
82 using ntp_snippets::PersistentScheduler; | 89 using ntp_snippets::PersistentScheduler; |
83 using ntp_snippets::RemoteSuggestionsDatabase; | 90 using ntp_snippets::RemoteSuggestionsDatabase; |
84 using ntp_snippets::RemoteSuggestionsProviderImpl; | 91 using ntp_snippets::RemoteSuggestionsProviderImpl; |
85 using ntp_snippets::RemoteSuggestionsStatusService; | 92 using ntp_snippets::RemoteSuggestionsStatusService; |
86 using ntp_snippets::SchedulingRemoteSuggestionsProvider; | 93 using ntp_snippets::SchedulingRemoteSuggestionsProvider; |
87 using ntp_snippets::TabDelegateSyncAdapter; | 94 using ntp_snippets::TabDelegateSyncAdapter; |
88 using suggestions::ImageDecoderImpl; | 95 using suggestions::ImageDecoderImpl; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void RegisterForeignSessionsProvider(SyncService* sync_service, | 198 void RegisterForeignSessionsProvider(SyncService* sync_service, |
192 ContentSuggestionsService* service, | 199 ContentSuggestionsService* service, |
193 PrefService* pref_service) { | 200 PrefService* pref_service) { |
194 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = | 201 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = |
195 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); | 202 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); |
196 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( | 203 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( |
197 service, std::move(sync_adapter), pref_service); | 204 service, std::move(sync_adapter), pref_service); |
198 service->RegisterProvider(std::move(provider)); | 205 service->RegisterProvider(std::move(provider)); |
199 } | 206 } |
200 | 207 |
| 208 std::unique_ptr<CategoryRanker> BuildCategoryRanker(PrefService* pref_service) { |
| 209 CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker(); |
| 210 switch (choice) { |
| 211 case CategoryRankerChoice::CONSTANT: |
| 212 return base::MakeUnique<ConstantCategoryRanker>(); |
| 213 case CategoryRankerChoice::CLICK_BASED: |
| 214 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service); |
| 215 default: |
| 216 NOTREACHED() << "The category ranker choice value is " |
| 217 << static_cast<int>(choice); |
| 218 } |
| 219 return nullptr; |
| 220 } |
| 221 |
201 } // namespace | 222 } // namespace |
202 | 223 |
203 // static | 224 // static |
204 ContentSuggestionsServiceFactory* | 225 ContentSuggestionsServiceFactory* |
205 ContentSuggestionsServiceFactory::GetInstance() { | 226 ContentSuggestionsServiceFactory::GetInstance() { |
206 return base::Singleton<ContentSuggestionsServiceFactory>::get(); | 227 return base::Singleton<ContentSuggestionsServiceFactory>::get(); |
207 } | 228 } |
208 | 229 |
209 // static | 230 // static |
210 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( | 231 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // Create the ContentSuggestionsService. | 266 // Create the ContentSuggestionsService. |
246 State state = | 267 State state = |
247 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) | 268 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) |
248 ? State::ENABLED | 269 ? State::ENABLED |
249 : State::DISABLED; | 270 : State::DISABLED; |
250 SigninManagerBase* signin_manager = | 271 SigninManagerBase* signin_manager = |
251 SigninManagerFactory::GetForProfile(profile); | 272 SigninManagerFactory::GetForProfile(profile); |
252 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 273 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
253 profile, ServiceAccessType::EXPLICIT_ACCESS); | 274 profile, ServiceAccessType::EXPLICIT_ACCESS); |
254 PrefService* pref_service = profile->GetPrefs(); | 275 PrefService* pref_service = profile->GetPrefs(); |
255 auto category_ranker = | 276 std::unique_ptr<CategoryRanker> category_ranker = |
256 base::MakeUnique<ntp_snippets::ConstantCategoryRanker>(); | 277 BuildCategoryRanker(pref_service); |
257 auto* service = | 278 auto* service = |
258 new ContentSuggestionsService(state, signin_manager, history_service, | 279 new ContentSuggestionsService(state, signin_manager, history_service, |
259 pref_service, std::move(category_ranker)); | 280 pref_service, std::move(category_ranker)); |
260 if (state == State::DISABLED) { | 281 if (state == State::DISABLED) { |
261 // Since we won't initialise the services, they won't get a chance to | 282 // Since we won't initialise the services, they won't get a chance to |
262 // unschedule their tasks. We do it explicitly here instead. | 283 // unschedule their tasks. We do it explicitly here instead. |
263 ClearScheduledTasks(); | 284 ClearScheduledTasks(); |
264 return service; | 285 return service; |
265 } | 286 } |
266 | 287 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 language_model, pref_service, profile); | 339 language_model, pref_service, profile); |
319 } | 340 } |
320 | 341 |
321 if (base::FeatureList::IsEnabled( | 342 if (base::FeatureList::IsEnabled( |
322 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 343 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
323 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 344 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
324 } | 345 } |
325 | 346 |
326 return service; | 347 return service; |
327 } | 348 } |
OLD | NEW |