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

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

Issue 2317993004: Move OnURLsDeleted from NTPSnippetsService to ContentSuggestionsService (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | components/ntp_snippets/content_suggestions_service.h » ('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 "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 std::unique_ptr<PhysicalWebPageSuggestionsProvider> 119 std::unique_ptr<PhysicalWebPageSuggestionsProvider>
120 physical_web_page_suggestions_provider = 120 physical_web_page_suggestions_provider =
121 base::MakeUnique<PhysicalWebPageSuggestionsProvider>( 121 base::MakeUnique<PhysicalWebPageSuggestionsProvider>(
122 service, category_factory); 122 service, category_factory);
123 service->RegisterProvider(std::move(physical_web_page_suggestions_provider)); 123 service->RegisterProvider(std::move(physical_web_page_suggestions_provider));
124 } 124 }
125 #endif // OS_ANDROID 125 #endif // OS_ANDROID
126 126
127 void RegisterArticleProvider(SigninManagerBase* signin_manager, 127 void RegisterArticleProvider(SigninManagerBase* signin_manager,
128 OAuth2TokenService* token_service, 128 OAuth2TokenService* token_service,
129 HistoryService* history_service,
130 SuggestionsService* suggestions_service, 129 SuggestionsService* suggestions_service,
131 ContentSuggestionsService* service, 130 ContentSuggestionsService* service,
132 CategoryFactory* category_factory, 131 CategoryFactory* category_factory,
133 PrefService* pref_service, 132 PrefService* pref_service,
134 Profile* profile) { 133 Profile* profile) {
135 scoped_refptr<net::URLRequestContextGetter> request_context = 134 scoped_refptr<net::URLRequestContextGetter> request_context =
136 content::BrowserContext::GetDefaultStoragePartition(profile) 135 content::BrowserContext::GetDefaultStoragePartition(profile)
137 ->GetURLRequestContext(); 136 ->GetURLRequestContext();
138 137
139 NTPSnippetsScheduler* scheduler = nullptr; 138 NTPSnippetsScheduler* scheduler = nullptr;
140 #if defined(OS_ANDROID) 139 #if defined(OS_ANDROID)
141 scheduler = NTPSnippetsLauncher::Get(); 140 scheduler = NTPSnippetsLauncher::Get();
142 #endif // OS_ANDROID 141 #endif // OS_ANDROID
143 base::FilePath database_dir( 142 base::FilePath database_dir(
144 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); 143 profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
145 scoped_refptr<base::SequencedTaskRunner> task_runner = 144 scoped_refptr<base::SequencedTaskRunner> task_runner =
146 BrowserThread::GetBlockingPool() 145 BrowserThread::GetBlockingPool()
147 ->GetSequencedTaskRunnerWithShutdownBehavior( 146 ->GetSequencedTaskRunnerWithShutdownBehavior(
148 base::SequencedWorkerPool::GetSequenceToken(), 147 base::SequencedWorkerPool::GetSequenceToken(),
149 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 148 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
150 bool is_stable_channel = 149 bool is_stable_channel =
151 chrome::GetChannel() == version_info::Channel::STABLE; 150 chrome::GetChannel() == version_info::Channel::STABLE;
152 std::unique_ptr<NTPSnippetsService> ntp_snippets_service = 151 std::unique_ptr<NTPSnippetsService> ntp_snippets_service =
153 base::MakeUnique<NTPSnippetsService>( 152 base::MakeUnique<NTPSnippetsService>(
154 service, service->category_factory(), pref_service, history_service, 153 service, service->category_factory(), pref_service,
155 suggestions_service, g_browser_process->GetApplicationLocale(), 154 suggestions_service, g_browser_process->GetApplicationLocale(),
156 scheduler, 155 scheduler,
157 base::MakeUnique<NTPSnippetsFetcher>( 156 base::MakeUnique<NTPSnippetsFetcher>(
158 signin_manager, token_service, request_context, pref_service, 157 signin_manager, token_service, request_context, pref_service,
159 category_factory, base::Bind(&safe_json::SafeJsonParser::Parse), 158 category_factory, base::Bind(&safe_json::SafeJsonParser::Parse),
160 is_stable_channel), 159 is_stable_channel),
161 base::MakeUnique<ImageFetcherImpl>( 160 base::MakeUnique<ImageFetcherImpl>(
162 base::MakeUnique<ImageDecoderImpl>(), request_context.get()), 161 base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
163 base::MakeUnique<ImageDecoderImpl>(), 162 base::MakeUnique<ImageDecoderImpl>(),
164 base::MakeUnique<NTPSnippetsDatabase>(database_dir, task_runner), 163 base::MakeUnique<NTPSnippetsDatabase>(database_dir, task_runner),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 content::BrowserContext* context) const { 202 content::BrowserContext* context) const {
204 using State = ContentSuggestionsService::State; 203 using State = ContentSuggestionsService::State;
205 Profile* profile = Profile::FromBrowserContext(context); 204 Profile* profile = Profile::FromBrowserContext(context);
206 DCHECK(!profile->IsOffTheRecord()); 205 DCHECK(!profile->IsOffTheRecord());
207 206
208 // Create the ContentSuggestionsService. 207 // Create the ContentSuggestionsService.
209 State state = 208 State state =
210 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) 209 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature)
211 ? State::ENABLED 210 ? State::ENABLED
212 : State::DISABLED; 211 : State::DISABLED;
213 ContentSuggestionsService* service = new ContentSuggestionsService(state); 212 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
213 profile, ServiceAccessType::EXPLICIT_ACCESS);
214 ContentSuggestionsService* service =
215 new ContentSuggestionsService(state, history_service);
214 if (state == State::DISABLED) { 216 if (state == State::DISABLED) {
215 // Since we won't initialise the services, they won't get a chance to 217 // Since we won't initialise the services, they won't get a chance to
216 // unschedule their tasks. We do it explicitly here instead. 218 // unschedule their tasks. We do it explicitly here instead.
217 ClearScheduledTasks(); 219 ClearScheduledTasks();
218 return service; 220 return service;
219 } 221 }
220 222
221 CategoryFactory* category_factory = service->category_factory(); 223 CategoryFactory* category_factory = service->category_factory();
222 PrefService* pref_service = profile->GetPrefs(); 224 PrefService* pref_service = profile->GetPrefs();
223 #if defined(OS_ANDROID) 225 #if defined(OS_ANDROID)
224 OfflinePageModel* offline_page_model = 226 OfflinePageModel* offline_page_model =
225 OfflinePageModelFactory::GetForBrowserContext(profile); 227 OfflinePageModelFactory::GetForBrowserContext(profile);
226 #endif // OS_ANDROID 228 #endif // OS_ANDROID
227 BookmarkModel* bookmark_model = 229 BookmarkModel* bookmark_model =
228 BookmarkModelFactory::GetForBrowserContext(profile); 230 BookmarkModelFactory::GetForBrowserContext(profile);
229 SigninManagerBase* signin_manager = 231 SigninManagerBase* signin_manager =
230 SigninManagerFactory::GetForProfile(profile); 232 SigninManagerFactory::GetForProfile(profile);
231 OAuth2TokenService* token_service = 233 OAuth2TokenService* token_service =
232 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 234 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
233 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
234 profile, ServiceAccessType::EXPLICIT_ACCESS);
235 SuggestionsService* suggestions_service = 235 SuggestionsService* suggestions_service =
236 SuggestionsServiceFactory::GetForProfile(profile); 236 SuggestionsServiceFactory::GetForProfile(profile);
237 237
238 #if defined(OS_ANDROID) 238 #if defined(OS_ANDROID)
239 bool recent_tabs_enabled = base::FeatureList::IsEnabled( 239 bool recent_tabs_enabled = base::FeatureList::IsEnabled(
240 ntp_snippets::kRecentOfflineTabSuggestionsFeature); 240 ntp_snippets::kRecentOfflineTabSuggestionsFeature);
241 bool downloads_enabled = 241 bool downloads_enabled =
242 base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature); 242 base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature);
243 if (recent_tabs_enabled || downloads_enabled) { 243 if (recent_tabs_enabled || downloads_enabled) {
244 RegisterOfflinePageProvider(offline_page_model, service, category_factory, 244 RegisterOfflinePageProvider(offline_page_model, service, category_factory,
245 pref_service); 245 pref_service);
246 } 246 }
247 #endif // OS_ANDROID 247 #endif // OS_ANDROID
248 248
249 // |bookmark_model| can be null in tests. 249 // |bookmark_model| can be null in tests.
250 if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature) && 250 if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature) &&
251 bookmark_model) { 251 bookmark_model) {
252 RegisterBookmarkProvider(bookmark_model, service, category_factory, 252 RegisterBookmarkProvider(bookmark_model, service, category_factory,
253 pref_service); 253 pref_service);
254 } 254 }
255 255
256 #if defined(OS_ANDROID) 256 #if defined(OS_ANDROID)
257 if (base::FeatureList::IsEnabled( 257 if (base::FeatureList::IsEnabled(
258 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) { 258 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) {
259 RegisterPhysicalWebPageProvider(service, category_factory); 259 RegisterPhysicalWebPageProvider(service, category_factory);
260 } 260 }
261 #endif // OS_ANDROID 261 #endif // OS_ANDROID
262 262
263 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { 263 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) {
264 RegisterArticleProvider(signin_manager, token_service, history_service, 264 RegisterArticleProvider(signin_manager, token_service, suggestions_service,
265 suggestions_service, service, category_factory, 265 service, category_factory, pref_service, profile);
266 pref_service, profile);
267 } 266 }
268 267
269 return service; 268 return service;
270 } 269 }
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/content_suggestions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698