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> | |
| 8 | |
| 7 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search/suggestions/image_decoder_impl.h" | 17 #include "chrome/browser/search/suggestions/image_decoder_impl.h" |
| 16 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" | 18 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 19 #include "chrome/common/channel_info.h" | 22 #include "chrome/common/channel_info.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 23 #include "components/bookmarks/browser/bookmark_model.h" |
| 24 #include "components/browser_sync/browser/profile_sync_service.h" | |
| 21 #include "components/image_fetcher/image_decoder.h" | 25 #include "components/image_fetcher/image_decoder.h" |
| 22 #include "components/image_fetcher/image_fetcher.h" | 26 #include "components/image_fetcher/image_fetcher.h" |
| 23 #include "components/image_fetcher/image_fetcher_impl.h" | 27 #include "components/image_fetcher/image_fetcher_impl.h" |
| 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 28 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 25 #include "components/keyed_service/core/service_access_type.h" | 29 #include "components/keyed_service/core/service_access_type.h" |
| 26 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" | 30 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
| 27 #include "components/ntp_snippets/category_factory.h" | 31 #include "components/ntp_snippets/category_factory.h" |
| 28 #include "components/ntp_snippets/content_suggestions_service.h" | 32 #include "components/ntp_snippets/content_suggestions_service.h" |
| 29 #include "components/ntp_snippets/features.h" | 33 #include "components/ntp_snippets/features.h" |
| 30 #include "components/ntp_snippets/ntp_snippets_constants.h" | 34 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 31 #include "components/ntp_snippets/ntp_snippets_database.h" | 35 #include "components/ntp_snippets/ntp_snippets_database.h" |
| 32 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 36 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 33 #include "components/ntp_snippets/ntp_snippets_scheduler.h" | 37 #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
| 34 #include "components/ntp_snippets/ntp_snippets_service.h" | 38 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 35 #include "components/ntp_snippets/ntp_snippets_status_service.h" | 39 #include "components/ntp_snippets/ntp_snippets_status_service.h" |
| 40 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" | |
| 36 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
| 37 #include "components/safe_json/safe_json_parser.h" | 42 #include "components/safe_json/safe_json_parser.h" |
| 38 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 43 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 39 #include "components/signin/core/browser/signin_manager.h" | 44 #include "components/signin/core/browser/signin_manager.h" |
| 40 #include "components/version_info/version_info.h" | 45 #include "components/version_info/version_info.h" |
| 41 #include "content/public/browser/browser_context.h" | 46 #include "content/public/browser/browser_context.h" |
| 42 #include "content/public/browser/browser_thread.h" | 47 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/storage_partition.h" | 48 #include "content/public/browser/storage_partition.h" |
| 44 #include "net/url_request/url_request_context_getter.h" | 49 #include "net/url_request/url_request_context_getter.h" |
| 45 | 50 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 62 using history::HistoryService; | 67 using history::HistoryService; |
| 63 using image_fetcher::ImageFetcherImpl; | 68 using image_fetcher::ImageFetcherImpl; |
| 64 using ntp_snippets::BookmarkSuggestionsProvider; | 69 using ntp_snippets::BookmarkSuggestionsProvider; |
| 65 using ntp_snippets::CategoryFactory; | 70 using ntp_snippets::CategoryFactory; |
| 66 using ntp_snippets::ContentSuggestionsService; | 71 using ntp_snippets::ContentSuggestionsService; |
| 67 using ntp_snippets::NTPSnippetsDatabase; | 72 using ntp_snippets::NTPSnippetsDatabase; |
| 68 using ntp_snippets::NTPSnippetsFetcher; | 73 using ntp_snippets::NTPSnippetsFetcher; |
| 69 using ntp_snippets::NTPSnippetsService; | 74 using ntp_snippets::NTPSnippetsService; |
| 70 using ntp_snippets::NTPSnippetsScheduler; | 75 using ntp_snippets::NTPSnippetsScheduler; |
| 71 using ntp_snippets::NTPSnippetsStatusService; | 76 using ntp_snippets::NTPSnippetsStatusService; |
| 77 using ntp_snippets::ForeignSessionsSuggestionsProvider; | |
| 72 using suggestions::ImageDecoderImpl; | 78 using suggestions::ImageDecoderImpl; |
| 73 using suggestions::SuggestionsService; | 79 using suggestions::SuggestionsService; |
| 74 using suggestions::SuggestionsServiceFactory; | 80 using suggestions::SuggestionsServiceFactory; |
| 75 | 81 |
| 76 namespace { | 82 namespace { |
| 77 | 83 |
| 78 // Clear the tasks that can be scheduled by running services. | 84 // Clear the tasks that can be scheduled by running services. |
| 79 void ClearScheduledTasks() { | 85 void ClearScheduledTasks() { |
| 80 #if defined(OS_ANDROID) | 86 #if defined(OS_ANDROID) |
| 81 NTPSnippetsLauncher::Get()->Unschedule(); | 87 NTPSnippetsLauncher::Get()->Unschedule(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 "ContentSuggestionsService", | 194 "ContentSuggestionsService", |
| 189 BrowserContextDependencyManager::GetInstance()) { | 195 BrowserContextDependencyManager::GetInstance()) { |
| 190 DependsOn(BookmarkModelFactory::GetInstance()); | 196 DependsOn(BookmarkModelFactory::GetInstance()); |
| 191 DependsOn(HistoryServiceFactory::GetInstance()); | 197 DependsOn(HistoryServiceFactory::GetInstance()); |
| 192 #if defined(OS_ANDROID) | 198 #if defined(OS_ANDROID) |
| 193 DependsOn(OfflinePageModelFactory::GetInstance()); | 199 DependsOn(OfflinePageModelFactory::GetInstance()); |
| 194 #endif // OS_ANDROID | 200 #endif // OS_ANDROID |
| 195 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 201 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 196 DependsOn(SigninManagerFactory::GetInstance()); | 202 DependsOn(SigninManagerFactory::GetInstance()); |
| 197 DependsOn(SuggestionsServiceFactory::GetInstance()); | 203 DependsOn(SuggestionsServiceFactory::GetInstance()); |
| 204 DependsOn(ProfileSyncServiceFactory::GetInstance()); | |
|
Marc Treib
2016/08/29 09:18:50
nit: please keep alphabetized
skym
2016/09/15 23:18:16
Done.
| |
| 198 } | 205 } |
| 199 | 206 |
| 200 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {} | 207 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {} |
| 201 | 208 |
| 202 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( | 209 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( |
| 203 content::BrowserContext* context) const { | 210 content::BrowserContext* context) const { |
| 204 using State = ContentSuggestionsService::State; | 211 using State = ContentSuggestionsService::State; |
| 205 Profile* profile = Profile::FromBrowserContext(context); | 212 Profile* profile = Profile::FromBrowserContext(context); |
| 206 DCHECK(!profile->IsOffTheRecord()); | 213 DCHECK(!profile->IsOffTheRecord()); |
| 207 | 214 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 RegisterPhysicalWebPageProvider(service, category_factory); | 264 RegisterPhysicalWebPageProvider(service, category_factory); |
| 258 } | 265 } |
| 259 #endif // OS_ANDROID | 266 #endif // OS_ANDROID |
| 260 | 267 |
| 261 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { | 268 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { |
| 262 RegisterArticleProvider(signin_manager, token_service, history_service, | 269 RegisterArticleProvider(signin_manager, token_service, history_service, |
| 263 suggestions_service, service, category_factory, | 270 suggestions_service, service, category_factory, |
| 264 pref_service, profile); | 271 pref_service, profile); |
| 265 } | 272 } |
| 266 | 273 |
| 274 if (base::FeatureList::IsEnabled( | |
| 275 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | |
| 276 sync_driver::SyncService* sync_service = | |
|
Marc Treib
2016/08/29 09:18:50
Please put this into a RegisterSessionsProvider he
skym
2016/09/15 23:18:16
Done.
| |
| 277 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); | |
| 278 std::unique_ptr<ForeignSessionsSuggestionsProvider> | |
| 279 foreign_sessions_suggestions_provider = | |
| 280 base::MakeUnique<ForeignSessionsSuggestionsProvider>( | |
| 281 service, service->category_factory(), sync_service, | |
| 282 profile->GetPrefs()); | |
| 283 service->RegisterProvider(std::move(foreign_sessions_suggestions_provider)); | |
| 284 } | |
| 285 | |
| 267 return service; | 286 return service; |
| 268 } | 287 } |
| OLD | NEW |