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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 base::Unretained(this))); | 230 base::Unretained(this))); |
231 } | 231 } |
232 | 232 |
233 NTPSnippetsService::~NTPSnippetsService() { | 233 NTPSnippetsService::~NTPSnippetsService() { |
234 DCHECK(state_ == State::SHUT_DOWN); | 234 DCHECK(state_ == State::SHUT_DOWN); |
235 } | 235 } |
236 | 236 |
237 // static | 237 // static |
238 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 238 void NTPSnippetsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
239 registry->RegisterListPref(prefs::kSnippetHosts); | 239 registry->RegisterListPref(prefs::kSnippetHosts); |
| 240 |
| 241 NTPSnippetsStatusService::RegisterProfilePrefs(registry); |
240 } | 242 } |
241 | 243 |
242 // Inherited from KeyedService. | 244 // Inherited from KeyedService. |
243 void NTPSnippetsService::Shutdown() { | 245 void NTPSnippetsService::Shutdown() { |
244 EnterState(State::SHUT_DOWN, ContentSuggestionsCategoryStatus::NOT_PROVIDED); | 246 EnterState(State::SHUT_DOWN, ContentSuggestionsCategoryStatus::NOT_PROVIDED); |
245 } | 247 } |
246 | 248 |
247 void NTPSnippetsService::FetchSnippets() { | 249 void NTPSnippetsService::FetchSnippets() { |
248 if (ready()) | 250 if (ready()) |
249 FetchSnippetsFromHosts(GetSuggestionsHosts()); | 251 FetchSnippetsFromHosts(GetSuggestionsHosts()); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 snippets_fetcher_->SetCallback( | 688 snippets_fetcher_->SetCallback( |
687 base::Bind(&NTPSnippetsService::OnFetchFinished, base::Unretained(this))); | 689 base::Bind(&NTPSnippetsService::OnFetchFinished, base::Unretained(this))); |
688 | 690 |
689 // |image_fetcher_| can be null in tests. | 691 // |image_fetcher_| can be null in tests. |
690 if (image_fetcher_) | 692 if (image_fetcher_) |
691 image_fetcher_->SetImageFetcherDelegate(this); | 693 image_fetcher_->SetImageFetcherDelegate(this); |
692 | 694 |
693 // Note: Initializing the status service will run the callback right away with | 695 // Note: Initializing the status service will run the callback right away with |
694 // the current state. | 696 // the current state. |
695 snippets_status_service_->Init(base::Bind( | 697 snippets_status_service_->Init(base::Bind( |
696 &NTPSnippetsService::UpdateStateForStatus, base::Unretained(this))); | 698 &NTPSnippetsService::OnDisabledReasonChanged, base::Unretained(this))); |
697 | 699 |
698 NotifyNewSuggestions(); | 700 NotifyNewSuggestions(); |
699 } | 701 } |
700 | 702 |
701 void NTPSnippetsService::UpdateStateForStatus(DisabledReason disabled_reason) { | 703 void NTPSnippetsService::OnDisabledReasonChanged( |
| 704 DisabledReason disabled_reason) { |
702 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, | 705 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
703 NTPSnippetsServiceDisabledReasonChanged(disabled_reason)); | 706 NTPSnippetsServiceDisabledReasonChanged(disabled_reason)); |
704 | 707 |
705 switch (disabled_reason) { | 708 switch (disabled_reason) { |
706 case DisabledReason::NONE: | 709 case DisabledReason::NONE: |
707 EnterState(State::READY, ContentSuggestionsCategoryStatus::AVAILABLE); | 710 EnterState(State::READY, ContentSuggestionsCategoryStatus::AVAILABLE); |
708 break; | 711 break; |
709 | 712 |
710 case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN: | 713 case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN: |
711 // HistorySync is not initialized yet, so we don't know what the actual | 714 // HistorySync is not initialized yet, so we don't know what the actual |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 818 } |
816 | 819 |
817 void NTPSnippetsService::NotifyCategoryStatusChanged() { | 820 void NTPSnippetsService::NotifyCategoryStatusChanged() { |
818 if (observer_) { | 821 if (observer_) { |
819 observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::ARTICLES, | 822 observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::ARTICLES, |
820 category_status_); | 823 category_status_); |
821 } | 824 } |
822 } | 825 } |
823 | 826 |
824 } // namespace ntp_snippets | 827 } // namespace ntp_snippets |
OLD | NEW |