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

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: Make unit-tests pass 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"
38 #include "components/ntp_snippets/remote/remote_suggestions_database.h" 37 #include "components/ntp_snippets/remote/remote_suggestions_database.h"
38 #include "components/ntp_snippets/remote/remote_suggestions_hard_scheduler.h"
39 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 39 #include "components/ntp_snippets/remote/remote_suggestions_provider.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/sessions/foreign_sessions_suggestions_provider .h" 41 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h"
42 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" 42 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h"
43 #include "components/prefs/pref_service.h" 43 #include "components/prefs/pref_service.h"
44 #include "components/safe_json/safe_json_parser.h" 44 #include "components/safe_json/safe_json_parser.h"
45 #include "components/signin/core/browser/profile_oauth2_token_service.h" 45 #include "components/signin/core/browser/profile_oauth2_token_service.h"
46 #include "components/signin/core/browser/signin_manager.h" 46 #include "components/signin/core/browser/signin_manager.h"
47 #include "components/translate/core/browser/language_model.h" 47 #include "components/translate/core/browser/language_model.h"
48 #include "components/version_info/version_info.h" 48 #include "components/version_info/version_info.h"
(...skipping 23 matching lines...) Expand all
72 72
73 using bookmarks::BookmarkModel; 73 using bookmarks::BookmarkModel;
74 using content::BrowserThread; 74 using content::BrowserThread;
75 using history::HistoryService; 75 using history::HistoryService;
76 using image_fetcher::ImageFetcherImpl; 76 using image_fetcher::ImageFetcherImpl;
77 using ntp_snippets::BookmarkSuggestionsProvider; 77 using ntp_snippets::BookmarkSuggestionsProvider;
78 using ntp_snippets::CategoryFactory; 78 using ntp_snippets::CategoryFactory;
79 using ntp_snippets::ContentSuggestionsService; 79 using ntp_snippets::ContentSuggestionsService;
80 using ntp_snippets::ForeignSessionsSuggestionsProvider; 80 using ntp_snippets::ForeignSessionsSuggestionsProvider;
81 using ntp_snippets::NTPSnippetsFetcher; 81 using ntp_snippets::NTPSnippetsFetcher;
82 using ntp_snippets::NTPSnippetsScheduler;
83 using ntp_snippets::RemoteSuggestionsDatabase; 82 using ntp_snippets::RemoteSuggestionsDatabase;
83 using ntp_snippets::RemoteSuggestionsHardScheduler;
84 using ntp_snippets::RemoteSuggestionsProvider; 84 using ntp_snippets::RemoteSuggestionsProvider;
85 using ntp_snippets::RemoteSuggestionsStatusService; 85 using ntp_snippets::RemoteSuggestionsStatusService;
86 using ntp_snippets::TabDelegateSyncAdapter; 86 using ntp_snippets::TabDelegateSyncAdapter;
87 using suggestions::ImageDecoderImpl; 87 using suggestions::ImageDecoderImpl;
88 using syncer::SyncService; 88 using syncer::SyncService;
89 using translate::LanguageModel; 89 using translate::LanguageModel;
90 90
91 namespace { 91 namespace {
92 92
93 // Clear the tasks that can be scheduled by running services. 93 // Clear the tasks that can be scheduled by running services.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 OAuth2TokenService* token_service, 145 OAuth2TokenService* token_service,
146 ContentSuggestionsService* service, 146 ContentSuggestionsService* service,
147 CategoryFactory* category_factory, 147 CategoryFactory* category_factory,
148 LanguageModel* language_model, 148 LanguageModel* language_model,
149 PrefService* pref_service, 149 PrefService* pref_service,
150 Profile* profile) { 150 Profile* profile) {
151 scoped_refptr<net::URLRequestContextGetter> request_context = 151 scoped_refptr<net::URLRequestContextGetter> request_context =
152 content::BrowserContext::GetDefaultStoragePartition(profile) 152 content::BrowserContext::GetDefaultStoragePartition(profile)
153 ->GetURLRequestContext(); 153 ->GetURLRequestContext();
154 154
155 NTPSnippetsScheduler* scheduler = nullptr; 155 RemoteSuggestionsHardScheduler* scheduler = nullptr;
156 #if defined(OS_ANDROID) 156 #if defined(OS_ANDROID)
157 scheduler = NTPSnippetsLauncher::Get(); 157 scheduler = NTPSnippetsLauncher::Get();
158 #endif // OS_ANDROID 158 #endif // OS_ANDROID
159 base::FilePath database_dir( 159 base::FilePath database_dir(
160 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); 160 profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
161 scoped_refptr<base::SequencedTaskRunner> task_runner = 161 scoped_refptr<base::SequencedTaskRunner> task_runner =
162 BrowserThread::GetBlockingPool() 162 BrowserThread::GetBlockingPool()
163 ->GetSequencedTaskRunnerWithShutdownBehavior( 163 ->GetSequencedTaskRunnerWithShutdownBehavior(
164 base::SequencedWorkerPool::GetSequenceToken(), 164 base::SequencedWorkerPool::GetSequenceToken(),
165 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 165 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
166 bool is_stable_channel = 166 bool is_stable_channel =
167 chrome::GetChannel() == version_info::Channel::STABLE; 167 chrome::GetChannel() == version_info::Channel::STABLE;
168 auto provider = base::MakeUnique<RemoteSuggestionsProvider>( 168 auto provider = base::MakeUnique<RemoteSuggestionsProvider>(
169 service, service->category_factory(), pref_service, 169 service, service->category_factory(), pref_service,
170 g_browser_process->GetApplicationLocale(), service->user_classifier(), 170 g_browser_process->GetApplicationLocale(), service->user_classifier(),
171 scheduler, base::MakeUnique<NTPSnippetsFetcher>( 171 scheduler, base::MakeUnique<NTPSnippetsFetcher>(
172 signin_manager, token_service, request_context, 172 signin_manager, token_service, request_context,
173 pref_service, category_factory, language_model, 173 pref_service, category_factory, language_model,
174 base::Bind(&safe_json::SafeJsonParser::Parse), 174 base::Bind(&safe_json::SafeJsonParser::Parse),
175 is_stable_channel ? google_apis::GetAPIKey() 175 is_stable_channel ? google_apis::GetAPIKey()
176 : google_apis::GetNonStableAPIKey(), 176 : google_apis::GetNonStableAPIKey(),
177 service->user_classifier()), 177 service->user_classifier()),
178 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), 178 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(),
179 request_context.get()), 179 request_context.get()),
180 base::MakeUnique<ImageDecoderImpl>(), 180 base::MakeUnique<ImageDecoderImpl>(),
181 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), 181 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner),
182 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, 182 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager,
183 pref_service)); 183 pref_service));
184 service->set_ntp_snippets_service(provider.get()); 184 service->set_remote_suggestions_provider(provider.get());
185 service->RegisterProvider(std::move(provider)); 185 service->RegisterProvider(std::move(provider));
186 } 186 }
187 187
188 void RegisterForeignSessionsProvider(SyncService* sync_service, 188 void RegisterForeignSessionsProvider(SyncService* sync_service,
189 ContentSuggestionsService* service, 189 ContentSuggestionsService* service,
190 CategoryFactory* category_factory, 190 CategoryFactory* category_factory,
191 PrefService* pref_service) { 191 PrefService* pref_service) {
192 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 192 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
193 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 193 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
194 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( 194 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>(
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 318 }
319 319
320 if (base::FeatureList::IsEnabled( 320 if (base::FeatureList::IsEnabled(
321 ntp_snippets::kForeignSessionsSuggestionsFeature)) { 321 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
322 RegisterForeignSessionsProvider(sync_service, service, category_factory, 322 RegisterForeignSessionsProvider(sync_service, service, category_factory,
323 pref_service); 323 pref_service);
324 } 324 }
325 325
326 return service; 326 return service;
327 } 327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698