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

Side by Side Diff: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc

Issue 2686053002: Don't instantiate ContentSuggestionsService on non-Android (Closed)
Patch Set: Add browsertest Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ntp_snippets/content_suggestions_service_factory_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 using ntp_snippets::RemoteSuggestionsDatabase; 88 using ntp_snippets::RemoteSuggestionsDatabase;
89 using ntp_snippets::RemoteSuggestionsFetcher; 89 using ntp_snippets::RemoteSuggestionsFetcher;
90 using ntp_snippets::RemoteSuggestionsProviderImpl; 90 using ntp_snippets::RemoteSuggestionsProviderImpl;
91 using ntp_snippets::RemoteSuggestionsStatusService; 91 using ntp_snippets::RemoteSuggestionsStatusService;
92 using ntp_snippets::SchedulingRemoteSuggestionsProvider; 92 using ntp_snippets::SchedulingRemoteSuggestionsProvider;
93 using ntp_snippets::TabDelegateSyncAdapter; 93 using ntp_snippets::TabDelegateSyncAdapter;
94 using suggestions::ImageDecoderImpl; 94 using suggestions::ImageDecoderImpl;
95 using syncer::SyncService; 95 using syncer::SyncService;
96 using translate::LanguageModel; 96 using translate::LanguageModel;
97 97
98 // For now, ContentSuggestionsService must only be instantiated on Android.
99 // See also crbug.com/688366.
100 #if defined(OS_ANDROID)
101 #define CONTENT_SUGGESTIONS_ENABLED 1
102 #else
103 #define CONTENT_SUGGESTIONS_ENABLED 0
104 #endif // OS_ANDROID
105
106 // The actual #if that does the work is below in BuildServiceInstanceFor. This
107 // one is just required to avoid "unused code" compiler errors.
108 #if CONTENT_SUGGESTIONS_ENABLED
109
98 namespace { 110 namespace {
99 111
100 #if defined(OS_ANDROID) 112 #if defined(OS_ANDROID)
101 113
102 bool IsRecentTabProviderEnabled() { 114 bool IsRecentTabProviderEnabled() {
103 return base::FeatureList::IsEnabled( 115 return base::FeatureList::IsEnabled(
104 ntp_snippets::kRecentOfflineTabSuggestionsFeature) && 116 ntp_snippets::kRecentOfflineTabSuggestionsFeature) &&
105 base::FeatureList::IsEnabled( 117 base::FeatureList::IsEnabled(
106 offline_pages::kOffliningRecentPagesFeature); 118 offline_pages::kOffliningRecentPagesFeature);
107 } 119 }
108 120
109 void RegisterRecentTabProvider(OfflinePageModel* offline_page_model, 121 void RegisterRecentTabProvider(OfflinePageModel* offline_page_model,
110 ContentSuggestionsService* service, 122 ContentSuggestionsService* service,
111 PrefService* pref_service) { 123 PrefService* pref_service) {
112 auto provider = base::MakeUnique<RecentTabSuggestionsProvider>( 124 auto provider = base::MakeUnique<RecentTabSuggestionsProvider>(
113 service, offline_page_model, pref_service); 125 service, offline_page_model, pref_service);
114 service->RegisterProvider(std::move(provider)); 126 service->RegisterProvider(std::move(provider));
115 } 127 }
116 128
117 void RegisterDownloadsProvider(OfflinePageModel* offline_page_model, 129 void RegisterDownloadsProvider(OfflinePageModel* offline_page_model,
118 DownloadManager* download_manager, 130 DownloadManager* download_manager,
119 DownloadHistory* download_history, 131 DownloadHistory* download_history,
120 ContentSuggestionsService* service, 132 ContentSuggestionsService* service,
121 PrefService* pref_service) { 133 PrefService* pref_service) {
122 auto provider = base::MakeUnique<DownloadSuggestionsProvider>( 134 auto provider = base::MakeUnique<DownloadSuggestionsProvider>(
123 service, offline_page_model, download_manager, download_history, 135 service, offline_page_model, download_manager, download_history,
124 pref_service, base::MakeUnique<base::DefaultClock>()); 136 pref_service, base::MakeUnique<base::DefaultClock>());
125 service->RegisterProvider(std::move(provider)); 137 service->RegisterProvider(std::move(provider));
126 } 138 }
139
127 #endif // OS_ANDROID 140 #endif // OS_ANDROID
128 141
129 void RegisterBookmarkProvider(BookmarkModel* bookmark_model, 142 void RegisterBookmarkProvider(BookmarkModel* bookmark_model,
130 ContentSuggestionsService* service, 143 ContentSuggestionsService* service,
131 PrefService* pref_service) { 144 PrefService* pref_service) {
132 auto provider = base::MakeUnique<BookmarkSuggestionsProvider>( 145 auto provider = base::MakeUnique<BookmarkSuggestionsProvider>(
133 service, bookmark_model, pref_service); 146 service, bookmark_model, pref_service);
134 service->RegisterProvider(std::move(provider)); 147 service->RegisterProvider(std::move(provider));
135 } 148 }
136 149
137 #if defined(OS_ANDROID) 150 #if defined(OS_ANDROID)
138 151
139 bool IsPhysicalWebPageProviderEnabled() { 152 bool IsPhysicalWebPageProviderEnabled() {
140 return base::FeatureList::IsEnabled( 153 return base::FeatureList::IsEnabled(
141 ntp_snippets::kPhysicalWebPageSuggestionsFeature) && 154 ntp_snippets::kPhysicalWebPageSuggestionsFeature) &&
142 base::FeatureList::IsEnabled(chrome::android::kPhysicalWebFeature); 155 base::FeatureList::IsEnabled(chrome::android::kPhysicalWebFeature);
143 } 156 }
144 157
145 void RegisterPhysicalWebPageProvider( 158 void RegisterPhysicalWebPageProvider(
146 ContentSuggestionsService* service, 159 ContentSuggestionsService* service,
147 PhysicalWebDataSource* physical_web_data_source, 160 PhysicalWebDataSource* physical_web_data_source,
148 PrefService* pref_service) { 161 PrefService* pref_service) {
149 auto provider = base::MakeUnique<PhysicalWebPageSuggestionsProvider>( 162 auto provider = base::MakeUnique<PhysicalWebPageSuggestionsProvider>(
150 service, physical_web_data_source, pref_service); 163 service, physical_web_data_source, pref_service);
151 service->RegisterProvider(std::move(provider)); 164 service->RegisterProvider(std::move(provider));
152 } 165 }
166
153 #endif // OS_ANDROID 167 #endif // OS_ANDROID
154 168
155 void RegisterArticleProvider(SigninManagerBase* signin_manager, 169 void RegisterArticleProvider(SigninManagerBase* signin_manager,
156 OAuth2TokenService* token_service, 170 OAuth2TokenService* token_service,
157 ContentSuggestionsService* service, 171 ContentSuggestionsService* service,
158 LanguageModel* language_model, 172 LanguageModel* language_model,
159 PrefService* pref_service, 173 PrefService* pref_service,
160 Profile* profile) { 174 Profile* profile) {
161 scoped_refptr<net::URLRequestContextGetter> request_context = 175 scoped_refptr<net::URLRequestContextGetter> request_context =
162 content::BrowserContext::GetDefaultStoragePartition(profile) 176 content::BrowserContext::GetDefaultStoragePartition(profile)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 PrefService* pref_service) { 220 PrefService* pref_service) {
207 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 221 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
208 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 222 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
209 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( 223 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>(
210 service, std::move(sync_adapter), pref_service); 224 service, std::move(sync_adapter), pref_service);
211 service->RegisterProvider(std::move(provider)); 225 service->RegisterProvider(std::move(provider));
212 } 226 }
213 227
214 } // namespace 228 } // namespace
215 229
230 #endif // CONTENT_SUGGESTIONS_ENABLED
231
216 // static 232 // static
217 ContentSuggestionsServiceFactory* 233 ContentSuggestionsServiceFactory*
218 ContentSuggestionsServiceFactory::GetInstance() { 234 ContentSuggestionsServiceFactory::GetInstance() {
219 return base::Singleton<ContentSuggestionsServiceFactory>::get(); 235 return base::Singleton<ContentSuggestionsServiceFactory>::get();
220 } 236 }
221 237
222 // static 238 // static
223 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( 239 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile(
224 Profile* profile) { 240 Profile* profile) {
225 return static_cast<ContentSuggestionsService*>( 241 return static_cast<ContentSuggestionsService*>(
(...skipping 18 matching lines...) Expand all
244 #endif // OS_ANDROID 260 #endif // OS_ANDROID
245 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 261 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
246 DependsOn(ProfileSyncServiceFactory::GetInstance()); 262 DependsOn(ProfileSyncServiceFactory::GetInstance());
247 DependsOn(SigninManagerFactory::GetInstance()); 263 DependsOn(SigninManagerFactory::GetInstance());
248 } 264 }
249 265
250 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() = default; 266 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() = default;
251 267
252 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( 268 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor(
253 content::BrowserContext* context) const { 269 content::BrowserContext* context) const {
270 #if CONTENT_SUGGESTIONS_ENABLED
271
254 using State = ContentSuggestionsService::State; 272 using State = ContentSuggestionsService::State;
255 Profile* profile = Profile::FromBrowserContext(context); 273 Profile* profile = Profile::FromBrowserContext(context);
256 DCHECK(!profile->IsOffTheRecord()); 274 DCHECK(!profile->IsOffTheRecord());
257 275
258 // Create the ContentSuggestionsService. 276 // Create the ContentSuggestionsService.
259 SigninManagerBase* signin_manager = 277 SigninManagerBase* signin_manager =
260 SigninManagerFactory::GetForProfile(profile); 278 SigninManagerFactory::GetForProfile(profile);
261 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 279 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
262 profile, ServiceAccessType::EXPLICIT_ACCESS); 280 profile, ServiceAccessType::EXPLICIT_ACCESS);
263 PrefService* pref_service = profile->GetPrefs(); 281 PrefService* pref_service = profile->GetPrefs();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 RegisterArticleProvider(signin_manager, token_service, service, 340 RegisterArticleProvider(signin_manager, token_service, service,
323 language_model, pref_service, profile); 341 language_model, pref_service, profile);
324 } 342 }
325 343
326 if (base::FeatureList::IsEnabled( 344 if (base::FeatureList::IsEnabled(
327 ntp_snippets::kForeignSessionsSuggestionsFeature)) { 345 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
328 RegisterForeignSessionsProvider(sync_service, service, pref_service); 346 RegisterForeignSessionsProvider(sync_service, service, pref_service);
329 } 347 }
330 348
331 return service; 349 return service;
350
351 #else
352 return nullptr;
353 #endif // CONTENT_SUGGESTIONS_ENABLED
332 } 354 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ntp_snippets/content_suggestions_service_factory_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698