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

Unified Diff: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc

Issue 2245633002: ContentSuggestionsService providers registration refactoring. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pw_provider
Patch Set: Marked Android specific code. Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
diff --git a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
index d43779da51fa53682290020e15d65164a608cb69..401cda05023307225aae7cff9be8bc125ff23c57 100644
--- a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
+++ b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
@@ -24,6 +24,7 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
+#include "components/ntp_snippets/category_factory.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/features.h"
#include "components/ntp_snippets/ntp_snippets_constants.h"
@@ -61,6 +62,7 @@ using content::BrowserThread;
using history::HistoryService;
using image_fetcher::ImageFetcherImpl;
using ntp_snippets::BookmarkSuggestionsProvider;
+using ntp_snippets::CategoryFactory;
using ntp_snippets::ContentSuggestionsService;
using ntp_snippets::NTPSnippetsDatabase;
using ntp_snippets::NTPSnippetsFetcher;
@@ -80,6 +82,92 @@ void ClearScheduledTasks() {
#endif // OS_ANDROID
}
+#if defined(OS_ANDROID)
+void RegisterOfflinePageProvider(OfflinePageModel* offline_page_model,
+ ContentSuggestionsService* service,
+ CategoryFactory* category_factory,
+ PrefService* pref_service) {
+ bool recent_tabs_enabled = base::FeatureList::IsEnabled(
+ ntp_snippets::kRecentOfflineTabSuggestionsFeature);
+ bool downloads_enabled =
+ base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature);
+ bool download_manager_ui_enabled =
+ base::FeatureList::IsEnabled(chrome::android::kDownloadsUiFeature);
+ std::unique_ptr<OfflinePageSuggestionsProvider>
+ offline_page_suggestions_provider =
+ base::MakeUnique<OfflinePageSuggestionsProvider>(
+ recent_tabs_enabled, downloads_enabled,
+ download_manager_ui_enabled, service, category_factory,
+ offline_page_model, pref_service);
+ service->RegisterProvider(std::move(offline_page_suggestions_provider));
+}
+#endif // OS_ANDROID
+
+void RegisterBookmarkProvider(BookmarkModel* bookmark_model,
+ ContentSuggestionsService* service,
+ CategoryFactory* category_factory,
+ PrefService* pref_service) {
+ std::unique_ptr<BookmarkSuggestionsProvider> bookmark_suggestions_provider =
+ base::MakeUnique<BookmarkSuggestionsProvider>(
+ service, category_factory, bookmark_model, pref_service);
+ service->RegisterProvider(std::move(bookmark_suggestions_provider));
+}
+
+#if defined(OS_ANDROID)
+void RegisterPhysicalWebPageProvider(ContentSuggestionsService* service,
+ CategoryFactory* category_factory) {
+ std::unique_ptr<PhysicalWebPageSuggestionsProvider>
+ physical_web_page_suggestions_provider =
+ base::MakeUnique<PhysicalWebPageSuggestionsProvider>(
+ service, category_factory);
+ service->RegisterProvider(std::move(physical_web_page_suggestions_provider));
+}
+#endif // OS_ANDROID
+
+void RegisterArticleProvider(SigninManagerBase* signin_manager,
+ OAuth2TokenService* token_service,
+ HistoryService* history_service,
+ SuggestionsService* suggestions_service,
+ ContentSuggestionsService* service,
+ CategoryFactory* category_factory,
+ PrefService* pref_service,
+ Profile* profile) {
+ scoped_refptr<net::URLRequestContextGetter> request_context =
+ content::BrowserContext::GetDefaultStoragePartition(profile)
+ ->GetURLRequestContext();
+
+ NTPSnippetsScheduler* scheduler = nullptr;
+#if defined(OS_ANDROID)
+ scheduler = NTPSnippetsLauncher::Get();
+#endif // OS_ANDROID
+ base::FilePath database_dir(
+ profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
+ scoped_refptr<base::SequencedTaskRunner> task_runner =
+ BrowserThread::GetBlockingPool()
+ ->GetSequencedTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::GetSequenceToken(),
+ base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
+ bool is_stable_channel =
+ chrome::GetChannel() == version_info::Channel::STABLE;
+ std::unique_ptr<NTPSnippetsService> ntp_snippets_service =
+ base::MakeUnique<NTPSnippetsService>(
+ service, service->category_factory(), pref_service, history_service,
+ suggestions_service, g_browser_process->GetApplicationLocale(),
+ scheduler,
+ base::MakeUnique<NTPSnippetsFetcher>(
+ signin_manager, token_service, request_context, pref_service,
+ category_factory, base::Bind(&safe_json::SafeJsonParser::Parse),
+ is_stable_channel),
+ base::MakeUnique<ImageFetcherImpl>(
+ base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
+ base::MakeUnique<ImageDecoderImpl>(),
+ base::MakeUnique<NTPSnippetsDatabase>(database_dir, task_runner),
+ base::MakeUnique<NTPSnippetsStatusService>(signin_manager,
+ pref_service));
+ service->set_ntp_snippets_service(ntp_snippets_service.get());
+ service->RegisterProvider(std::move(ntp_snippets_service));
+}
+
} // namespace
// static
@@ -130,98 +218,50 @@ KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor(
return service;
}
+ CategoryFactory* category_factory = service->category_factory();
+ PrefService* pref_service = profile->GetPrefs();
+#if defined(OS_ANDROID)
+ OfflinePageModel* offline_page_model =
+ OfflinePageModelFactory::GetForBrowserContext(profile);
+#endif // OS_ANDROID
+ BookmarkModel* bookmark_model =
+ BookmarkModelFactory::GetForBrowserContext(profile);
+ SigninManagerBase* signin_manager =
+ SigninManagerFactory::GetForProfile(profile);
+ OAuth2TokenService* token_service =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
+ HistoryService* history_service = HistoryServiceFactory::GetForProfile(
+ profile, ServiceAccessType::EXPLICIT_ACCESS);
+ SuggestionsService* suggestions_service =
+ SuggestionsServiceFactory::GetForProfile(profile);
+
#if defined(OS_ANDROID)
- // Create the OfflinePageSuggestionsProvider.
bool recent_tabs_enabled = base::FeatureList::IsEnabled(
ntp_snippets::kRecentOfflineTabSuggestionsFeature);
bool downloads_enabled =
base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature);
- bool download_manager_ui_enabled =
- base::FeatureList::IsEnabled(chrome::android::kDownloadsUiFeature);
if (recent_tabs_enabled || downloads_enabled) {
- OfflinePageModel* offline_page_model =
- OfflinePageModelFactory::GetForBrowserContext(profile);
-
- std::unique_ptr<OfflinePageSuggestionsProvider>
- offline_page_suggestions_provider =
- base::MakeUnique<OfflinePageSuggestionsProvider>(
- recent_tabs_enabled, downloads_enabled,
- download_manager_ui_enabled, service,
- service->category_factory(), offline_page_model,
- profile->GetPrefs());
- service->RegisterProvider(std::move(offline_page_suggestions_provider));
+ RegisterOfflinePageProvider(offline_page_model, service, category_factory,
+ pref_service);
}
#endif // OS_ANDROID
- // Create the BookmarkSuggestionsProvider.
- if (base::FeatureList::IsEnabled(
- ntp_snippets::kBookmarkSuggestionsFeature)) {
- BookmarkModel* bookmark_model =
- BookmarkModelFactory::GetForBrowserContext(profile);
- std::unique_ptr<BookmarkSuggestionsProvider> bookmark_suggestions_provider =
- base::MakeUnique<BookmarkSuggestionsProvider>(
- service, service->category_factory(), bookmark_model,
- profile->GetPrefs());
- service->RegisterProvider(std::move(bookmark_suggestions_provider));
+ if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature)) {
+ RegisterBookmarkProvider(bookmark_model, service, category_factory,
+ pref_service);
}
#if defined(OS_ANDROID)
- // Create the PhysicalWebPageSuggestionsProvider.
if (base::FeatureList::IsEnabled(
ntp_snippets::kPhysicalWebPageSuggestionsFeature)) {
- std::unique_ptr<PhysicalWebPageSuggestionsProvider>
- physical_web_page_suggestions_provider =
- base::MakeUnique<PhysicalWebPageSuggestionsProvider>(
- service, service->category_factory());
- service->RegisterProvider(
- std::move(physical_web_page_suggestions_provider));
+ RegisterPhysicalWebPageProvider(service, category_factory);
}
#endif // OS_ANDROID
if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) {
- // Create the NTPSnippetsService (articles provider).
- SigninManagerBase* signin_manager =
- SigninManagerFactory::GetForProfile(profile);
- OAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
- scoped_refptr<net::URLRequestContextGetter> request_context =
- content::BrowserContext::GetDefaultStoragePartition(context)
- ->GetURLRequestContext();
- HistoryService* history_service = HistoryServiceFactory::GetForProfile(
- profile, ServiceAccessType::EXPLICIT_ACCESS);
- SuggestionsService* suggestions_service =
- SuggestionsServiceFactory::GetForProfile(profile);
- NTPSnippetsScheduler* scheduler = nullptr;
-#if defined(OS_ANDROID)
- scheduler = NTPSnippetsLauncher::Get();
-#endif // OS_ANDROID
- base::FilePath database_dir(
- profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
- scoped_refptr<base::SequencedTaskRunner> task_runner =
- BrowserThread::GetBlockingPool()
- ->GetSequencedTaskRunnerWithShutdownBehavior(
- base::SequencedWorkerPool::GetSequenceToken(),
- base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
- bool is_stable_channel =
- chrome::GetChannel() == version_info::Channel::STABLE;
- std::unique_ptr<NTPSnippetsService> ntp_snippets_service =
- base::MakeUnique<NTPSnippetsService>(
- service, service->category_factory(), profile->GetPrefs(),
- history_service, suggestions_service,
- g_browser_process->GetApplicationLocale(),
- scheduler, base::MakeUnique<NTPSnippetsFetcher>(
- signin_manager, token_service, request_context,
- profile->GetPrefs(), service->category_factory(),
- base::Bind(&safe_json::SafeJsonParser::Parse),
- is_stable_channel),
- base::MakeUnique<ImageFetcherImpl>(
- base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
- base::MakeUnique<ImageDecoderImpl>(),
- base::MakeUnique<NTPSnippetsDatabase>(database_dir, task_runner),
- base::MakeUnique<NTPSnippetsStatusService>(signin_manager,
- profile->GetPrefs()));
- service->set_ntp_snippets_service(ntp_snippets_service.get());
- service->RegisterProvider(std::move(ntp_snippets_service));
+ RegisterArticleProvider(signin_manager, token_service, history_service,
+ suggestions_service, service, category_factory,
+ pref_service, profile);
}
return service;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698