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

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

Issue 1997473004: Snippets are enabled when search suggestions are enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 6 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
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" 12 #include "chrome/browser/search/suggestions/image_fetcher_impl.h"
12 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 13 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h" 15 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/browser/sync/profile_sync_service_factory.h" 16 #include "chrome/browser/sync/profile_sync_service_factory.h"
16 #include "chrome/common/channel_info.h" 17 #include "chrome/common/channel_info.h"
18 #include "chrome/common/pref_names.h"
17 #include "components/browser_sync/browser/profile_sync_service.h" 19 #include "components/browser_sync/browser/profile_sync_service.h"
18 #include "components/image_fetcher/image_fetcher.h" 20 #include "components/image_fetcher/image_fetcher.h"
19 #include "components/keyed_service/content/browser_context_dependency_manager.h" 21 #include "components/keyed_service/content/browser_context_dependency_manager.h"
20 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 22 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
21 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 23 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
22 #include "components/ntp_snippets/ntp_snippets_service.h" 24 #include "components/ntp_snippets/ntp_snippets_service.h"
25 #include "components/prefs/pref_service.h"
23 #include "components/safe_json/safe_json_parser.h" 26 #include "components/safe_json/safe_json_parser.h"
24 #include "components/signin/core/browser/profile_oauth2_token_service.h" 27 #include "components/signin/core/browser/profile_oauth2_token_service.h"
25 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
26 #include "components/version_info/version_info.h" 29 #include "components/version_info/version_info.h"
27 #include "content/public/browser/browser_context.h" 30 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/storage_partition.h" 32 #include "content/public/browser/storage_partition.h"
30 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
31 34
32 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
36 #include "chrome/browser/android/chrome_feature_list.h"
33 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" 37 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h"
34 #endif // OS_ANDROID 38 #endif // OS_ANDROID
35 39
36 using content::BrowserThread; 40 using content::BrowserThread;
37 using suggestions::ImageFetcherImpl; 41 using suggestions::ImageFetcherImpl;
38 using suggestions::SuggestionsService; 42 using suggestions::SuggestionsService;
39 using suggestions::SuggestionsServiceFactory; 43 using suggestions::SuggestionsServiceFactory;
40 44
41 // static 45 // static
42 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { 46 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() {
(...skipping 16 matching lines...) Expand all
59 DependsOn(ProfileSyncServiceFactory::GetInstance()); 63 DependsOn(ProfileSyncServiceFactory::GetInstance());
60 DependsOn(SigninManagerFactory::GetInstance()); 64 DependsOn(SigninManagerFactory::GetInstance());
61 DependsOn(SuggestionsServiceFactory::GetInstance()); 65 DependsOn(SuggestionsServiceFactory::GetInstance());
62 } 66 }
63 67
64 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} 68 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {}
65 69
66 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( 70 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor(
67 content::BrowserContext* context) const { 71 content::BrowserContext* context) const {
68 Profile* profile = Profile::FromBrowserContext(context); 72 Profile* profile = Profile::FromBrowserContext(context);
73
74 // TODO(mvanouwerkerk): Move the enable logic into the service once we start
75 // observing pref changes.
76 bool enabled = profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled);
77 #if defined(OS_ANDROID)
78 enabled = enabled &&
79 base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature);
80 #endif // OS_ANDROID
81
69 SigninManagerBase* signin_manager = 82 SigninManagerBase* signin_manager =
70 SigninManagerFactory::GetForProfile(profile); 83 SigninManagerFactory::GetForProfile(profile);
71 OAuth2TokenService* token_service = 84 OAuth2TokenService* token_service =
72 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 85 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
73 scoped_refptr<net::URLRequestContextGetter> request_context = 86 scoped_refptr<net::URLRequestContextGetter> request_context =
74 content::BrowserContext::GetDefaultStoragePartition(context)-> 87 content::BrowserContext::GetDefaultStoragePartition(context)->
75 GetURLRequestContext(); 88 GetURLRequestContext();
76 ProfileSyncService* sync_service = 89 ProfileSyncService* sync_service =
77 ProfileSyncServiceFactory::GetForProfile(profile); 90 ProfileSyncServiceFactory::GetForProfile(profile);
78 SuggestionsService* suggestions_service = 91 SuggestionsService* suggestions_service =
79 SuggestionsServiceFactory::GetForProfile(profile); 92 SuggestionsServiceFactory::GetForProfile(profile);
80 93
81 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; 94 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr;
82 #if defined(OS_ANDROID) 95 #if defined(OS_ANDROID)
83 scheduler = NTPSnippetsLauncher::Get(); 96 scheduler = NTPSnippetsLauncher::Get();
84 #endif // OS_ANDROID 97 #endif // OS_ANDROID
85 98
86 scoped_refptr<base::SequencedTaskRunner> task_runner = 99 scoped_refptr<base::SequencedTaskRunner> task_runner =
87 BrowserThread::GetBlockingPool() 100 BrowserThread::GetBlockingPool()
88 ->GetSequencedTaskRunnerWithShutdownBehavior( 101 ->GetSequencedTaskRunnerWithShutdownBehavior(
89 base::SequencedWorkerPool::GetSequenceToken(), 102 base::SequencedWorkerPool::GetSequenceToken(),
90 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 103 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
91 104
92 return new ntp_snippets::NTPSnippetsService( 105 return new ntp_snippets::NTPSnippetsService(
93 profile->GetPrefs(), sync_service, suggestions_service, task_runner, 106 enabled, profile->GetPrefs(), sync_service, suggestions_service,
94 g_browser_process->GetApplicationLocale(), scheduler, 107 task_runner, g_browser_process->GetApplicationLocale(), scheduler,
95 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher( 108 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher(
96 signin_manager, token_service, request_context, 109 signin_manager, token_service, request_context,
97 base::Bind(&safe_json::SafeJsonParser::Parse), 110 base::Bind(&safe_json::SafeJsonParser::Parse),
98 chrome::GetChannel() == version_info::Channel::STABLE)), 111 chrome::GetChannel() == version_info::Channel::STABLE)),
99 base::WrapUnique(new ImageFetcherImpl(request_context.get()))); 112 base::WrapUnique(new ImageFetcherImpl(request_context.get())));
100 } 113 }
OLDNEW
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698