diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-17 18:48:20 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-17 18:48:20 +0000 |
commit | deb33c43f7db7b7179c819cc4444a11f45b753b4 (patch) | |
tree | 7ba6b04cef38a9ec9af0173326ca8d00948538e6 | |
parent | e584f52d634b6259a1edccc4f549a0cb96457292 (diff) | |
download | chromium_src-deb33c43f7db7b7179c819cc4444a11f45b753b4.zip chromium_src-deb33c43f7db7b7179c819cc4444a11f45b753b4.tar.gz chromium_src-deb33c43f7db7b7179c819cc4444a11f45b753b4.tar.bz2 |
Sync: Clean up SyncSetupWizard.
* Move static helper methods to unnamed nameespace in the source.
* Consolidate some logic.
* Fix up comments.
BUG=none
TEST=none
R=tim@chromium.org
Review URL: http://codereview.chromium.org/7184004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89527 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/sync_setup_wizard.cc | 64 | ||||
-rw-r--r-- | chrome/browser/sync/sync_setup_wizard.h | 14 |
2 files changed, 37 insertions, 41 deletions
diff --git a/chrome/browser/sync/sync_setup_wizard.cc b/chrome/browser/sync/sync_setup_wizard.cc index 23a44ba..b8dc3dd 100644 --- a/chrome/browser/sync/sync_setup_wizard.cc +++ b/chrome/browser/sync/sync_setup_wizard.cc @@ -10,6 +10,38 @@ #include "base/logging.h" #include "chrome/browser/sync/sync_setup_flow.h" +namespace { + +// If we just need to pop open an individual dialog, say to collect +// gaia credentials in the event of a steady-state auth failure, this is +// a "discrete" run (as in not a continuous wizard flow). This returns +// the end state to pass to Run for a given |start_state|. +SyncSetupWizard::State GetEndStateForDiscreteRun( + SyncSetupWizard::State start_state) { + SyncSetupWizard::State result = SyncSetupWizard::FATAL_ERROR; + if (start_state == SyncSetupWizard::GAIA_LOGIN) { + result = SyncSetupWizard::GAIA_SUCCESS; + } else if (start_state == SyncSetupWizard::ENTER_PASSPHRASE || + start_state == SyncSetupWizard::NONFATAL_ERROR || + start_state == SyncSetupWizard::SYNC_EVERYTHING || + start_state == SyncSetupWizard::CONFIGURE) { + result = SyncSetupWizard::DONE; + } + DCHECK_NE(SyncSetupWizard::FATAL_ERROR, result) << + "Invalid start state for discrete run: " << start_state; + return result; +} + +// Helper to return whether |state| warrants starting a new flow. +bool IsTerminalState(SyncSetupWizard::State state) { + return state == SyncSetupWizard::GAIA_SUCCESS || + state == SyncSetupWizard::DONE || + state == SyncSetupWizard::FATAL_ERROR || + state == SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR; +} + +} // namespace + SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) : service_(service), flow_container_(new SyncSetupFlowContainer()) { @@ -35,20 +67,12 @@ void SyncSetupWizard::Step(State advance_state) { // No flow in progress, but we've finished the wizard flow once before. // This is just a discrete run. if (IsTerminalState(advance_state)) - return; // Nothing to do. + return; flow_container_->set_flow(SyncSetupFlow::Run(service_, flow_container_, advance_state, GetEndStateForDiscreteRun(advance_state))); } } -// static -bool SyncSetupWizard::IsTerminalState(State advance_state) { - return advance_state == GAIA_SUCCESS || - advance_state == DONE || - advance_state == FATAL_ERROR || - advance_state == SETUP_ABORTED_BY_PENDING_CLEAR; -} - bool SyncSetupWizard::IsVisible() const { return flow_container_->get_flow() != NULL; } @@ -62,28 +86,8 @@ void SyncSetupWizard::Focus() { SyncSetupFlow* SyncSetupWizard::AttachSyncSetupHandler( SyncSetupFlowHandler* handler) { SyncSetupFlow* flow = flow_container_->get_flow(); - if (!flow) - return NULL; - - if (!flow->AttachSyncSetupHandler(handler)) + if (!flow || !flow->AttachSyncSetupHandler(handler)) return NULL; return flow; } - -// static -SyncSetupWizard::State SyncSetupWizard::GetEndStateForDiscreteRun( - State start_state) { - State result = FATAL_ERROR; - if (start_state == GAIA_LOGIN) { - result = GAIA_SUCCESS; - } else if (start_state == ENTER_PASSPHRASE || - start_state == NONFATAL_ERROR || - start_state == SYNC_EVERYTHING || - start_state == CONFIGURE) { - result = DONE; - } - DCHECK_NE(FATAL_ERROR, result) << - "Invalid start state for discrete run: " << start_state; - return result; -} diff --git a/chrome/browser/sync/sync_setup_wizard.h b/chrome/browser/sync/sync_setup_wizard.h index 2a856a1..a9f3579 100644 --- a/chrome/browser/sync/sync_setup_wizard.h +++ b/chrome/browser/sync/sync_setup_wizard.h @@ -67,20 +67,12 @@ class SyncSetupWizard { // not visible. void Focus(); - // TODO(jhawkins): Refactor to take a State parameter and handle the call to - // Step() as well as hooking up the handler. + // Attaches |handler| to the flow contained in |flow_container_|. Returns NULL + // if the flow does not exist or if an existing handler is already attached to + // the flow. SyncSetupFlow* AttachSyncSetupHandler(SyncSetupFlowHandler* handler); private: - // If we just need to pop open an individual dialog, say to collect - // gaia credentials in the event of a steady-state auth failure, this is - // a "discrete" run (as in not a continuous wizard flow). This returns - // the end state to pass to Run for a given |start_state|. - static State GetEndStateForDiscreteRun(State start_state); - - // Helper to return whether |state| warrants starting a new flow. - static bool IsTerminalState(State state); - ProfileSyncService* service_; SyncSetupFlowContainer* flow_container_; |