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

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: Updating for comments, again! 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/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 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
186 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
187 std::unique_ptr<ForeignSessionsSuggestionsProvider>
188 foreign_sessions_suggestions_provider =
189 base::MakeUnique<ForeignSessionsSuggestionsProvider>(
190 service, category_factory, std::move(sync_adapter), pref_service);
191 service->RegisterProvider(std::move(foreign_sessions_suggestions_provider));
192 }
193
172 } // namespace 194 } // namespace
173 195
174 // static 196 // static
175 ContentSuggestionsServiceFactory* 197 ContentSuggestionsServiceFactory*
176 ContentSuggestionsServiceFactory::GetInstance() { 198 ContentSuggestionsServiceFactory::GetInstance() {
177 return base::Singleton<ContentSuggestionsServiceFactory>::get(); 199 return base::Singleton<ContentSuggestionsServiceFactory>::get();
178 } 200 }
179 201
180 // static 202 // static
181 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile( 203 ContentSuggestionsService* ContentSuggestionsServiceFactory::GetForProfile(
(...skipping 12 matching lines...) Expand all
194 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory() 216 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory()
195 : BrowserContextKeyedServiceFactory( 217 : BrowserContextKeyedServiceFactory(
196 "ContentSuggestionsService", 218 "ContentSuggestionsService",
197 BrowserContextDependencyManager::GetInstance()) { 219 BrowserContextDependencyManager::GetInstance()) {
198 DependsOn(BookmarkModelFactory::GetInstance()); 220 DependsOn(BookmarkModelFactory::GetInstance());
199 DependsOn(HistoryServiceFactory::GetInstance()); 221 DependsOn(HistoryServiceFactory::GetInstance());
200 #if defined(OS_ANDROID) 222 #if defined(OS_ANDROID)
201 DependsOn(OfflinePageModelFactory::GetInstance()); 223 DependsOn(OfflinePageModelFactory::GetInstance());
202 #endif // OS_ANDROID 224 #endif // OS_ANDROID
203 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 225 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
226 DependsOn(ProfileSyncServiceFactory::GetInstance());
204 DependsOn(SigninManagerFactory::GetInstance()); 227 DependsOn(SigninManagerFactory::GetInstance());
205 DependsOn(SuggestionsServiceFactory::GetInstance()); 228 DependsOn(SuggestionsServiceFactory::GetInstance());
206 } 229 }
207 230
208 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {} 231 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {}
209 232
210 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( 233 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor(
211 content::BrowserContext* context) const { 234 content::BrowserContext* context) const {
212 using State = ContentSuggestionsService::State; 235 using State = ContentSuggestionsService::State;
213 Profile* profile = Profile::FromBrowserContext(context); 236 Profile* profile = Profile::FromBrowserContext(context);
(...skipping 22 matching lines...) Expand all
236 OfflinePageModelFactory::GetForBrowserContext(profile); 259 OfflinePageModelFactory::GetForBrowserContext(profile);
237 #endif // OS_ANDROID 260 #endif // OS_ANDROID
238 BookmarkModel* bookmark_model = 261 BookmarkModel* bookmark_model =
239 BookmarkModelFactory::GetForBrowserContext(profile); 262 BookmarkModelFactory::GetForBrowserContext(profile);
240 SigninManagerBase* signin_manager = 263 SigninManagerBase* signin_manager =
241 SigninManagerFactory::GetForProfile(profile); 264 SigninManagerFactory::GetForProfile(profile);
242 OAuth2TokenService* token_service = 265 OAuth2TokenService* token_service =
243 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 266 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
244 SuggestionsService* suggestions_service = 267 SuggestionsService* suggestions_service =
245 SuggestionsServiceFactory::GetForProfile(profile); 268 SuggestionsServiceFactory::GetForProfile(profile);
269 SyncService* sync_service =
270 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile);
246 271
247 #if defined(OS_ANDROID) 272 #if defined(OS_ANDROID)
248 bool recent_tabs_enabled = base::FeatureList::IsEnabled( 273 bool recent_tabs_enabled = base::FeatureList::IsEnabled(
249 ntp_snippets::kRecentOfflineTabSuggestionsFeature); 274 ntp_snippets::kRecentOfflineTabSuggestionsFeature);
250 bool downloads_enabled = 275 bool downloads_enabled =
251 base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature); 276 base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature);
252 if (recent_tabs_enabled || downloads_enabled) { 277 if (recent_tabs_enabled || downloads_enabled) {
253 RegisterOfflinePageProvider(offline_page_model, service, category_factory, 278 RegisterOfflinePageProvider(offline_page_model, service, category_factory,
254 pref_service); 279 pref_service);
255 } 280 }
(...skipping 11 matching lines...) Expand all
267 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) { 292 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) {
268 RegisterPhysicalWebPageProvider(service, category_factory); 293 RegisterPhysicalWebPageProvider(service, category_factory);
269 } 294 }
270 #endif // OS_ANDROID 295 #endif // OS_ANDROID
271 296
272 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { 297 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) {
273 RegisterArticleProvider(signin_manager, token_service, suggestions_service, 298 RegisterArticleProvider(signin_manager, token_service, suggestions_service,
274 service, category_factory, pref_service, profile); 299 service, category_factory, pref_service, profile);
275 } 300 }
276 301
302 if (base::FeatureList::IsEnabled(
303 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
304 RegisterForeignSessionsProvider(sync_service, service, category_factory,
305 pref_service);
306 }
307
277 return service; 308 return service;
278 } 309 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698