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" |
| 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 21 matching lines...) Expand all Loading... | |
| 32 #include "components/keyed_service/core/service_access_type.h" | 32 #include "components/keyed_service/core/service_access_type.h" |
| 33 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" | 33 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
| 34 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 34 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 35 #include "components/ntp_snippets/content_suggestions_service.h" | 35 #include "components/ntp_snippets/content_suggestions_service.h" |
| 36 #include "components/ntp_snippets/features.h" | 36 #include "components/ntp_snippets/features.h" |
| 37 #include "components/ntp_snippets/ntp_snippets_constants.h" | 37 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 38 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 38 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
| 39 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 39 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 40 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 40 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
| 41 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 41 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 42 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" | |
| 42 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 43 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
| 43 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider. h" | |
| 44 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" | 44 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" |
| 45 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" | 45 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" |
| 46 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
| 47 #include "components/safe_json/safe_json_parser.h" | 47 #include "components/safe_json/safe_json_parser.h" |
| 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 49 #include "components/signin/core/browser/signin_manager.h" | 49 #include "components/signin/core/browser/signin_manager.h" |
| 50 #include "components/translate/core/browser/language_model.h" | 50 #include "components/translate/core/browser/language_model.h" |
| 51 #include "components/version_info/version_info.h" | 51 #include "components/version_info/version_info.h" |
| 52 #include "content/public/browser/browser_context.h" | 52 #include "content/public/browser/browser_context.h" |
| 53 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 using image_fetcher::ImageFetcherImpl; | 88 using image_fetcher::ImageFetcherImpl; |
| 89 using ntp_snippets::BookmarkSuggestionsProvider; | 89 using ntp_snippets::BookmarkSuggestionsProvider; |
| 90 using ntp_snippets::CategoryRanker; | 90 using ntp_snippets::CategoryRanker; |
| 91 using ntp_snippets::ContentSuggestionsService; | 91 using ntp_snippets::ContentSuggestionsService; |
| 92 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 92 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
| 93 using ntp_snippets::GetFetchEndpoint; | 93 using ntp_snippets::GetFetchEndpoint; |
| 94 using ntp_snippets::PersistentScheduler; | 94 using ntp_snippets::PersistentScheduler; |
| 95 using ntp_snippets::RemoteSuggestionsDatabase; | 95 using ntp_snippets::RemoteSuggestionsDatabase; |
| 96 using ntp_snippets::RemoteSuggestionsFetcher; | 96 using ntp_snippets::RemoteSuggestionsFetcher; |
| 97 using ntp_snippets::RemoteSuggestionsProviderImpl; | 97 using ntp_snippets::RemoteSuggestionsProviderImpl; |
| 98 using ntp_snippets::RemoteSuggestionsSchedulerImpl; | |
| 98 using ntp_snippets::RemoteSuggestionsStatusService; | 99 using ntp_snippets::RemoteSuggestionsStatusService; |
| 99 using ntp_snippets::SchedulingRemoteSuggestionsProvider; | |
| 100 using ntp_snippets::TabDelegateSyncAdapter; | 100 using ntp_snippets::TabDelegateSyncAdapter; |
| 101 using suggestions::ImageDecoderImpl; | 101 using suggestions::ImageDecoderImpl; |
| 102 using syncer::SyncService; | 102 using syncer::SyncService; |
| 103 using translate::LanguageModel; | 103 using translate::LanguageModel; |
| 104 | 104 |
| 105 // For now, ContentSuggestionsService must only be instantiated on Android. | 105 // For now, ContentSuggestionsService must only be instantiated on Android. |
| 106 // See also crbug.com/688366. | 106 // See also crbug.com/688366. |
| 107 #if defined(OS_ANDROID) | 107 #if defined(OS_ANDROID) |
| 108 #define CONTENT_SUGGESTIONS_ENABLED 1 | 108 #define CONTENT_SUGGESTIONS_ENABLED 1 |
| 109 #else | 109 #else |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 service->user_classifier()); | 209 service->user_classifier()); |
| 210 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( | 210 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( |
| 211 service, pref_service, g_browser_process->GetApplicationLocale(), | 211 service, pref_service, g_browser_process->GetApplicationLocale(), |
| 212 service->category_ranker(), std::move(suggestions_fetcher), | 212 service->category_ranker(), std::move(suggestions_fetcher), |
| 213 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), | 213 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), |
| 214 request_context.get()), | 214 request_context.get()), |
| 215 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), | 215 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), |
| 216 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, | 216 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, |
| 217 pref_service)); | 217 pref_service)); |
| 218 | 218 |
| 219 PersistentScheduler* scheduler = nullptr; | 219 PersistentScheduler* persistent_scheduler = nullptr; |
| 220 #if defined(OS_ANDROID) | 220 #if defined(OS_ANDROID) |
| 221 scheduler = NTPSnippetsLauncher::Get(); | 221 persistent_scheduler = NTPSnippetsLauncher::Get(); |
| 222 #endif // OS_ANDROID | 222 #endif // OS_ANDROID |
| 223 | 223 |
| 224 RemoteSuggestionsProviderImpl* provider_raw = provider.get(); | 224 auto scheduler = base::MakeUnique<RemoteSuggestionsSchedulerImpl>( |
| 225 auto scheduling_provider = | 225 provider.get(), persistent_scheduler, service->user_classifier(), |
| 226 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( | 226 pref_service, g_browser_process->local_state(), |
| 227 service, std::move(provider), scheduler, service->user_classifier(), | 227 base::MakeUnique<base::DefaultClock>()); |
| 228 pref_service, g_browser_process->local_state(), | 228 provider->SetRemoteSuggestionsScheduler(scheduler.get()); |
| 229 base::MakeUnique<base::DefaultClock>()); | 229 service->set_remote_suggestions_provider(provider.get()); |
| 230 provider_raw->SetRemoteSuggestionsScheduler(scheduling_provider.get()); | 230 |
| 231 service->set_remote_suggestions_provider(scheduling_provider.get()); | 231 service->set_remote_suggestions_scheduler(std::move(scheduler)); |
|
Marc Treib
2017/03/23 16:41:15
Hm, the order of initialization is a bit convolute
tschumann
2017/03/23 17:38:27
Sounds good to me. Ownership is best expressed wit
jkrcal
2017/03/27 10:03:02
Done.
| |
| 232 service->set_remote_suggestions_scheduler(scheduling_provider.get()); | 232 service->RegisterProvider(std::move(provider)); |
| 233 service->RegisterProvider(std::move(scheduling_provider)); | |
| 234 } | 233 } |
| 235 | 234 |
| 236 void RegisterForeignSessionsProvider(SyncService* sync_service, | 235 void RegisterForeignSessionsProvider(SyncService* sync_service, |
| 237 ContentSuggestionsService* service, | 236 ContentSuggestionsService* service, |
| 238 PrefService* pref_service) { | 237 PrefService* pref_service) { |
| 239 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = | 238 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = |
| 240 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); | 239 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); |
| 241 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( | 240 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( |
| 242 service, std::move(sync_adapter), pref_service); | 241 service, std::move(sync_adapter), pref_service); |
| 243 service->RegisterProvider(std::move(provider)); | 242 service->RegisterProvider(std::move(provider)); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 365 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
| 367 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 366 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
| 368 } | 367 } |
| 369 | 368 |
| 370 return service; | 369 return service; |
| 371 | 370 |
| 372 #else | 371 #else |
| 373 return nullptr; | 372 return nullptr; |
| 374 #endif // CONTENT_SUGGESTIONS_ENABLED | 373 #endif // CONTENT_SUGGESTIONS_ENABLED |
| 375 } | 374 } |
| OLD | NEW |