| OLD | NEW |
| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 registry->RegisterListPref(prefs::kSnippetHosts); | 211 registry->RegisterListPref(prefs::kSnippetHosts); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void NTPSnippetsService::Init(bool enabled) { | 214 void NTPSnippetsService::Init(bool enabled) { |
| 215 DCHECK(state_ == State::NOT_INITED); | 215 DCHECK(state_ == State::NOT_INITED); |
| 216 state_ = State::INITED; | 216 state_ = State::INITED; |
| 217 | 217 |
| 218 enabled_ = enabled; | 218 enabled_ = enabled; |
| 219 if (enabled_) { | 219 if (enabled_) { |
| 220 // |suggestions_service_| can be null in tests. | 220 // |suggestions_service_| can be null in tests. |
| 221 if (snippets_fetcher_->UseHostRestriction() && suggestions_service_) { | 221 if (snippets_fetcher_->UsesHostRestrictions() && suggestions_service_) { |
| 222 suggestions_service_subscription_ = suggestions_service_->AddCallback( | 222 suggestions_service_subscription_ = suggestions_service_->AddCallback( |
| 223 base::Bind(&NTPSnippetsService::OnSuggestionsChanged, | 223 base::Bind(&NTPSnippetsService::OnSuggestionsChanged, |
| 224 base::Unretained(this))); | 224 base::Unretained(this))); |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Get any existing snippets immediately from prefs. | 227 // Get any existing snippets immediately from prefs. |
| 228 LoadDiscardedSnippetsFromPrefs(); | 228 LoadDiscardedSnippetsFromPrefs(); |
| 229 LoadSnippetsFromPrefs(); | 229 LoadSnippetsFromPrefs(); |
| 230 | 230 |
| 231 // If we don't have any snippets yet, start a fetch. | 231 // If we don't have any snippets yet, start a fetch. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 if (snippet->expiry_date() < next_expiry) | 542 if (snippet->expiry_date() < next_expiry) |
| 543 next_expiry = snippet->expiry_date(); | 543 next_expiry = snippet->expiry_date(); |
| 544 } | 544 } |
| 545 DCHECK_GT(next_expiry, expiry); | 545 DCHECK_GT(next_expiry, expiry); |
| 546 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, | 546 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, |
| 547 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished, | 547 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished, |
| 548 base::Unretained(this))); | 548 base::Unretained(this))); |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace ntp_snippets | 551 } // namespace ntp_snippets |
| OLD | NEW |