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

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.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. Add a TODO. Created 4 years, 7 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 "components/ntp_snippets/ntp_snippets_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 void WrapImageFetchedCallback( 178 void WrapImageFetchedCallback(
179 const NTPSnippetsService::ImageFetchedCallback& callback, 179 const NTPSnippetsService::ImageFetchedCallback& callback,
180 const GURL& snippet_id_url, 180 const GURL& snippet_id_url,
181 const gfx::Image& image) { 181 const gfx::Image& image) {
182 callback.Run(snippet_id_url.spec(), image); 182 callback.Run(snippet_id_url.spec(), image);
183 } 183 }
184 184
185 } // namespace 185 } // namespace
186 186
187 NTPSnippetsService::NTPSnippetsService( 187 NTPSnippetsService::NTPSnippetsService(
188 bool enabled,
188 PrefService* pref_service, 189 PrefService* pref_service,
189 SuggestionsService* suggestions_service, 190 SuggestionsService* suggestions_service,
190 scoped_refptr<base::SequencedTaskRunner> file_task_runner, 191 scoped_refptr<base::SequencedTaskRunner> file_task_runner,
191 const std::string& application_language_code, 192 const std::string& application_language_code,
192 NTPSnippetsScheduler* scheduler, 193 NTPSnippetsScheduler* scheduler,
193 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, 194 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher,
194 std::unique_ptr<ImageFetcher> image_fetcher) 195 std::unique_ptr<ImageFetcher> image_fetcher)
195 : state_(State::NOT_INITED), 196 : state_(State::NOT_INITED),
196 enabled_(false), 197 enabled_(enabled),
197 pref_service_(pref_service), 198 pref_service_(pref_service),
198 suggestions_service_(suggestions_service), 199 suggestions_service_(suggestions_service),
199 file_task_runner_(file_task_runner), 200 file_task_runner_(file_task_runner),
200 application_language_code_(application_language_code), 201 application_language_code_(application_language_code),
201 scheduler_(scheduler), 202 scheduler_(scheduler),
202 snippets_fetcher_(std::move(snippets_fetcher)), 203 snippets_fetcher_(std::move(snippets_fetcher)),
203 image_fetcher_(std::move(image_fetcher)) { 204 image_fetcher_(std::move(image_fetcher)) {
204 snippets_fetcher_->SetCallback(base::Bind( 205 snippets_fetcher_->SetCallback(base::Bind(
205 &NTPSnippetsService::OnFetchFinished, base::Unretained(this))); 206 &NTPSnippetsService::OnFetchFinished, base::Unretained(this)));
206 } 207 }
207 208
208 NTPSnippetsService::~NTPSnippetsService() { 209 NTPSnippetsService::~NTPSnippetsService() {
209 DCHECK(state_ == State::NOT_INITED || state_ == State::SHUT_DOWN); 210 DCHECK(state_ == State::NOT_INITED || state_ == State::SHUT_DOWN);
210 } 211 }
211 212
212 // static 213 // static
213 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { 214 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
214 registry->RegisterListPref(prefs::kSnippets); 215 registry->RegisterListPref(prefs::kSnippets);
215 registry->RegisterListPref(prefs::kDiscardedSnippets); 216 registry->RegisterListPref(prefs::kDiscardedSnippets);
216 registry->RegisterListPref(prefs::kSnippetHosts); 217 registry->RegisterListPref(prefs::kSnippetHosts);
217 } 218 }
218 219
219 void NTPSnippetsService::Init(bool enabled) { 220 void NTPSnippetsService::Init() {
220 DCHECK(state_ == State::NOT_INITED); 221 DCHECK(state_ == State::NOT_INITED);
221 state_ = State::INITED; 222 state_ = State::INITED;
222 223
223 enabled_ = enabled;
224 if (enabled_) { 224 if (enabled_) {
225 // |suggestions_service_| can be null in tests. 225 // |suggestions_service_| can be null in tests.
226 if (snippets_fetcher_->UsesHostRestrictions() && suggestions_service_) { 226 if (snippets_fetcher_->UsesHostRestrictions() && suggestions_service_) {
227 suggestions_service_subscription_ = suggestions_service_->AddCallback( 227 suggestions_service_subscription_ = suggestions_service_->AddCallback(
228 base::Bind(&NTPSnippetsService::OnSuggestionsChanged, 228 base::Bind(&NTPSnippetsService::OnSuggestionsChanged,
229 base::Unretained(this))); 229 base::Unretained(this)));
230 } 230 }
231 231
232 // Get any existing snippets immediately from prefs. 232 // Get any existing snippets immediately from prefs.
233 LoadDiscardedSnippetsFromPrefs(); 233 LoadDiscardedSnippetsFromPrefs();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (snippet->expiry_date() < next_expiry) 548 if (snippet->expiry_date() < next_expiry)
549 next_expiry = snippet->expiry_date(); 549 next_expiry = snippet->expiry_date();
550 } 550 }
551 DCHECK_GT(next_expiry, expiry); 551 DCHECK_GT(next_expiry, expiry);
552 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, 552 expiry_timer_.Start(FROM_HERE, next_expiry - expiry,
553 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished, 553 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished,
554 base::Unretained(this))); 554 base::Unretained(this)));
555 } 555 }
556 556
557 } // namespace ntp_snippets 557 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698