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

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

Issue 2557363002: [NTP Snippets] Refactor background scheduling for remote suggestions (Closed)
Patch Set: Tim's comments and splitting RemoteSuggestionsProvider and RemoteSuggestionsProviderImpl Created 4 years 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> 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 16 matching lines...) Expand all
27 #include "components/image_fetcher/image_fetcher.h" 27 #include "components/image_fetcher/image_fetcher.h"
28 #include "components/image_fetcher/image_fetcher_impl.h" 28 #include "components/image_fetcher/image_fetcher_impl.h"
29 #include "components/keyed_service/content/browser_context_dependency_manager.h" 29 #include "components/keyed_service/content/browser_context_dependency_manager.h"
30 #include "components/keyed_service/core/service_access_type.h" 30 #include "components/keyed_service/core/service_access_type.h"
31 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" 31 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
32 #include "components/ntp_snippets/category_factory.h" 32 #include "components/ntp_snippets/category_factory.h"
33 #include "components/ntp_snippets/content_suggestions_service.h" 33 #include "components/ntp_snippets/content_suggestions_service.h"
34 #include "components/ntp_snippets/features.h" 34 #include "components/ntp_snippets/features.h"
35 #include "components/ntp_snippets/ntp_snippets_constants.h" 35 #include "components/ntp_snippets/ntp_snippets_constants.h"
36 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" 36 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
37 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" 37 #include "components/ntp_snippets/remote/persistent_scheduler.h"
38 #include "components/ntp_snippets/remote/remote_suggestions_database.h" 38 #include "components/ntp_snippets/remote/remote_suggestions_database.h"
39 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 39 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h"
40 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" 40 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h"
41 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider. h"
41 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" 42 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h"
42 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" 43 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h"
43 #include "components/prefs/pref_service.h" 44 #include "components/prefs/pref_service.h"
44 #include "components/safe_json/safe_json_parser.h" 45 #include "components/safe_json/safe_json_parser.h"
45 #include "components/signin/core/browser/profile_oauth2_token_service.h" 46 #include "components/signin/core/browser/profile_oauth2_token_service.h"
46 #include "components/signin/core/browser/signin_manager.h" 47 #include "components/signin/core/browser/signin_manager.h"
47 #include "components/translate/core/browser/language_model.h" 48 #include "components/translate/core/browser/language_model.h"
48 #include "components/version_info/version_info.h" 49 #include "components/version_info/version_info.h"
49 #include "content/public/browser/browser_context.h" 50 #include "content/public/browser/browser_context.h"
50 #include "content/public/browser/browser_thread.h" 51 #include "content/public/browser/browser_thread.h"
(...skipping 21 matching lines...) Expand all
72 73
73 using bookmarks::BookmarkModel; 74 using bookmarks::BookmarkModel;
74 using content::BrowserThread; 75 using content::BrowserThread;
75 using history::HistoryService; 76 using history::HistoryService;
76 using image_fetcher::ImageFetcherImpl; 77 using image_fetcher::ImageFetcherImpl;
77 using ntp_snippets::BookmarkSuggestionsProvider; 78 using ntp_snippets::BookmarkSuggestionsProvider;
78 using ntp_snippets::CategoryFactory; 79 using ntp_snippets::CategoryFactory;
79 using ntp_snippets::ContentSuggestionsService; 80 using ntp_snippets::ContentSuggestionsService;
80 using ntp_snippets::ForeignSessionsSuggestionsProvider; 81 using ntp_snippets::ForeignSessionsSuggestionsProvider;
81 using ntp_snippets::NTPSnippetsFetcher; 82 using ntp_snippets::NTPSnippetsFetcher;
82 using ntp_snippets::NTPSnippetsScheduler; 83 using ntp_snippets::PersistentScheduler;
83 using ntp_snippets::RemoteSuggestionsDatabase; 84 using ntp_snippets::RemoteSuggestionsDatabase;
84 using ntp_snippets::RemoteSuggestionsProvider; 85 using ntp_snippets::RemoteSuggestionsProviderImpl;
85 using ntp_snippets::RemoteSuggestionsStatusService; 86 using ntp_snippets::RemoteSuggestionsStatusService;
87 using ntp_snippets::SchedulingRemoteSuggestionsProvider;
86 using ntp_snippets::TabDelegateSyncAdapter; 88 using ntp_snippets::TabDelegateSyncAdapter;
87 using suggestions::ImageDecoderImpl; 89 using suggestions::ImageDecoderImpl;
88 using syncer::SyncService; 90 using syncer::SyncService;
89 using translate::LanguageModel; 91 using translate::LanguageModel;
90 92
91 namespace { 93 namespace {
92 94
93 // Clear the tasks that can be scheduled by running services. 95 // Clear the tasks that can be scheduled by running services.
94 void ClearScheduledTasks() { 96 void ClearScheduledTasks() {
95 #if defined(OS_ANDROID) 97 #if defined(OS_ANDROID)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 OAuth2TokenService* token_service, 148 OAuth2TokenService* token_service,
147 ContentSuggestionsService* service, 149 ContentSuggestionsService* service,
148 CategoryFactory* category_factory, 150 CategoryFactory* category_factory,
149 LanguageModel* language_model, 151 LanguageModel* language_model,
150 PrefService* pref_service, 152 PrefService* pref_service,
151 Profile* profile) { 153 Profile* profile) {
152 scoped_refptr<net::URLRequestContextGetter> request_context = 154 scoped_refptr<net::URLRequestContextGetter> request_context =
153 content::BrowserContext::GetDefaultStoragePartition(profile) 155 content::BrowserContext::GetDefaultStoragePartition(profile)
154 ->GetURLRequestContext(); 156 ->GetURLRequestContext();
155 157
156 NTPSnippetsScheduler* scheduler = nullptr;
157 #if defined(OS_ANDROID)
158 scheduler = NTPSnippetsLauncher::Get();
159 #endif // OS_ANDROID
160 base::FilePath database_dir( 158 base::FilePath database_dir(
161 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); 159 profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
162 scoped_refptr<base::SequencedTaskRunner> task_runner = 160 scoped_refptr<base::SequencedTaskRunner> task_runner =
163 BrowserThread::GetBlockingPool() 161 BrowserThread::GetBlockingPool()
164 ->GetSequencedTaskRunnerWithShutdownBehavior( 162 ->GetSequencedTaskRunnerWithShutdownBehavior(
165 base::SequencedWorkerPool::GetSequenceToken(), 163 base::SequencedWorkerPool::GetSequenceToken(),
166 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 164 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
167 bool is_stable_channel = 165 bool is_stable_channel =
168 chrome::GetChannel() == version_info::Channel::STABLE; 166 chrome::GetChannel() == version_info::Channel::STABLE;
169 auto provider = base::MakeUnique<RemoteSuggestionsProvider>( 167 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>(
170 service, service->category_factory(), pref_service, 168 service, service->category_factory(), pref_service,
171 g_browser_process->GetApplicationLocale(), service->user_classifier(), 169 g_browser_process->GetApplicationLocale(),
172 scheduler, base::MakeUnique<NTPSnippetsFetcher>( 170 base::MakeUnique<NTPSnippetsFetcher>(
173 signin_manager, token_service, request_context, 171 signin_manager, token_service, request_context, pref_service,
174 pref_service, category_factory, language_model, 172 category_factory, language_model,
175 base::Bind(&safe_json::SafeJsonParser::Parse), 173 base::Bind(&safe_json::SafeJsonParser::Parse),
176 is_stable_channel ? google_apis::GetAPIKey() 174 is_stable_channel ? google_apis::GetAPIKey()
177 : google_apis::GetNonStableAPIKey(), 175 : google_apis::GetNonStableAPIKey(),
178 service->user_classifier()), 176 service->user_classifier()),
179 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), 177 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(),
180 request_context.get()), 178 request_context.get()),
181 base::MakeUnique<ImageDecoderImpl>(), 179 base::MakeUnique<ImageDecoderImpl>(),
182 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), 180 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner),
183 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, 181 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager,
184 pref_service)); 182 pref_service));
185 service->set_ntp_snippets_service(provider.get()); 183 service->set_remote_suggestions_provider(provider.get());
186 service->RegisterProvider(std::move(provider)); 184
185 PersistentScheduler* scheduler = nullptr;
186 #if defined(OS_ANDROID)
187 scheduler = NTPSnippetsLauncher::Get();
188 #endif // OS_ANDROID
189
190 auto scheduling_provider =
191 base::MakeUnique<SchedulingRemoteSuggestionsProvider>(
192 service, category_factory, std::move(provider), scheduler,
193 service->user_classifier(), pref_service);
194 service->set_remote_suggestions_scheduler(scheduling_provider.get());
195 service->RegisterProvider(std::move(scheduling_provider));
187 } 196 }
188 197
189 void RegisterForeignSessionsProvider(SyncService* sync_service, 198 void RegisterForeignSessionsProvider(SyncService* sync_service,
190 ContentSuggestionsService* service, 199 ContentSuggestionsService* service,
191 CategoryFactory* category_factory, 200 CategoryFactory* category_factory,
192 PrefService* pref_service) { 201 PrefService* pref_service) {
193 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 202 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
194 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 203 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
195 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( 204 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>(
196 service, category_factory, std::move(sync_adapter), pref_service); 205 service, category_factory, std::move(sync_adapter), pref_service);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 328 }
320 329
321 if (base::FeatureList::IsEnabled( 330 if (base::FeatureList::IsEnabled(
322 ntp_snippets::kForeignSessionsSuggestionsFeature)) { 331 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
323 RegisterForeignSessionsProvider(sync_service, service, category_factory, 332 RegisterForeignSessionsProvider(sync_service, service, category_factory,
324 pref_service); 333 pref_service);
325 } 334 }
326 335
327 return service; 336 return service;
328 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698