| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/sync/sync_setup_wizard.h" | 5 #include "chrome/browser/sync/sync_setup_wizard.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/sync_setup_flow.h" | 14 #include "chrome/browser/sync/sync_setup_flow.h" |
| 15 #include "chrome/browser/sync/util/oauth.h" | 15 #include "chrome/browser/sync/util/oauth.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // If we just need to pop open an individual dialog, say to collect | |
| 22 // gaia credentials in the event of a steady-state auth failure, this is | |
| 23 // a "discrete" run (as in not a continuous wizard flow). This returns | |
| 24 // the end state to pass to Run for a given |start_state|. | |
| 25 SyncSetupWizard::State GetEndStateForDiscreteRun( | |
| 26 SyncSetupWizard::State start_state) { | |
| 27 SyncSetupWizard::State result = SyncSetupWizard::FATAL_ERROR; | |
| 28 if (start_state == SyncSetupWizard::GAIA_LOGIN || | |
| 29 start_state == SyncSetupWizard::OAUTH_LOGIN) { | |
| 30 result = SyncSetupWizard::GAIA_SUCCESS; | |
| 31 } else if (start_state == SyncSetupWizard::ENTER_PASSPHRASE || | |
| 32 start_state == SyncSetupWizard::NONFATAL_ERROR || | |
| 33 start_state == SyncSetupWizard::SYNC_EVERYTHING || | |
| 34 start_state == SyncSetupWizard::CONFIGURE) { | |
| 35 result = SyncSetupWizard::DONE; | |
| 36 } | |
| 37 DCHECK_NE(SyncSetupWizard::FATAL_ERROR, result) << | |
| 38 "Invalid start state for discrete run: " << start_state; | |
| 39 return result; | |
| 40 } | |
| 41 | |
| 42 // Helper to return whether |state| warrants starting a new flow. | 21 // Helper to return whether |state| warrants starting a new flow. |
| 43 bool IsTerminalState(SyncSetupWizard::State state) { | 22 bool IsTerminalState(SyncSetupWizard::State state) { |
| 44 return state == SyncSetupWizard::GAIA_SUCCESS || | 23 return state == SyncSetupWizard::DONE || |
| 45 state == SyncSetupWizard::DONE || | 24 state == SyncSetupWizard::FATAL_ERROR; |
| 46 state == SyncSetupWizard::FATAL_ERROR || | |
| 47 state == SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR; | |
| 48 } | 25 } |
| 49 | 26 |
| 50 } // namespace | 27 } // namespace |
| 51 | 28 |
| 52 SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) | 29 SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) |
| 53 : service_(service), | 30 : service_(service), |
| 54 flow_container_(new SyncSetupFlowContainer()) { | 31 flow_container_(new SyncSetupFlowContainer()) { |
| 55 } | 32 } |
| 56 | 33 |
| 57 SyncSetupWizard::~SyncSetupWizard() { | 34 SyncSetupWizard::~SyncSetupWizard() { |
| 58 delete flow_container_; | 35 delete flow_container_; |
| 59 } | 36 } |
| 60 | 37 |
| 61 void SyncSetupWizard::Step(State advance_state) { | 38 void SyncSetupWizard::Step(State advance_state) { |
| 62 SyncSetupFlow* flow = flow_container_->get_flow(); | 39 SyncSetupFlow* flow = flow_container_->get_flow(); |
| 63 if (flow) { | 40 if (flow) { |
| 64 // A setup flow is in progress and dialog is currently showing. | 41 // A setup flow is in progress and dialog is currently showing. |
| 65 flow->Advance(advance_state); | 42 flow->Advance(advance_state); |
| 66 } else if (!service_->HasSyncSetupCompleted()) { | 43 } else { |
| 67 if (IsTerminalState(advance_state)) | 44 if (IsTerminalState(advance_state)) |
| 68 return; | 45 return; |
| 69 // No flow is in progress, and we have never escorted the user all the | 46 // Starting a new flow - make sure we're at a valid starting state. |
| 70 // way through the wizard flow. | 47 DCHECK(advance_state == ENTER_PASSPHRASE || |
| 71 // TODO(atwilson): Make sure this works on all autostart_enabled platforms. | 48 advance_state == SYNC_EVERYTHING || |
| 72 State end_state = DONE; | 49 advance_state == CONFIGURE); |
| 73 if (service_->auto_start_enabled() && | |
| 74 !service_->profile()->GetPrefs()->GetBoolean( | |
| 75 prefs::kSyncSuppressStart)) { | |
| 76 end_state = GAIA_SUCCESS; | |
| 77 } | |
| 78 flow_container_->set_flow( | 50 flow_container_->set_flow( |
| 79 SyncSetupFlow::Run(service_, flow_container_, advance_state, | 51 SyncSetupFlow::Run(service_, flow_container_, advance_state, DONE)); |
| 80 end_state)); | |
| 81 } else { | |
| 82 // No flow in progress, but we've finished the wizard flow once before. | |
| 83 // This is just a discrete run. | |
| 84 if (IsTerminalState(advance_state)) | |
| 85 return; | |
| 86 flow_container_->set_flow(SyncSetupFlow::Run(service_, flow_container_, | |
| 87 advance_state, GetEndStateForDiscreteRun(advance_state))); | |
| 88 } | 52 } |
| 89 } | 53 } |
| 90 | 54 |
| 91 bool SyncSetupWizard::IsVisible() const { | 55 bool SyncSetupWizard::IsVisible() const { |
| 92 return flow_container_->get_flow() != NULL && | 56 return flow_container_->get_flow() != NULL && |
| 93 flow_container_->get_flow()->IsAttached(); | 57 flow_container_->get_flow()->IsAttached(); |
| 94 } | 58 } |
| 95 | 59 |
| 96 // static | |
| 97 SyncSetupWizard::State SyncSetupWizard::GetLoginState() { | |
| 98 return browser_sync::IsUsingOAuth() ? | |
| 99 SyncSetupWizard::OAUTH_LOGIN : | |
| 100 SyncSetupWizard::GAIA_LOGIN; | |
| 101 } | |
| 102 | |
| 103 void SyncSetupWizard::Focus() { | 60 void SyncSetupWizard::Focus() { |
| 104 SyncSetupFlow* flow = flow_container_->get_flow(); | 61 SyncSetupFlow* flow = flow_container_->get_flow(); |
| 105 if (flow) | 62 if (flow) |
| 106 flow->Focus(); | 63 flow->Focus(); |
| 107 } | 64 } |
| 108 | 65 |
| 109 SyncSetupFlow* SyncSetupWizard::AttachSyncSetupHandler( | 66 SyncSetupFlow* SyncSetupWizard::AttachSyncSetupHandler( |
| 110 SyncSetupFlowHandler* handler) { | 67 SyncSetupFlowHandler* handler) { |
| 111 SyncSetupFlow* flow = flow_container_->get_flow(); | 68 SyncSetupFlow* flow = flow_container_->get_flow(); |
| 112 if (!flow || !flow->AttachSyncSetupHandler(handler)) | 69 if (!flow || !flow->AttachSyncSetupHandler(handler)) |
| 113 return NULL; | 70 return NULL; |
| 114 | 71 |
| 115 return flow; | 72 return flow; |
| 116 } | 73 } |
| OLD | NEW |