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

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

Issue 2158373002: [NTP Snippets] Add a pref to disable the NTPSnippetsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/ntp_snippets/content_suggestions_service_factory.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 14 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
15 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 15 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h" 18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/common/channel_info.h" 19 #include "chrome/common/channel_info.h"
20 #include "chrome/common/pref_names.h"
21 #include "components/browser_sync/browser/profile_sync_service.h" 20 #include "components/browser_sync/browser/profile_sync_service.h"
22 #include "components/image_fetcher/image_decoder.h" 21 #include "components/image_fetcher/image_decoder.h"
23 #include "components/image_fetcher/image_fetcher.h" 22 #include "components/image_fetcher/image_fetcher.h"
24 #include "components/image_fetcher/image_fetcher_impl.h" 23 #include "components/image_fetcher/image_fetcher_impl.h"
25 #include "components/keyed_service/content/browser_context_dependency_manager.h" 24 #include "components/keyed_service/content/browser_context_dependency_manager.h"
26 #include "components/ntp_snippets/content_suggestions_service.h" 25 #include "components/ntp_snippets/content_suggestions_service.h"
27 #include "components/ntp_snippets/ntp_snippets_constants.h" 26 #include "components/ntp_snippets/ntp_snippets_constants.h"
28 #include "components/ntp_snippets/ntp_snippets_database.h" 27 #include "components/ntp_snippets/ntp_snippets_database.h"
29 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 28 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
30 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 29 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 content::BrowserContext* context) const { 81 content::BrowserContext* context) const {
83 Profile* profile = Profile::FromBrowserContext(context); 82 Profile* profile = Profile::FromBrowserContext(context);
84 83
85 ContentSuggestionsService* content_suggestions_service = 84 ContentSuggestionsService* content_suggestions_service =
86 ContentSuggestionsServiceFactory::GetForProfile(profile); 85 ContentSuggestionsServiceFactory::GetForProfile(profile);
87 // TODO(pke): When the AndroidBridge does not access the NTPSnippetsService 86 // TODO(pke): When the AndroidBridge does not access the NTPSnippetsService
88 // directly anymore (for retrieving content), the NTPSnippetsService does not 87 // directly anymore (for retrieving content), the NTPSnippetsService does not
89 // need to be created if content_suggestions_service->state() == DISABLED, 88 // need to be created if content_suggestions_service->state() == DISABLED,
90 // just return nullptr then and remove the other "if" below. 89 // just return nullptr then and remove the other "if" below.
91 90
92 // TODO(mvanouwerkerk): Move the enable logic into the service once we start
93 // observing pref changes.
94 bool enabled = false; 91 bool enabled = false;
95 #if defined(OS_ANDROID) 92 #if defined(OS_ANDROID)
96 enabled = profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled) && 93 enabled = base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature);
97 base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature);
98 #endif // OS_ANDROID 94 #endif // OS_ANDROID
99 95
100 SigninManagerBase* signin_manager = 96 SigninManagerBase* signin_manager =
101 SigninManagerFactory::GetForProfile(profile); 97 SigninManagerFactory::GetForProfile(profile);
102 OAuth2TokenService* token_service = 98 OAuth2TokenService* token_service =
103 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 99 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
104 scoped_refptr<net::URLRequestContextGetter> request_context = 100 scoped_refptr<net::URLRequestContextGetter> request_context =
105 content::BrowserContext::GetDefaultStoragePartition(context)-> 101 content::BrowserContext::GetDefaultStoragePartition(context)->
106 GetURLRequestContext(); 102 GetURLRequestContext();
107 ProfileSyncService* sync_service = 103 ProfileSyncService* sync_service =
(...skipping 21 matching lines...) Expand all
129 base::MakeUnique<ntp_snippets::NTPSnippetsFetcher>( 125 base::MakeUnique<ntp_snippets::NTPSnippetsFetcher>(
130 signin_manager, token_service, request_context, 126 signin_manager, token_service, request_context,
131 base::Bind(&safe_json::SafeJsonParser::Parse), 127 base::Bind(&safe_json::SafeJsonParser::Parse),
132 chrome::GetChannel() == version_info::Channel::STABLE), 128 chrome::GetChannel() == version_info::Channel::STABLE),
133 base::MakeUnique<ImageFetcherImpl>( 129 base::MakeUnique<ImageFetcherImpl>(
134 base::MakeUnique<ImageDecoderImpl>(), request_context.get()), 130 base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
135 base::MakeUnique<ImageDecoderImpl>(), 131 base::MakeUnique<ImageDecoderImpl>(),
136 base::MakeUnique<ntp_snippets::NTPSnippetsDatabase>(database_dir, 132 base::MakeUnique<ntp_snippets::NTPSnippetsDatabase>(database_dir,
137 task_runner), 133 task_runner),
138 base::MakeUnique<ntp_snippets::NTPSnippetsStatusService>( 134 base::MakeUnique<ntp_snippets::NTPSnippetsStatusService>(
139 signin_manager, sync_service)); 135 signin_manager, sync_service, profile->GetPrefs()));
140 136
141 if (content_suggestions_service->state() == 137 if (content_suggestions_service->state() ==
142 ContentSuggestionsService::State::ENABLED) { 138 ContentSuggestionsService::State::ENABLED) {
143 content_suggestions_service->RegisterProvider(ntp_snippets_service); 139 content_suggestions_service->RegisterProvider(ntp_snippets_service);
144 } 140 }
145 return ntp_snippets_service; 141 return ntp_snippets_service;
146 } 142 }
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_service.h » ('j') | components/ntp_snippets/ntp_snippets_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698