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

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2145563002: Add ContentSuggestionsService to SnippetsInternals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@articleprovider2
Patch Set: Refactor NTPSnippetsService::UpdateStateForStatus switch statement 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
« no previous file with comments | « chrome/browser/ui/webui/snippets_internals_message_handler.cc ('k') | no next file » | 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 "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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 snippets_status_service_->Init(base::Bind( 693 snippets_status_service_->Init(base::Bind(
694 &NTPSnippetsService::UpdateStateForStatus, base::Unretained(this))); 694 &NTPSnippetsService::UpdateStateForStatus, base::Unretained(this)));
695 695
696 NotifyNewSuggestions(); 696 NotifyNewSuggestions();
697 } 697 }
698 698
699 void NTPSnippetsService::UpdateStateForStatus(DisabledReason disabled_reason) { 699 void NTPSnippetsService::UpdateStateForStatus(DisabledReason disabled_reason) {
700 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, 700 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_,
701 NTPSnippetsServiceDisabledReasonChanged(disabled_reason)); 701 NTPSnippetsServiceDisabledReasonChanged(disabled_reason));
702 702
703 State new_state;
704 ContentSuggestionsCategoryStatus new_status;
705 switch (disabled_reason) { 703 switch (disabled_reason) {
706 case DisabledReason::NONE: 704 case DisabledReason::NONE:
707 new_state = State::READY; 705 EnterState(State::READY, ContentSuggestionsCategoryStatus::AVAILABLE);
708 new_status = ContentSuggestionsCategoryStatus::AVAILABLE;
709 break; 706 break;
710 707
711 case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN: 708 case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN:
712 // HistorySync is not initialized yet, so we don't know what the actual 709 // HistorySync is not initialized yet, so we don't know what the actual
713 // state is and we just return the current one. If things change, 710 // state is and we just return the current one. If things change,
714 // |OnStateChanged| will call this function again to update the state. 711 // |OnStateChanged| will call this function again to update the state.
715 DVLOG(1) << "Sync configuration incomplete, continuing based on the " 712 DVLOG(1) << "Sync configuration incomplete, continuing based on the "
716 "current state."; 713 "current state.";
717 new_state = state_; 714 EnterState(state_, ContentSuggestionsCategoryStatus::INITIALIZING);
718 new_status = ContentSuggestionsCategoryStatus::INITIALIZING;
719 break; 715 break;
720 716
721 case DisabledReason::EXPLICITLY_DISABLED: 717 case DisabledReason::EXPLICITLY_DISABLED:
722 new_state = State::DISABLED; 718 EnterState(
723 new_status = 719 State::DISABLED,
724 ContentSuggestionsCategoryStatus::CATEGORY_EXPLICITLY_DISABLED; 720 ContentSuggestionsCategoryStatus::CATEGORY_EXPLICITLY_DISABLED);
725 break; 721 break;
726 722
727 case DisabledReason::SIGNED_OUT: 723 case DisabledReason::SIGNED_OUT:
728 new_state = State::DISABLED; 724 EnterState(State::DISABLED, ContentSuggestionsCategoryStatus::SIGNED_OUT);
729 new_status = ContentSuggestionsCategoryStatus::SIGNED_OUT;
730 break; 725 break;
731 726
732 case DisabledReason::SYNC_DISABLED: 727 case DisabledReason::SYNC_DISABLED:
733 new_state = State::DISABLED; 728 EnterState(State::DISABLED,
734 new_status = ContentSuggestionsCategoryStatus::SYNC_DISABLED; 729 ContentSuggestionsCategoryStatus::SYNC_DISABLED);
735 break; 730 break;
736 731
737 case DisabledReason::PASSPHRASE_ENCRYPTION_ENABLED: 732 case DisabledReason::PASSPHRASE_ENCRYPTION_ENABLED:
738 new_state = State::DISABLED; 733 EnterState(
739 new_status = 734 State::DISABLED,
740 ContentSuggestionsCategoryStatus::PASSPHRASE_ENCRYPTION_ENABLED; 735 ContentSuggestionsCategoryStatus::PASSPHRASE_ENCRYPTION_ENABLED);
741 break; 736 break;
742 737
743 case DisabledReason::HISTORY_SYNC_DISABLED: 738 case DisabledReason::HISTORY_SYNC_DISABLED:
744 new_state = State::DISABLED; 739 EnterState(State::DISABLED,
745 new_status = ContentSuggestionsCategoryStatus::HISTORY_SYNC_DISABLED; 740 ContentSuggestionsCategoryStatus::HISTORY_SYNC_DISABLED);
746 break;
747
748 default:
749 // All cases should be handled by the above switch
750 NOTREACHED();
751 new_state = State::DISABLED;
752 new_status = ContentSuggestionsCategoryStatus::LOADING_ERROR;
753 break; 741 break;
754 } 742 }
755
756 EnterState(new_state, new_status);
757 } 743 }
758 744
759 void NTPSnippetsService::EnterState(State state, 745 void NTPSnippetsService::EnterState(State state,
760 ContentSuggestionsCategoryStatus status) { 746 ContentSuggestionsCategoryStatus status) {
761 if (status != category_status_) { 747 if (status != category_status_) {
762 category_status_ = status; 748 category_status_ = status;
763 NotifyCategoryStatusChanged(); 749 NotifyCategoryStatusChanged();
764 } 750 }
765 751
766 if (state == state_) 752 if (state == state_)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 } 813 }
828 814
829 void NTPSnippetsService::NotifyCategoryStatusChanged() { 815 void NTPSnippetsService::NotifyCategoryStatusChanged() {
830 if (observer_) { 816 if (observer_) {
831 observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::ARTICLES, 817 observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::ARTICLES,
832 category_status_); 818 category_status_);
833 } 819 }
834 } 820 }
835 821
836 } // namespace ntp_snippets 822 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/snippets_internals_message_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698