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

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

Issue 2131943002: Change NTPSnippetsService to implement ContentSuggestionsProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@neuerservice2
Patch Set: Insert the default-case again because some compilers need it Created 4 years, 5 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
OLDNEW
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 "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" 5 #include "chrome/browser/ntp_snippets/ntp_snippets_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/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 14 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
14 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 15 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h" 18 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/common/channel_info.h" 19 #include "chrome/common/channel_info.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "components/browser_sync/browser/profile_sync_service.h" 21 #include "components/browser_sync/browser/profile_sync_service.h"
21 #include "components/image_fetcher/image_decoder.h" 22 #include "components/image_fetcher/image_decoder.h"
22 #include "components/image_fetcher/image_fetcher.h" 23 #include "components/image_fetcher/image_fetcher.h"
23 #include "components/image_fetcher/image_fetcher_impl.h" 24 #include "components/image_fetcher/image_fetcher_impl.h"
24 #include "components/keyed_service/content/browser_context_dependency_manager.h" 25 #include "components/keyed_service/content/browser_context_dependency_manager.h"
26 #include "components/ntp_snippets/content_suggestions_service.h"
25 #include "components/ntp_snippets/ntp_snippets_constants.h" 27 #include "components/ntp_snippets/ntp_snippets_constants.h"
26 #include "components/ntp_snippets/ntp_snippets_database.h" 28 #include "components/ntp_snippets/ntp_snippets_database.h"
27 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 29 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
28 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 30 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
29 #include "components/ntp_snippets/ntp_snippets_service.h" 31 #include "components/ntp_snippets/ntp_snippets_service.h"
30 #include "components/ntp_snippets/ntp_snippets_status_service.h" 32 #include "components/ntp_snippets/ntp_snippets_status_service.h"
31 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
32 #include "components/safe_json/safe_json_parser.h" 34 #include "components/safe_json/safe_json_parser.h"
33 #include "components/signin/core/browser/profile_oauth2_token_service.h" 35 #include "components/signin/core/browser/profile_oauth2_token_service.h"
34 #include "components/signin/core/browser/signin_manager.h" 36 #include "components/signin/core/browser/signin_manager.h"
35 #include "components/version_info/version_info.h" 37 #include "components/version_info/version_info.h"
36 #include "content/public/browser/browser_context.h" 38 #include "content/public/browser/browser_context.h"
37 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/storage_partition.h" 40 #include "content/public/browser/storage_partition.h"
39 #include "net/url_request/url_request_context_getter.h" 41 #include "net/url_request/url_request_context_getter.h"
40 42
41 #if defined(OS_ANDROID) 43 #if defined(OS_ANDROID)
42 #include "chrome/browser/android/chrome_feature_list.h" 44 #include "chrome/browser/android/chrome_feature_list.h"
43 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" 45 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h"
44 #endif // OS_ANDROID 46 #endif // OS_ANDROID
45 47
46 using content::BrowserThread; 48 using content::BrowserThread;
47 using image_fetcher::ImageFetcherImpl; 49 using image_fetcher::ImageFetcherImpl;
48 using suggestions::ImageDecoderImpl; 50 using suggestions::ImageDecoderImpl;
49 using suggestions::SuggestionsService; 51 using suggestions::SuggestionsService;
50 using suggestions::SuggestionsServiceFactory; 52 using suggestions::SuggestionsServiceFactory;
53 using ntp_snippets::ContentSuggestionsService;
51 54
52 // static 55 // static
53 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { 56 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() {
54 return base::Singleton<NTPSnippetsServiceFactory>::get(); 57 return base::Singleton<NTPSnippetsServiceFactory>::get();
55 } 58 }
56 59
57 // static 60 // static
58 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( 61 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile(
59 Profile* profile) { 62 Profile* profile) {
60 DCHECK(!profile->IsOffTheRecord()); 63 DCHECK(!profile->IsOffTheRecord());
61 return static_cast<ntp_snippets::NTPSnippetsService*>( 64 return static_cast<ntp_snippets::NTPSnippetsService*>(
62 GetInstance()->GetServiceForBrowserContext(profile, true)); 65 GetInstance()->GetServiceForBrowserContext(profile, true));
63 } 66 }
64 67
65 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() 68 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory()
66 : BrowserContextKeyedServiceFactory( 69 : BrowserContextKeyedServiceFactory(
67 "NTPSnippetsService", 70 "NTPSnippetsService",
68 BrowserContextDependencyManager::GetInstance()) { 71 BrowserContextDependencyManager::GetInstance()) {
69 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 72 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
70 DependsOn(ProfileSyncServiceFactory::GetInstance()); 73 DependsOn(ProfileSyncServiceFactory::GetInstance());
71 DependsOn(SigninManagerFactory::GetInstance()); 74 DependsOn(SigninManagerFactory::GetInstance());
72 DependsOn(SuggestionsServiceFactory::GetInstance()); 75 DependsOn(SuggestionsServiceFactory::GetInstance());
76 DependsOn(ContentSuggestionsServiceFactory::GetInstance());
73 } 77 }
74 78
75 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} 79 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {}
76 80
77 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( 81 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor(
78 content::BrowserContext* context) const { 82 content::BrowserContext* context) const {
79 Profile* profile = Profile::FromBrowserContext(context); 83 Profile* profile = Profile::FromBrowserContext(context);
80 84
85 ContentSuggestionsService* content_suggestions_service =
86 ContentSuggestionsServiceFactory::GetForProfile(profile);
87 // TODO(pke): When the AndroidBridge does not access the NTPSnippetsService
88 // directly anymore (for retrieving content), the NTPSnippetsService does not
89 // need to be created if content_suggestions_service->state() == DISABLED,
90 // just return nullptr then and remove the other "if" below.
91
81 // TODO(mvanouwerkerk): Move the enable logic into the service once we start 92 // TODO(mvanouwerkerk): Move the enable logic into the service once we start
82 // observing pref changes. 93 // observing pref changes.
83 bool enabled = false; 94 bool enabled = false;
84 #if defined(OS_ANDROID) 95 #if defined(OS_ANDROID)
85 enabled = profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled) && 96 enabled = profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled) &&
86 base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature); 97 base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature);
87 #endif // OS_ANDROID 98 #endif // OS_ANDROID
88 99
89 SigninManagerBase* signin_manager = 100 SigninManagerBase* signin_manager =
90 SigninManagerFactory::GetForProfile(profile); 101 SigninManagerFactory::GetForProfile(profile);
(...skipping 13 matching lines...) Expand all
104 #endif // OS_ANDROID 115 #endif // OS_ANDROID
105 116
106 base::FilePath database_dir( 117 base::FilePath database_dir(
107 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); 118 profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
108 scoped_refptr<base::SequencedTaskRunner> task_runner = 119 scoped_refptr<base::SequencedTaskRunner> task_runner =
109 BrowserThread::GetBlockingPool() 120 BrowserThread::GetBlockingPool()
110 ->GetSequencedTaskRunnerWithShutdownBehavior( 121 ->GetSequencedTaskRunnerWithShutdownBehavior(
111 base::SequencedWorkerPool::GetSequenceToken(), 122 base::SequencedWorkerPool::GetSequenceToken(),
112 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 123 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
113 124
114 return new ntp_snippets::NTPSnippetsService( 125 ntp_snippets::NTPSnippetsService* ntp_snippets_service =
115 enabled, profile->GetPrefs(), suggestions_service, 126 new ntp_snippets::NTPSnippetsService(
116 g_browser_process->GetApplicationLocale(), scheduler, 127 enabled, profile->GetPrefs(), suggestions_service,
117 base::MakeUnique<ntp_snippets::NTPSnippetsFetcher>( 128 g_browser_process->GetApplicationLocale(), scheduler,
118 signin_manager, token_service, request_context, 129 base::MakeUnique<ntp_snippets::NTPSnippetsFetcher>(
119 base::Bind(&safe_json::SafeJsonParser::Parse), 130 signin_manager, token_service, request_context,
120 chrome::GetChannel() == version_info::Channel::STABLE), 131 base::Bind(&safe_json::SafeJsonParser::Parse),
121 base::MakeUnique<ImageFetcherImpl>( 132 chrome::GetChannel() == version_info::Channel::STABLE),
122 base::MakeUnique<ImageDecoderImpl>(), request_context.get()), 133 base::MakeUnique<ImageFetcherImpl>(
123 base::MakeUnique<ImageDecoderImpl>(), 134 base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
124 base::MakeUnique<ntp_snippets::NTPSnippetsDatabase>(database_dir, 135 base::MakeUnique<ImageDecoderImpl>(),
125 task_runner), 136 base::MakeUnique<ntp_snippets::NTPSnippetsDatabase>(database_dir,
126 base::MakeUnique<ntp_snippets::NTPSnippetsStatusService>(signin_manager, 137 task_runner),
127 sync_service)); 138 base::MakeUnique<ntp_snippets::NTPSnippetsStatusService>(
139 signin_manager, sync_service));
140
141 if (content_suggestions_service->state() ==
142 ContentSuggestionsService::State::ENABLED) {
143 content_suggestions_service->RegisterProvider(ntp_snippets_service);
144 }
145 return ntp_snippets_service;
128 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698