Chromium Code Reviews| 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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 sync_service_observer_.Add(sync_service_); | 651 sync_service_observer_.Add(sync_service_); |
| 652 | 652 |
| 653 // Change state after we started loading the snippets. During startup, the | 653 // Change state after we started loading the snippets. During startup, the |
| 654 // Sync service might not be completely loaded when we initialize this | 654 // Sync service might not be completely loaded when we initialize this |
| 655 // service, so we might stay in the NOT_INITED state until the sync state is | 655 // service, so we might stay in the NOT_INITED state until the sync state is |
| 656 // updated. See |GetStateForDependenciesStatus|. | 656 // updated. See |GetStateForDependenciesStatus|. |
| 657 EnterState(GetStateForDependenciesStatus()); | 657 EnterState(GetStateForDependenciesStatus()); |
| 658 | 658 |
| 659 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, | 659 FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
| 660 NTPSnippetsServiceLoaded()); | 660 NTPSnippetsServiceLoaded()); |
| 661 | |
| 662 // Start a fetch if we don't have any snippets yet, or a fetch was requested | |
| 663 // earlier. | |
| 664 if (ready() && (snippets_.empty() || fetch_after_load_)) { | |
|
dgn
2016/06/13 17:27:15
redundant, if we transition to ready, we have the
| |
| 665 fetch_after_load_ = false; | |
| 666 FetchSnippets(); | |
| 667 } | |
| 668 } | 661 } |
| 669 | 662 |
| 670 NTPSnippetsService::State NTPSnippetsService::GetStateForDependenciesStatus() { | 663 NTPSnippetsService::State NTPSnippetsService::GetStateForDependenciesStatus() { |
| 671 switch (GetDisabledReason()) { | 664 switch (GetDisabledReason()) { |
| 672 case DisabledReason::NONE: | 665 case DisabledReason::NONE: |
| 673 return State::READY; | 666 return State::READY; |
| 674 | 667 |
| 675 case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN: | 668 case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN: |
| 676 // HistorySync is not initialized yet, so we don't know what the actual | 669 // HistorySync is not initialized yet, so we don't know what the actual |
| 677 // state is and we just return the current one. If things change, | 670 // state is and we just return the current one. If things change, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 698 case State::NOT_INITED: | 691 case State::NOT_INITED: |
| 699 // Initial state, it should not be possible to get back there. | 692 // Initial state, it should not be possible to get back there. |
| 700 NOTREACHED(); | 693 NOTREACHED(); |
| 701 return; | 694 return; |
| 702 | 695 |
| 703 case State::READY: { | 696 case State::READY: { |
| 704 DCHECK(state_ == State::NOT_INITED || state_ == State::DISABLED); | 697 DCHECK(state_ == State::NOT_INITED || state_ == State::DISABLED); |
| 705 | 698 |
| 706 // If the service was previously disabled, we will need to start a fetch | 699 // If the service was previously disabled, we will need to start a fetch |
| 707 // because otherwise there won't be any. | 700 // because otherwise there won't be any. |
| 708 bool fetch_snippets = state_ == State::DISABLED || fetch_after_load_; | 701 bool fetch_snippets = snippets_.empty() || fetch_after_load_; |
| 709 DVLOG(1) << "Entering state: READY"; | 702 DVLOG(1) << "Entering state: READY"; |
| 710 state_ = State::READY; | 703 state_ = State::READY; |
| 711 fetch_after_load_ = false; | 704 fetch_after_load_ = false; |
| 712 EnterStateEnabled(fetch_snippets); | 705 EnterStateEnabled(fetch_snippets); |
| 713 return; | 706 return; |
| 714 } | 707 } |
| 715 | 708 |
| 716 case State::DISABLED: | 709 case State::DISABLED: |
| 717 DCHECK(state_ == State::NOT_INITED || state_ == State::READY); | 710 DCHECK(state_ == State::NOT_INITED || state_ == State::READY); |
| 718 | 711 |
| 719 DVLOG(1) << "Entering state: DISABLED"; | 712 DVLOG(1) << "Entering state: DISABLED"; |
| 720 state_ = State::DISABLED; | 713 state_ = State::DISABLED; |
| 721 EnterStateDisabled(); | 714 EnterStateDisabled(); |
| 722 return; | 715 return; |
| 723 | 716 |
| 724 case State::SHUT_DOWN: | 717 case State::SHUT_DOWN: |
| 725 DVLOG(1) << "Entering state: SHUT_DOWN"; | 718 DVLOG(1) << "Entering state: SHUT_DOWN"; |
| 726 state_ = State::SHUT_DOWN; | 719 state_ = State::SHUT_DOWN; |
| 727 EnterStateShutdown(); | 720 EnterStateShutdown(); |
| 728 return; | 721 return; |
| 729 } | 722 } |
| 730 } | 723 } |
| 731 | 724 |
| 732 void NTPSnippetsService::ClearDeprecatedPrefs() { | 725 void NTPSnippetsService::ClearDeprecatedPrefs() { |
| 733 pref_service_->ClearPref(prefs::kDeprecatedSnippets); | 726 pref_service_->ClearPref(prefs::kDeprecatedSnippets); |
| 734 pref_service_->ClearPref(prefs::kDeprecatedDiscardedSnippets); | 727 pref_service_->ClearPref(prefs::kDeprecatedDiscardedSnippets); |
| 735 } | 728 } |
| 736 | 729 |
| 737 } // namespace ntp_snippets | 730 } // namespace ntp_snippets |
| OLD | NEW |