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

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

Issue 2279123002: [Sync] Initial implementation of foreign sessions suggestions provider. (Closed)
Patch Set: Adding sessions deps to BUILD.gn Created 4 years, 3 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
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>
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"
41 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h"
36 #include "components/prefs/pref_service.h" 42 #include "components/prefs/pref_service.h"
37 #include "components/safe_json/safe_json_parser.h" 43 #include "components/safe_json/safe_json_parser.h"
38 #include "components/signin/core/browser/profile_oauth2_token_service.h" 44 #include "components/signin/core/browser/profile_oauth2_token_service.h"
39 #include "components/signin/core/browser/signin_manager.h" 45 #include "components/signin/core/browser/signin_manager.h"
40 #include "components/version_info/version_info.h" 46 #include "components/version_info/version_info.h"
41 #include "content/public/browser/browser_context.h" 47 #include "content/public/browser/browser_context.h"
42 #include "content/public/browser/browser_thread.h" 48 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/storage_partition.h" 49 #include "content/public/browser/storage_partition.h"
44 #include "google_apis/google_api_keys.h" 50 #include "google_apis/google_api_keys.h"
45 #include "net/url_request/url_request_context_getter.h" 51 #include "net/url_request/url_request_context_getter.h"
(...skipping 17 matching lines...) Expand all
63 using history::HistoryService; 69 using history::HistoryService;
64 using image_fetcher::ImageFetcherImpl; 70 using image_fetcher::ImageFetcherImpl;
65 using ntp_snippets::BookmarkSuggestionsProvider; 71 using ntp_snippets::BookmarkSuggestionsProvider;
66 using ntp_snippets::CategoryFactory; 72 using ntp_snippets::CategoryFactory;
67 using ntp_snippets::ContentSuggestionsService; 73 using ntp_snippets::ContentSuggestionsService;
68 using ntp_snippets::NTPSnippetsDatabase; 74 using ntp_snippets::NTPSnippetsDatabase;
69 using ntp_snippets::NTPSnippetsFetcher; 75 using ntp_snippets::NTPSnippetsFetcher;
70 using ntp_snippets::NTPSnippetsService; 76 using ntp_snippets::NTPSnippetsService;
71 using ntp_snippets::NTPSnippetsScheduler; 77 using ntp_snippets::NTPSnippetsScheduler;
72 using ntp_snippets::NTPSnippetsStatusService; 78 using ntp_snippets::NTPSnippetsStatusService;
79 using ntp_snippets::ForeignSessionsSuggestionsProvider;
80 using ntp_snippets::TabDelegateSyncAdapter;
73 using suggestions::ImageDecoderImpl; 81 using suggestions::ImageDecoderImpl;
74 using suggestions::SuggestionsService; 82 using suggestions::SuggestionsService;
75 using suggestions::SuggestionsServiceFactory; 83 using suggestions::SuggestionsServiceFactory;
84 using sync_driver::SyncService;
76 85
77 namespace { 86 namespace {
78 87
79 // Clear the tasks that can be scheduled by running services. 88 // Clear the tasks that can be scheduled by running services.
80 void ClearScheduledTasks() { 89 void ClearScheduledTasks() {
81 #if defined(OS_ANDROID) 90 #if defined(OS_ANDROID)
82 NTPSnippetsLauncher::Get()->Unschedule(); 91 NTPSnippetsLauncher::Get()->Unschedule();
83 #endif // OS_ANDROID 92 #endif // OS_ANDROID
84 } 93 }
85 94
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 base::MakeUnique<ImageFetcherImpl>( 171 base::MakeUnique<ImageFetcherImpl>(
163 base::MakeUnique<ImageDecoderImpl>(), request_context.get()), 172 base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
164 base::MakeUnique<ImageDecoderImpl>(), 173 base::MakeUnique<ImageDecoderImpl>(),
165 base::MakeUnique<NTPSnippetsDatabase>(database_dir, task_runner), 174 base::MakeUnique<NTPSnippetsDatabase>(database_dir, task_runner),
166 base::MakeUnique<NTPSnippetsStatusService>(signin_manager, 175 base::MakeUnique<NTPSnippetsStatusService>(signin_manager,
167 pref_service)); 176 pref_service));
168 service->set_ntp_snippets_service(ntp_snippets_service.get()); 177 service->set_ntp_snippets_service(ntp_snippets_service.get());
169 service->RegisterProvider(std::move(ntp_snippets_service)); 178 service->RegisterProvider(std::move(ntp_snippets_service));
170 } 179 }
171 180
181 void RegisterForeignSessionsProvider(SyncService* sync_service,
182 ContentSuggestionsService* service,
183 CategoryFactory* category_factory,
184 PrefService* pref_service,
185 Profile* profile) {
Marc Treib 2016/09/16 12:26:48 profile doesn't seem to be required
skym 2016/09/16 18:18:47 Done.
186 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
187 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
188 std::unique_ptr<ForeignSessionsSuggestionsProvider>
189 foreign_sessions_suggestions_provider =
190 base::MakeUnique<ForeignSessionsSuggestionsProvider>(
191 service, category_factory, std::move(sync_adapter), pref_service);
192 service->RegisterProvider(std::move(foreign_sessions_suggestions_provider));
193 }
194
172 } // namespace 195 } // namespace
173 196
174 // static 197 // static
175 ContentSuggestionsServiceFactory* 198 ContentSuggestionsServiceFactory*
176 ContentSuggestionsServiceFactory::GetInstance() { 199 ContentSuggestionsServiceFactory::GetInstance() {
177 return base::Singleton<ContentSuggestionsServiceFactory>::get(); 200 return base::Singleton<ContentSuggestionsServiceFactory>::get();
178 } 201 }
179 202
180 // static 203 // static
181 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( 204 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile(
182 Profile* profile) { 205 Profile* profile) {
183 return static_cast<ContentSuggestionsService*>( 206 return static_cast<ContentSuggestionsService*>(
184 GetInstance()->GetServiceForBrowserContext(profile, true)); 207 GetInstance()->GetServiceForBrowserContext(profile, true));
185 } 208 }
186 209
187 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory() 210 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory()
188 : BrowserContextKeyedServiceFactory( 211 : BrowserContextKeyedServiceFactory(
189 "ContentSuggestionsService", 212 "ContentSuggestionsService",
190 BrowserContextDependencyManager::GetInstance()) { 213 BrowserContextDependencyManager::GetInstance()) {
191 DependsOn(BookmarkModelFactory::GetInstance()); 214 DependsOn(BookmarkModelFactory::GetInstance());
192 DependsOn(HistoryServiceFactory::GetInstance()); 215 DependsOn(HistoryServiceFactory::GetInstance());
193 #if defined(OS_ANDROID) 216 #if defined(OS_ANDROID)
194 DependsOn(OfflinePageModelFactory::GetInstance()); 217 DependsOn(OfflinePageModelFactory::GetInstance());
195 #endif // OS_ANDROID 218 #endif // OS_ANDROID
196 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 219 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
220 DependsOn(ProfileSyncServiceFactory::GetInstance());
197 DependsOn(SigninManagerFactory::GetInstance()); 221 DependsOn(SigninManagerFactory::GetInstance());
198 DependsOn(SuggestionsServiceFactory::GetInstance()); 222 DependsOn(SuggestionsServiceFactory::GetInstance());
199 } 223 }
200 224
201 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {} 225 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {}
202 226
203 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( 227 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor(
204 content::BrowserContext* context) const { 228 content::BrowserContext* context) const {
205 using State = ContentSuggestionsService::State; 229 using State = ContentSuggestionsService::State;
206 Profile* profile = Profile::FromBrowserContext(context); 230 Profile* profile = Profile::FromBrowserContext(context);
(...skipping 22 matching lines...) Expand all
229 OfflinePageModelFactory::GetForBrowserContext(profile); 253 OfflinePageModelFactory::GetForBrowserContext(profile);
230 #endif // OS_ANDROID 254 #endif // OS_ANDROID
231 BookmarkModel* bookmark_model = 255 BookmarkModel* bookmark_model =
232 BookmarkModelFactory::GetForBrowserContext(profile); 256 BookmarkModelFactory::GetForBrowserContext(profile);
233 SigninManagerBase* signin_manager = 257 SigninManagerBase* signin_manager =
234 SigninManagerFactory::GetForProfile(profile); 258 SigninManagerFactory::GetForProfile(profile);
235 OAuth2TokenService* token_service = 259 OAuth2TokenService* token_service =
236 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 260 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
237 SuggestionsService* suggestions_service = 261 SuggestionsService* suggestions_service =
238 SuggestionsServiceFactory::GetForProfile(profile); 262 SuggestionsServiceFactory::GetForProfile(profile);
263 SyncService* sync_service =
264 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile);
239 265
240 #if defined(OS_ANDROID) 266 #if defined(OS_ANDROID)
241 bool recent_tabs_enabled = base::FeatureList::IsEnabled( 267 bool recent_tabs_enabled = base::FeatureList::IsEnabled(
242 ntp_snippets::kRecentOfflineTabSuggestionsFeature); 268 ntp_snippets::kRecentOfflineTabSuggestionsFeature);
243 bool downloads_enabled = 269 bool downloads_enabled =
244 base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature); 270 base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature);
245 if (recent_tabs_enabled || downloads_enabled) { 271 if (recent_tabs_enabled || downloads_enabled) {
246 RegisterOfflinePageProvider(offline_page_model, service, category_factory, 272 RegisterOfflinePageProvider(offline_page_model, service, category_factory,
247 pref_service); 273 pref_service);
248 } 274 }
(...skipping 11 matching lines...) Expand all
260 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) { 286 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) {
261 RegisterPhysicalWebPageProvider(service, category_factory); 287 RegisterPhysicalWebPageProvider(service, category_factory);
262 } 288 }
263 #endif // OS_ANDROID 289 #endif // OS_ANDROID
264 290
265 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { 291 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) {
266 RegisterArticleProvider(signin_manager, token_service, suggestions_service, 292 RegisterArticleProvider(signin_manager, token_service, suggestions_service,
267 service, category_factory, pref_service, profile); 293 service, category_factory, pref_service, profile);
268 } 294 }
269 295
296 if (base::FeatureList::IsEnabled(
297 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
298 RegisterForeignSessionsProvider(sync_service, service, category_factory,
299 pref_service, profile);
300 }
301
270 return service; 302 return service;
271 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698