Chromium Code Reviews| 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" |
|
jkrcal
2016/12/22 10:06:01
Can you the same changes for the iOS factory pleas
vitaliii
2016/12/22 13:11:37
Done.
However, I cannot prevent duplication of th
jkrcal
2016/12/22 13:39:15
That's okay, thanks!
| |
| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search/suggestions/image_decoder_impl.h" | 17 #include "chrome/browser/search/suggestions/image_decoder_impl.h" |
| 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 21 #include "chrome/browser/translate/language_model_factory.h" | 21 #include "chrome/browser/translate/language_model_factory.h" |
| 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::ClickBasedCategoryRanker; | |
| 84 using ntp_snippets::ConstantCategoryRanker; | |
| 79 using ntp_snippets::ContentSuggestionsService; | 85 using ntp_snippets::ContentSuggestionsService; |
| 80 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 86 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
| 81 using ntp_snippets::NTPSnippetsFetcher; | 87 using ntp_snippets::NTPSnippetsFetcher; |
| 82 using ntp_snippets::PersistentScheduler; | 88 using ntp_snippets::PersistentScheduler; |
| 83 using ntp_snippets::RemoteSuggestionsDatabase; | 89 using ntp_snippets::RemoteSuggestionsDatabase; |
| 84 using ntp_snippets::RemoteSuggestionsProviderImpl; | 90 using ntp_snippets::RemoteSuggestionsProviderImpl; |
| 85 using ntp_snippets::RemoteSuggestionsStatusService; | 91 using ntp_snippets::RemoteSuggestionsStatusService; |
| 86 using ntp_snippets::SchedulingRemoteSuggestionsProvider; | 92 using ntp_snippets::SchedulingRemoteSuggestionsProvider; |
| 87 using ntp_snippets::TabDelegateSyncAdapter; | 93 using ntp_snippets::TabDelegateSyncAdapter; |
| 88 using suggestions::ImageDecoderImpl; | 94 using suggestions::ImageDecoderImpl; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 void RegisterForeignSessionsProvider(SyncService* sync_service, | 197 void RegisterForeignSessionsProvider(SyncService* sync_service, |
| 192 ContentSuggestionsService* service, | 198 ContentSuggestionsService* service, |
| 193 PrefService* pref_service) { | 199 PrefService* pref_service) { |
| 194 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = | 200 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = |
| 195 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); | 201 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); |
| 196 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( | 202 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( |
| 197 service, std::move(sync_adapter), pref_service); | 203 service, std::move(sync_adapter), pref_service); |
| 198 service->RegisterProvider(std::move(provider)); | 204 service->RegisterProvider(std::move(provider)); |
| 199 } | 205 } |
| 200 | 206 |
| 207 std::unique_ptr<CategoryRanker> BuildCategoryRanker(PrefService* pref_service) { | |
| 208 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.
| |
| 209 ntp_snippets::kStudyName, "category_ranker"); | |
| 210 | |
| 211 if (category_ranker_parameter.empty()) { | |
| 212 // Default, Enabled or Disabled. | |
| 213 return base::MakeUnique<ConstantCategoryRanker>(); | |
| 214 } | |
| 215 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.
| |
| 216 return base::MakeUnique<ConstantCategoryRanker>(); | |
| 217 } | |
| 218 if (category_ranker_parameter == "click_based") { | |
| 219 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service); | |
| 220 } | |
| 221 | |
| 222 NOTREACHED() << "The category_ranker parameter value is " | |
| 223 << category_ranker_parameter; | |
| 224 return nullptr; | |
| 225 } | |
| 226 | |
| 201 } // namespace | 227 } // namespace |
| 202 | 228 |
| 203 // static | 229 // static |
| 204 ContentSuggestionsServiceFactory* | 230 ContentSuggestionsServiceFactory* |
| 205 ContentSuggestionsServiceFactory::GetInstance() { | 231 ContentSuggestionsServiceFactory::GetInstance() { |
| 206 return base::Singleton<ContentSuggestionsServiceFactory>::get(); | 232 return base::Singleton<ContentSuggestionsServiceFactory>::get(); |
| 207 } | 233 } |
| 208 | 234 |
| 209 // static | 235 // static |
| 210 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( | 236 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 // Create the ContentSuggestionsService. | 271 // Create the ContentSuggestionsService. |
| 246 State state = | 272 State state = |
| 247 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) | 273 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) |
| 248 ? State::ENABLED | 274 ? State::ENABLED |
| 249 : State::DISABLED; | 275 : State::DISABLED; |
| 250 SigninManagerBase* signin_manager = | 276 SigninManagerBase* signin_manager = |
| 251 SigninManagerFactory::GetForProfile(profile); | 277 SigninManagerFactory::GetForProfile(profile); |
| 252 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 278 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 253 profile, ServiceAccessType::EXPLICIT_ACCESS); | 279 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 254 PrefService* pref_service = profile->GetPrefs(); | 280 PrefService* pref_service = profile->GetPrefs(); |
| 255 auto category_ranker = | 281 std::unique_ptr<CategoryRanker> category_ranker = |
| 256 base::MakeUnique<ntp_snippets::ConstantCategoryRanker>(); | 282 BuildCategoryRanker(pref_service); |
| 257 auto* service = | 283 auto* service = |
| 258 new ContentSuggestionsService(state, signin_manager, history_service, | 284 new ContentSuggestionsService(state, signin_manager, history_service, |
| 259 pref_service, std::move(category_ranker)); | 285 pref_service, std::move(category_ranker)); |
| 260 if (state == State::DISABLED) { | 286 if (state == State::DISABLED) { |
| 261 // Since we won't initialise the services, they won't get a chance to | 287 // Since we won't initialise the services, they won't get a chance to |
| 262 // unschedule their tasks. We do it explicitly here instead. | 288 // unschedule their tasks. We do it explicitly here instead. |
| 263 ClearScheduledTasks(); | 289 ClearScheduledTasks(); |
| 264 return service; | 290 return service; |
| 265 } | 291 } |
| 266 | 292 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 language_model, pref_service, profile); | 344 language_model, pref_service, profile); |
| 319 } | 345 } |
| 320 | 346 |
| 321 if (base::FeatureList::IsEnabled( | 347 if (base::FeatureList::IsEnabled( |
| 322 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 348 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
| 323 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 349 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
| 324 } | 350 } |
| 325 | 351 |
| 326 return service; | 352 return service; |
| 327 } | 353 } |
| OLD | NEW |