OLD | NEW |
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 content::BrowserContext::GetDefaultStoragePartition(profile) | 187 content::BrowserContext::GetDefaultStoragePartition(profile) |
188 ->GetURLRequestContext(); | 188 ->GetURLRequestContext(); |
189 | 189 |
190 base::FilePath database_dir( | 190 base::FilePath database_dir( |
191 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); | 191 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); |
192 scoped_refptr<base::SequencedTaskRunner> task_runner = | 192 scoped_refptr<base::SequencedTaskRunner> task_runner = |
193 BrowserThread::GetBlockingPool() | 193 BrowserThread::GetBlockingPool() |
194 ->GetSequencedTaskRunnerWithShutdownBehavior( | 194 ->GetSequencedTaskRunnerWithShutdownBehavior( |
195 base::SequencedWorkerPool::GetSequenceToken(), | 195 base::SequencedWorkerPool::GetSequenceToken(), |
196 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 196 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
197 bool is_stable_channel = | 197 std::string api_key; |
198 chrome::GetChannel() == version_info::Channel::STABLE; | 198 // The API is private. If we don't have the official API key, don't even try. |
| 199 if (google_apis::IsGoogleChromeAPIKeyUsed()) { |
| 200 bool is_stable_channel = |
| 201 chrome::GetChannel() == version_info::Channel::STABLE; |
| 202 api_key = is_stable_channel ? google_apis::GetAPIKey() |
| 203 : google_apis::GetNonStableAPIKey(); |
| 204 } |
199 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>( | 205 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>( |
200 signin_manager, token_service, request_context, pref_service, | 206 signin_manager, token_service, request_context, pref_service, |
201 language_model, base::Bind(&safe_json::SafeJsonParser::Parse), | 207 language_model, base::Bind(&safe_json::SafeJsonParser::Parse), |
202 GetFetchEndpoint(chrome::GetChannel()), | 208 GetFetchEndpoint(chrome::GetChannel()), api_key, |
203 is_stable_channel ? google_apis::GetAPIKey() | |
204 : google_apis::GetNonStableAPIKey(), | |
205 service->user_classifier()); | 209 service->user_classifier()); |
206 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( | 210 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( |
207 service, pref_service, g_browser_process->GetApplicationLocale(), | 211 service, pref_service, g_browser_process->GetApplicationLocale(), |
208 service->category_ranker(), std::move(suggestions_fetcher), | 212 service->category_ranker(), std::move(suggestions_fetcher), |
209 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), | 213 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), |
210 request_context.get()), | 214 request_context.get()), |
211 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), | 215 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), |
212 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, | 216 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, |
213 pref_service)); | 217 pref_service)); |
214 | 218 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 292 |
289 // Create the ContentSuggestionsService. | 293 // Create the ContentSuggestionsService. |
290 SigninManagerBase* signin_manager = | 294 SigninManagerBase* signin_manager = |
291 SigninManagerFactory::GetForProfile(profile); | 295 SigninManagerFactory::GetForProfile(profile); |
292 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 296 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
293 profile, ServiceAccessType::EXPLICIT_ACCESS); | 297 profile, ServiceAccessType::EXPLICIT_ACCESS); |
294 PrefService* pref_service = profile->GetPrefs(); | 298 PrefService* pref_service = profile->GetPrefs(); |
295 std::unique_ptr<CategoryRanker> category_ranker = | 299 std::unique_ptr<CategoryRanker> category_ranker = |
296 ntp_snippets::BuildSelectedCategoryRanker( | 300 ntp_snippets::BuildSelectedCategoryRanker( |
297 pref_service, base::MakeUnique<base::DefaultClock>()); | 301 pref_service, base::MakeUnique<base::DefaultClock>()); |
298 auto* service = | 302 auto* service = new ContentSuggestionsService(State::ENABLED, signin_manager, |
299 new ContentSuggestionsService(State::ENABLED, signin_manager, | 303 history_service, pref_service, |
300 history_service, pref_service, std::move(category_ranker)); | 304 std::move(category_ranker)); |
301 | 305 |
302 #if defined(OS_ANDROID) | 306 #if defined(OS_ANDROID) |
303 OfflinePageModel* offline_page_model = | 307 OfflinePageModel* offline_page_model = |
304 OfflinePageModelFactory::GetForBrowserContext(profile); | 308 OfflinePageModelFactory::GetForBrowserContext(profile); |
305 RequestCoordinator* request_coordinator = | 309 RequestCoordinator* request_coordinator = |
306 RequestCoordinatorFactory::GetForBrowserContext(profile); | 310 RequestCoordinatorFactory::GetForBrowserContext(profile); |
307 DownloadManager* download_manager = | 311 DownloadManager* download_manager = |
308 content::BrowserContext::GetDownloadManager(profile); | 312 content::BrowserContext::GetDownloadManager(profile); |
309 DownloadService* download_service = | 313 DownloadService* download_service = |
310 DownloadServiceFactory::GetForBrowserContext(profile); | 314 DownloadServiceFactory::GetForBrowserContext(profile); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 365 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
362 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 366 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
363 } | 367 } |
364 | 368 |
365 return service; | 369 return service; |
366 | 370 |
367 #else | 371 #else |
368 return nullptr; | 372 return nullptr; |
369 #endif // CONTENT_SUGGESTIONS_ENABLED | 373 #endif // CONTENT_SUGGESTIONS_ENABLED |
370 } | 374 } |
OLD | NEW |