Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service _factory.h" | 5 #include "ios/chrome/browser/ntp_snippets/ios_chrome_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/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/time/default_clock.h" | 14 #include "base/time/default_clock.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
| 17 #include "components/image_fetcher/image_decoder.h" | 17 #include "components/image_fetcher/image_decoder.h" |
| 18 #include "components/image_fetcher/image_fetcher.h" | 18 #include "components/image_fetcher/image_fetcher.h" |
| 19 #include "components/image_fetcher/image_fetcher_impl.h" | |
| 19 #include "components/keyed_service/core/service_access_type.h" | 20 #include "components/keyed_service/core/service_access_type.h" |
| 20 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 21 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 21 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" | 22 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
| 22 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 23 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 23 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h " | 24 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h " |
| 24 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" | 25 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
| 25 #include "components/ntp_snippets/content_suggestions_service.h" | 26 #include "components/ntp_snippets/content_suggestions_service.h" |
| 26 #include "components/ntp_snippets/features.h" | 27 #include "components/ntp_snippets/features.h" |
| 27 #include "components/ntp_snippets/ntp_snippets_constants.h" | 28 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 28 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 29 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
| 29 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 30 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 30 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 31 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
| 31 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 32 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 32 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 33 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
| 33 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider. h" | 34 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider. h" |
| 34 #include "components/signin/core/browser/signin_manager.h" | 35 #include "components/signin/core/browser/signin_manager.h" |
| 35 #include "components/version_info/version_info.h" | 36 #include "components/version_info/version_info.h" |
| 36 #include "google_apis/google_api_keys.h" | 37 #include "google_apis/google_api_keys.h" |
| 37 #include "ios/chrome/browser/application_context.h" | 38 #include "ios/chrome/browser/application_context.h" |
| 38 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 39 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 39 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 40 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 40 #include "ios/chrome/browser/history/history_service_factory.h" | 41 #include "ios/chrome/browser/history/history_service_factory.h" |
| 41 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" | 42 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" |
| 42 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 43 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
| 43 #include "ios/chrome/browser/suggestions/image_fetcher_impl.h" | |
| 44 #include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h" | 44 #include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h" |
| 45 #include "ios/chrome/common/channel_info.h" | 45 #include "ios/chrome/common/channel_info.h" |
| 46 #include "ios/web/public/browser_state.h" | 46 #include "ios/web/public/browser_state.h" |
| 47 #include "ios/web/public/web_thread.h" | 47 #include "ios/web/public/web_thread.h" |
| 48 #include "net/url_request/url_request_context_getter.h" | 48 #include "net/url_request/url_request_context_getter.h" |
| 49 | 49 |
| 50 using bookmarks::BookmarkModel; | 50 using bookmarks::BookmarkModel; |
| 51 using history::HistoryService; | 51 using history::HistoryService; |
| 52 using image_fetcher::ImageFetcherImpl; | |
| 52 using ios::BookmarkModelFactory; | 53 using ios::BookmarkModelFactory; |
| 53 using ntp_snippets::BookmarkSuggestionsProvider; | 54 using ntp_snippets::BookmarkSuggestionsProvider; |
| 54 using ntp_snippets::ContentSuggestionsService; | 55 using ntp_snippets::ContentSuggestionsService; |
| 55 using ntp_snippets::PersistentScheduler; | 56 using ntp_snippets::PersistentScheduler; |
| 56 using ntp_snippets::RemoteSuggestionsDatabase; | 57 using ntp_snippets::RemoteSuggestionsDatabase; |
| 57 using ntp_snippets::RemoteSuggestionsFetcher; | 58 using ntp_snippets::RemoteSuggestionsFetcher; |
| 58 using ntp_snippets::RemoteSuggestionsProviderImpl; | 59 using ntp_snippets::RemoteSuggestionsProviderImpl; |
| 59 using ntp_snippets::RemoteSuggestionsStatusService; | 60 using ntp_snippets::RemoteSuggestionsStatusService; |
| 60 using ntp_snippets::SchedulingRemoteSuggestionsProvider; | 61 using ntp_snippets::SchedulingRemoteSuggestionsProvider; |
| 61 using suggestions::CreateIOSImageDecoder; | 62 using suggestions::CreateIOSImageDecoder; |
| 62 using suggestions::ImageFetcherImpl; | |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 void ParseJson(const std::string& json, | 66 void ParseJson(const std::string& json, |
| 67 const ntp_snippets::SuccessCallback& success_callback, | 67 const ntp_snippets::SuccessCallback& success_callback, |
| 68 const ntp_snippets::ErrorCallback& error_callback) { | 68 const ntp_snippets::ErrorCallback& error_callback) { |
| 69 base::JSONReader json_reader; | 69 base::JSONReader json_reader; |
| 70 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); | 70 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); |
| 71 if (value) { | 71 if (value) { |
| 72 base::ThreadTaskRunnerHandle::Get()->PostTask( | 72 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 OAuth2TokenServiceFactory::GetForBrowserState(chrome_browser_state); | 147 OAuth2TokenServiceFactory::GetForBrowserState(chrome_browser_state); |
| 148 scoped_refptr<net::URLRequestContextGetter> request_context = | 148 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 149 browser_state->GetRequestContext(); | 149 browser_state->GetRequestContext(); |
| 150 base::FilePath database_dir( | 150 base::FilePath database_dir( |
| 151 browser_state->GetStatePath().Append(ntp_snippets::kDatabaseFolder)); | 151 browser_state->GetStatePath().Append(ntp_snippets::kDatabaseFolder)); |
| 152 scoped_refptr<base::SequencedTaskRunner> task_runner = | 152 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 153 web::WebThread::GetBlockingPool() | 153 web::WebThread::GetBlockingPool() |
| 154 ->GetSequencedTaskRunnerWithShutdownBehavior( | 154 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 155 base::SequencedWorkerPool::GetSequenceToken(), | 155 base::SequencedWorkerPool::GetSequenceToken(), |
| 156 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 156 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 157 | |
| 157 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>( | 158 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>( |
| 158 signin_manager, token_service, request_context, prefs, nullptr, | 159 signin_manager, token_service, request_context, prefs, nullptr, |
| 159 base::Bind(&ParseJson), GetChannel() == version_info::Channel::STABLE | 160 base::Bind(&ParseJson), GetChannel() == version_info::Channel::STABLE |
| 160 ? google_apis::GetAPIKey() | 161 ? google_apis::GetAPIKey() |
| 161 : google_apis::GetNonStableAPIKey(), | 162 : google_apis::GetNonStableAPIKey(), |
| 162 service->user_classifier()); | 163 service->user_classifier()); |
| 164 | |
| 163 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( | 165 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( |
| 164 service.get(), prefs, GetApplicationContext()->GetApplicationLocale(), | 166 service.get(), prefs, GetApplicationContext()->GetApplicationLocale(), |
| 165 service->category_ranker(), std::move(suggestions_fetcher), | 167 service->category_ranker(), std::move(suggestions_fetcher), |
| 166 base::MakeUnique<ImageFetcherImpl>(request_context.get(), | 168 base::MakeUnique<ImageFetcherImpl>( |
| 167 web::WebThread::GetBlockingPool()), | 169 CreateIOSImageDecoder(web::WebThread::GetBlockingPool()), |
|
gambard
2017/02/17 08:16:09
I have used the same pool as the one used by the t
noyau (Ping after 24h)
2017/02/17 10:04:18
Probably historical. The taskrunner is createed on
Marc Treib
2017/02/17 10:10:31
Yup, transient - in fact, we have the same problem
gambard
2017/02/17 10:11:16
No, the RemoteSuggestionsProviderImpl (living in c
Marc Treib
2017/02/17 10:13:19
Concurrent comments ftw :D
Some more detail: Once
| |
| 170 request_context.get()), | |
| 168 CreateIOSImageDecoder(task_runner), | 171 CreateIOSImageDecoder(task_runner), |
| 169 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), | 172 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), |
| 170 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, | 173 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, |
| 171 prefs)); | 174 prefs)); |
| 172 | 175 |
| 173 // TODO(jkrcal): Implement a persistent scheduler for iOS. crbug.com/676249 | 176 // TODO(jkrcal): Implement a persistent scheduler for iOS. crbug.com/676249 |
| 174 auto scheduling_provider = | 177 auto scheduling_provider = |
| 175 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( | 178 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( |
| 176 service.get(), std::move(provider), | 179 service.get(), std::move(provider), |
| 177 /*persistent_scheduler=*/nullptr, service->user_classifier(), prefs, | 180 /*persistent_scheduler=*/nullptr, service->user_classifier(), prefs, |
| 178 base::MakeUnique<base::DefaultClock>()); | 181 base::MakeUnique<base::DefaultClock>()); |
| 179 service->set_remote_suggestions_provider(scheduling_provider.get()); | 182 service->set_remote_suggestions_provider(scheduling_provider.get()); |
| 180 service->set_remote_suggestions_scheduler(scheduling_provider.get()); | 183 service->set_remote_suggestions_scheduler(scheduling_provider.get()); |
| 181 service->RegisterProvider(std::move(scheduling_provider)); | 184 service->RegisterProvider(std::move(scheduling_provider)); |
| 182 } | 185 } |
| 183 | 186 |
| 184 return std::move(service); | 187 return std::move(service); |
| 185 } | 188 } |
| OLD | NEW |