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

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

Issue 2671453003: [NTP::Cleanup] Avoid nested complex function calls (Closed)
Patch Set: resolve iOS compile error. 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 | ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 base::FilePath database_dir( 165 base::FilePath database_dir(
166 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); 166 profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
167 scoped_refptr<base::SequencedTaskRunner> task_runner = 167 scoped_refptr<base::SequencedTaskRunner> task_runner =
168 BrowserThread::GetBlockingPool() 168 BrowserThread::GetBlockingPool()
169 ->GetSequencedTaskRunnerWithShutdownBehavior( 169 ->GetSequencedTaskRunnerWithShutdownBehavior(
170 base::SequencedWorkerPool::GetSequenceToken(), 170 base::SequencedWorkerPool::GetSequenceToken(),
171 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 171 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
172 bool is_stable_channel = 172 bool is_stable_channel =
173 chrome::GetChannel() == version_info::Channel::STABLE; 173 chrome::GetChannel() == version_info::Channel::STABLE;
174 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>(
175 signin_manager, token_service, request_context, pref_service,
176 language_model, base::Bind(&safe_json::SafeJsonParser::Parse),
177 is_stable_channel ? google_apis::GetAPIKey()
178 : google_apis::GetNonStableAPIKey(),
179 service->user_classifier());
180 auto image_decoder_for_fetcher = base::MakeUnique<ImageDecoderImpl>();
181 auto image_fetcher = base::MakeUnique<ImageFetcherImpl>(
182 std::move(image_decoder_for_fetcher), request_context.get());
183 auto image_decoder = base::MakeUnique<ImageDecoderImpl>();
184 auto database =
185 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner);
186 auto status_service = base::MakeUnique<RemoteSuggestionsStatusService>(
187 signin_manager, pref_service);
174 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( 188 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>(
175 service, pref_service, g_browser_process->GetApplicationLocale(), 189 service, pref_service, g_browser_process->GetApplicationLocale(),
176 service->category_ranker(), 190 service->category_ranker(), std::move(suggestions_fetcher),
177 base::MakeUnique<RemoteSuggestionsFetcher>( 191 std::move(image_fetcher), std::move(image_decoder), std::move(database),
178 signin_manager, token_service, request_context, pref_service, 192 std::move(status_service));
tschumann 2017/02/01 11:35:37 I'm having a hard time following the motivation. C
Marc Treib 2017/02/01 12:33:20 Maybe put all of this into a scope, so the variabl
vitaliii 2017/02/01 13:15:15 Done. 1) I inlined MakeUnique calls, which have n
179 language_model, base::Bind(&safe_json::SafeJsonParser::Parse),
180 is_stable_channel ? google_apis::GetAPIKey()
181 : google_apis::GetNonStableAPIKey(),
182 service->user_classifier()),
183 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(),
184 request_context.get()),
185 base::MakeUnique<ImageDecoderImpl>(),
186 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner),
187 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager,
188 pref_service));
189 193
190 PersistentScheduler* scheduler = nullptr; 194 PersistentScheduler* scheduler = nullptr;
191 #if defined(OS_ANDROID) 195 #if defined(OS_ANDROID)
192 scheduler = NTPSnippetsLauncher::Get(); 196 scheduler = NTPSnippetsLauncher::Get();
193 #endif // OS_ANDROID 197 #endif // OS_ANDROID
194 198
199 auto scheduling_provider_clock = base::MakeUnique<base::DefaultClock>();
195 auto scheduling_provider = 200 auto scheduling_provider =
196 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( 201 base::MakeUnique<SchedulingRemoteSuggestionsProvider>(
197 service, std::move(provider), scheduler, service->user_classifier(), 202 service, std::move(provider), scheduler, service->user_classifier(),
198 pref_service, base::MakeUnique<base::DefaultClock>()); 203 pref_service, std::move(scheduling_provider_clock));
199 service->set_remote_suggestions_provider(scheduling_provider.get()); 204 service->set_remote_suggestions_provider(scheduling_provider.get());
200 service->set_remote_suggestions_scheduler(scheduling_provider.get()); 205 service->set_remote_suggestions_scheduler(scheduling_provider.get());
201 service->RegisterProvider(std::move(scheduling_provider)); 206 service->RegisterProvider(std::move(scheduling_provider));
202 } 207 }
203 208
204 void RegisterForeignSessionsProvider(SyncService* sync_service, 209 void RegisterForeignSessionsProvider(SyncService* sync_service,
205 ContentSuggestionsService* service, 210 ContentSuggestionsService* service,
206 PrefService* pref_service) { 211 PrefService* pref_service) {
207 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 212 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
208 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 213 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 using State = ContentSuggestionsService::State; 259 using State = ContentSuggestionsService::State;
255 Profile* profile = Profile::FromBrowserContext(context); 260 Profile* profile = Profile::FromBrowserContext(context);
256 DCHECK(!profile->IsOffTheRecord()); 261 DCHECK(!profile->IsOffTheRecord());
257 262
258 // Create the ContentSuggestionsService. 263 // Create the ContentSuggestionsService.
259 SigninManagerBase* signin_manager = 264 SigninManagerBase* signin_manager =
260 SigninManagerFactory::GetForProfile(profile); 265 SigninManagerFactory::GetForProfile(profile);
261 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 266 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
262 profile, ServiceAccessType::EXPLICIT_ACCESS); 267 profile, ServiceAccessType::EXPLICIT_ACCESS);
263 PrefService* pref_service = profile->GetPrefs(); 268 PrefService* pref_service = profile->GetPrefs();
269 auto ranker_clock = base::MakeUnique<base::DefaultClock>();
264 std::unique_ptr<CategoryRanker> category_ranker = 270 std::unique_ptr<CategoryRanker> category_ranker =
265 ntp_snippets::BuildSelectedCategoryRanker( 271 ntp_snippets::BuildSelectedCategoryRanker(pref_service,
266 pref_service, base::MakeUnique<base::DefaultClock>()); 272 std::move(ranker_clock));
267 auto* service = 273 auto* service =
268 new ContentSuggestionsService(State::ENABLED, signin_manager, 274 new ContentSuggestionsService(State::ENABLED, signin_manager,
269 history_service, pref_service, std::move(category_ranker)); 275 history_service, pref_service, std::move(category_ranker));
270 276
271 #if defined(OS_ANDROID) 277 #if defined(OS_ANDROID)
272 OfflinePageModel* offline_page_model = 278 OfflinePageModel* offline_page_model =
273 OfflinePageModelFactory::GetForBrowserContext(profile); 279 OfflinePageModelFactory::GetForBrowserContext(profile);
274 DownloadManager* download_manager = 280 DownloadManager* download_manager =
275 content::BrowserContext::GetDownloadManager(profile); 281 content::BrowserContext::GetDownloadManager(profile);
276 DownloadService* download_service = 282 DownloadService* download_service =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 language_model, pref_service, profile); 329 language_model, pref_service, profile);
324 } 330 }
325 331
326 if (base::FeatureList::IsEnabled( 332 if (base::FeatureList::IsEnabled(
327 ntp_snippets::kForeignSessionsSuggestionsFeature)) { 333 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
328 RegisterForeignSessionsProvider(sync_service, service, pref_service); 334 RegisterForeignSessionsProvider(sync_service, service, pref_service);
329 } 335 }
330 336
331 return service; 337 return service;
332 } 338 }
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698