[email protected] | 0865c134 | 2011-01-28 20:29:37 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d80033e | 2009-10-16 10:32:04 | [diff] [blame] | 5 | #include "chrome/browser/sync/sync_setup_flow.h" |
[email protected] | 8ac2dc11 | 2009-10-01 23:19:13 | [diff] [blame] | 6 | |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 7 | #include "base/callback.h" |
[email protected] | 23ec180 | 2011-05-24 17:40:31 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 9 | #include "base/json/json_reader.h" |
| 10 | #include "base/json/json_writer.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 11 | #include "base/metrics/histogram.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 12 | #include "base/string_util.h" |
[email protected] | d80033e | 2009-10-16 10:32:04 | [diff] [blame] | 13 | #include "base/utf_string_conversions.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 14 | #include "base/values.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 15 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 17 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 18 | #include "chrome/browser/sync/sync_setup_flow_handler.h" |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 19 | #include "chrome/browser/sync/syncable/model_type.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 20 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 23ec180 | 2011-05-24 17:40:31 | [diff] [blame] | 21 | #include "chrome/common/chrome_switches.h" |
[email protected] | 99074c5 | 2010-08-19 18:44:19 | [diff] [blame] | 22 | #include "chrome/common/net/gaia/google_service_auth_error.h" |
[email protected] | 24f8371 | 2009-10-08 22:52:45 | [diff] [blame] | 23 | #include "chrome/common/pref_names.h" |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 24 | #include "chrome/common/url_constants.h" |
[email protected] | d2912a2 | 2011-03-15 15:20:50 | [diff] [blame] | 25 | #include "grit/generated_resources.h" |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 26 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 27 | namespace { |
| 28 | |
| 29 | // Helper function to disable password sync. |
| 30 | void DisablePasswordSync(ProfileSyncService* service) { |
| 31 | syncable::ModelTypeSet types; |
| 32 | service->GetPreferredDataTypes(&types); |
| 33 | types.erase(syncable::PASSWORDS); |
| 34 | service->OnUserChoseDatatypes(false, types); |
| 35 | } |
| 36 | |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 37 | // Returns the next step for the non-fatal error case. |
| 38 | SyncSetupWizard::State GetStepForNonFatalError(ProfileSyncService* service) { |
[email protected] | b862fc8b | 2011-08-17 17:59:24 | [diff] [blame] | 39 | // TODO(sync): Update this error handling to allow different platforms to |
| 40 | // display the error appropriately (http://crbug.com/92722) instead of |
| 41 | // navigating to a LOGIN state that is not supported on every platform. |
[email protected] | bc44b8d8 | 2011-07-22 08:39:11 | [diff] [blame] | 42 | if (service->IsPassphraseRequired()) { |
| 43 | if (service->IsUsingSecondaryPassphrase()) |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 44 | return SyncSetupWizard::ENTER_PASSPHRASE; |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 45 | return SyncSetupWizard::GetLoginState(); |
[email protected] | bc44b8d8 | 2011-07-22 08:39:11 | [diff] [blame] | 46 | } |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 47 | |
| 48 | const GoogleServiceAuthError& error = service->GetAuthError(); |
| 49 | if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
| 50 | error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || |
| 51 | error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || |
| 52 | error.state() == GoogleServiceAuthError::ACCOUNT_DISABLED || |
| 53 | error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 54 | return SyncSetupWizard::GetLoginState(); |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 55 | |
| 56 | NOTREACHED(); |
| 57 | return SyncSetupWizard::FATAL_ERROR; |
| 58 | } |
| 59 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 60 | } // namespace |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 61 | |
[email protected] | 0865c134 | 2011-01-28 20:29:37 | [diff] [blame] | 62 | SyncConfiguration::SyncConfiguration() |
[email protected] | d45f751 | 2011-06-21 21:18:27 | [diff] [blame] | 63 | : encrypt_all(false), |
| 64 | sync_everything(false), |
[email protected] | 0865c134 | 2011-01-28 20:29:37 | [diff] [blame] | 65 | use_secondary_passphrase(false) { |
| 66 | } |
| 67 | |
| 68 | SyncConfiguration::~SyncConfiguration() {} |
| 69 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 70 | SyncSetupFlow::~SyncSetupFlow() { |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 71 | flow_handler_->SetFlow(NULL); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 74 | // static |
| 75 | SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, |
| 76 | SyncSetupFlowContainer* container, |
| 77 | SyncSetupWizard::State start, |
| 78 | SyncSetupWizard::State end) { |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 79 | if (start == SyncSetupWizard::NONFATAL_ERROR) |
| 80 | start = GetStepForNonFatalError(service); |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 81 | return new SyncSetupFlow(start, end, container, service); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 84 | // static |
| 85 | void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, |
| 86 | DictionaryValue* args) { |
[email protected] | 712257e | 2009-11-11 22:57:46 | [diff] [blame] | 87 | const GoogleServiceAuthError& error = service->GetAuthError(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 88 | if (!service->last_attempted_user_email().empty()) { |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 89 | args->SetString("user", service->last_attempted_user_email()); |
| 90 | args->SetInteger("error", error.state()); |
| 91 | args->SetBoolean("editable_user", true); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 92 | } else { |
[email protected] | bb868b4 | 2010-11-18 22:33:00 | [diff] [blame] | 93 | string16 user; |
| 94 | if (!service->cros_user().empty()) |
| 95 | user = UTF8ToUTF16(service->cros_user()); |
| 96 | else |
| 97 | user = service->GetAuthenticatedUsername(); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 98 | args->SetString("user", user); |
| 99 | args->SetInteger("error", 0); |
| 100 | args->SetBoolean("editable_user", user.empty()); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 101 | } |
[email protected] | 1fc9b3f | 2009-11-12 21:22:09 | [diff] [blame] | 102 | |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 103 | args->SetString("captchaUrl", error.captcha().image_url.spec()); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 104 | } |
| 105 | |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 106 | void SyncSetupFlow::GetArgsForConfigure(ProfileSyncService* service, |
| 107 | DictionaryValue* args) { |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 108 | // The SYNC_EVERYTHING case will set this to true. |
[email protected] | 56e2a440 | 2011-05-05 18:49:49 | [diff] [blame] | 109 | args->SetBoolean("showSyncEverythingPage", false); |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 110 | |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 111 | args->SetBoolean("keepEverythingSynced", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 112 | service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); |
| 113 | |
| 114 | // Bookmarks, Preferences, and Themes are launched for good, there's no |
| 115 | // going back now. Check if the other data types are registered though. |
| 116 | syncable::ModelTypeSet registered_types; |
| 117 | service->GetRegisteredDataTypes(®istered_types); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 118 | args->SetBoolean("passwordsRegistered", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 119 | registered_types.count(syncable::PASSWORDS) > 0); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 120 | args->SetBoolean("autofillRegistered", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 121 | registered_types.count(syncable::AUTOFILL) > 0); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 122 | args->SetBoolean("extensionsRegistered", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 123 | registered_types.count(syncable::EXTENSIONS) > 0); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 124 | args->SetBoolean("typedUrlsRegistered", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 125 | registered_types.count(syncable::TYPED_URLS) > 0); |
[email protected] | 75b362b | 2010-08-17 04:18:13 | [diff] [blame] | 126 | args->SetBoolean("appsRegistered", |
[email protected] | 06e3320 | 2010-08-16 23:45:15 | [diff] [blame] | 127 | registered_types.count(syncable::APPS) > 0); |
[email protected] | d9e3309 | 2011-09-01 03:34:05 | [diff] [blame] | 128 | args->SetBoolean("searchEnginesRegistered", |
| 129 | registered_types.count(syncable::SEARCH_ENGINES) > 0); |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 130 | args->SetBoolean("sessionsRegistered", |
| 131 | registered_types.count(syncable::SESSIONS) > 0); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 132 | args->SetBoolean("syncBookmarks", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 133 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncBookmarks)); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 134 | args->SetBoolean("syncPreferences", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 135 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPreferences)); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 136 | args->SetBoolean("syncThemes", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 137 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncThemes)); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 138 | args->SetBoolean("syncPasswords", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 139 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPasswords)); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 140 | args->SetBoolean("syncAutofill", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 141 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill)); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 142 | args->SetBoolean("syncExtensions", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 143 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions)); |
[email protected] | d9e3309 | 2011-09-01 03:34:05 | [diff] [blame] | 144 | args->SetBoolean("syncSearchEngines", |
| 145 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncSearchEngines)); |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 146 | args->SetBoolean("syncSessions", |
| 147 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncSessions)); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 148 | args->SetBoolean("syncTypedUrls", |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 149 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls)); |
[email protected] | 75b362b | 2010-08-17 04:18:13 | [diff] [blame] | 150 | args->SetBoolean("syncApps", |
[email protected] | 06e3320 | 2010-08-16 23:45:15 | [diff] [blame] | 151 | service->profile()->GetPrefs()->GetBoolean(prefs::kSyncApps)); |
[email protected] | 23ec180 | 2011-05-24 17:40:31 | [diff] [blame] | 152 | args->SetBoolean("encryptionEnabled", |
[email protected] | a57c07c | 2011-07-20 00:59:13 | [diff] [blame] | 153 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 154 | switches::kDisableSyncEncryption)); |
[email protected] | 23ec180 | 2011-05-24 17:40:31 | [diff] [blame] | 155 | |
| 156 | syncable::ModelTypeSet encrypted_types; |
| 157 | service->GetEncryptedDataTypes(&encrypted_types); |
| 158 | bool encrypt_all = |
| 159 | encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end(); |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 160 | if (service->HasPendingEncryptedTypes()) |
| 161 | encrypt_all = true; |
[email protected] | 23ec180 | 2011-05-24 17:40:31 | [diff] [blame] | 162 | args->SetBoolean("encryptAllData", encrypt_all); |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 163 | |
| 164 | // Load the parameters for the encryption tab. |
| 165 | args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 166 | |
| 167 | // Determine if we need a passphrase or not, and if so, prompt the user. |
| 168 | if (service->IsPassphraseRequiredForDecryption() && |
| 169 | (service->IsUsingSecondaryPassphrase() || cached_passphrase_.empty())) { |
| 170 | // We need a passphrase, and either it's an explicit passphrase, or we |
| 171 | // don't have a cached gaia passphrase, so we have to prompt the user. |
| 172 | args->SetBoolean("show_passphrase", true); |
| 173 | } |
| 174 | args->SetBoolean("passphrase_creation_rejected", |
| 175 | tried_creating_explicit_passphrase_); |
| 176 | args->SetBoolean("passphrase_setting_rejected", |
| 177 | tried_setting_explicit_passphrase_); |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | 7c72ecaf | 2011-06-15 20:42:47 | [diff] [blame] | 180 | bool SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) { |
| 181 | if (flow_handler_) |
| 182 | return false; |
| 183 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 184 | flow_handler_ = handler; |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 185 | handler->SetFlow(this); |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 186 | ActivateState(current_state_); |
[email protected] | 7c72ecaf | 2011-06-15 20:42:47 | [diff] [blame] | 187 | return true; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 188 | } |
| 189 | |
[email protected] | 3c9e109 | 2011-08-04 18:41:15 | [diff] [blame] | 190 | bool SyncSetupFlow::IsAttached() const { |
| 191 | return flow_handler_ != NULL; |
| 192 | } |
| 193 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 194 | void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { |
| 195 | if (!ShouldAdvance(advance_state)) { |
| 196 | LOG(WARNING) << "Invalid state change from " |
| 197 | << current_state_ << " to " << advance_state; |
| 198 | return; |
| 199 | } |
| 200 | |
[email protected] | 3c9e109 | 2011-08-04 18:41:15 | [diff] [blame] | 201 | if (flow_handler_) |
| 202 | ActivateState(advance_state); |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void SyncSetupFlow::Focus() { |
[email protected] | 6783bdd | 2011-06-28 23:51:47 | [diff] [blame] | 206 | // This gets called from SyncSetupWizard::Focus(), and might get called |
| 207 | // before flow_handler_ is set in AttachSyncSetupHandler() (which gets |
| 208 | // called asynchronously after the UI initializes). |
| 209 | if (flow_handler_) |
| 210 | flow_handler_->Focus(); |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | // A callback to notify the delegate that the dialog closed. |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 214 | // TODO(rickcam): Bug 90713: Handle OAUTH_LOGIN case here |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 215 | void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) { |
| 216 | DCHECK(json_retval.empty()); |
| 217 | container_->set_flow(NULL); // Sever ties from the wizard. |
[email protected] | 7ad97cf | 2011-07-29 21:42:16 | [diff] [blame] | 218 | // If we've reached the end, mark it. This could be a discrete run, in which |
| 219 | // case it's already set, but it simplifes the logic to do it this way. |
| 220 | if (current_state_ == end_state_) |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 221 | service_->SetSyncSetupCompleted(); |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 222 | |
| 223 | // Record the state at which the user cancelled the signon dialog. |
| 224 | switch (current_state_) { |
| 225 | case SyncSetupWizard::GAIA_LOGIN: |
| 226 | ProfileSyncService::SyncEvent( |
| 227 | ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
| 228 | break; |
| 229 | case SyncSetupWizard::GAIA_SUCCESS: |
| 230 | ProfileSyncService::SyncEvent( |
| 231 | ProfileSyncService::CANCEL_DURING_SIGNON); |
| 232 | break; |
| 233 | case SyncSetupWizard::CONFIGURE: |
| 234 | case SyncSetupWizard::ENTER_PASSPHRASE: |
| 235 | case SyncSetupWizard::SETTING_UP: |
| 236 | // TODO(atwilson): Treat a close during ENTER_PASSPHRASE like a |
| 237 | // Cancel + Skip (i.e. call OnPassphraseCancel()). http://crbug.com/74645 |
| 238 | ProfileSyncService::SyncEvent( |
| 239 | ProfileSyncService::CANCEL_DURING_CONFIGURE); |
| 240 | break; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 241 | case SyncSetupWizard::DONE: |
| 242 | // TODO(sync): rename this histogram; it's tracking authorization AND |
| 243 | // initial sync download time. |
| 244 | UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime", |
| 245 | base::TimeTicks::Now() - login_start_time_); |
| 246 | break; |
| 247 | default: |
| 248 | break; |
| 249 | } |
| 250 | |
| 251 | service_->OnUserCancelledDialog(); |
| 252 | delete this; |
| 253 | } |
| 254 | |
| 255 | void SyncSetupFlow::OnUserSubmittedAuth(const std::string& username, |
| 256 | const std::string& password, |
| 257 | const std::string& captcha, |
| 258 | const std::string& access_code) { |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 259 | cached_passphrase_ = password; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 260 | service_->OnUserSubmittedAuth(username, password, captcha, access_code); |
| 261 | } |
| 262 | |
| 263 | void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) { |
| 264 | // Go to the "loading..." screen. |
| 265 | Advance(SyncSetupWizard::SETTING_UP); |
| 266 | |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 267 | // Note: encryption will not occur until OnUserChoseDatatypes is called. |
| 268 | syncable::ModelTypeSet encrypted_types; |
[email protected] | 23ec180 | 2011-05-24 17:40:31 | [diff] [blame] | 269 | if (configuration.encrypt_all) { |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 270 | // Encrypt all registered types. |
| 271 | service_->GetRegisteredDataTypes(&encrypted_types); |
| 272 | } // Else we clear the pending types for encryption. |
| 273 | service_->set_pending_types_for_encryption(encrypted_types); |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 274 | |
[email protected] | 1a315b4 | 2011-08-04 17:44:18 | [diff] [blame] | 275 | if (!configuration.gaia_passphrase.empty()) { |
| 276 | // Caller passed a gaia passphrase. This is illegal if we are currently |
| 277 | // using a secondary passphrase. |
| 278 | DCHECK(!service_->IsUsingSecondaryPassphrase()); |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 279 | service_->SetPassphrase(configuration.gaia_passphrase, false); |
| 280 | } else if (!service_->IsUsingSecondaryPassphrase() && |
| 281 | !cached_passphrase_.empty()) { |
| 282 | // Service needs a GAIA passphrase and we have one cached, so try it. |
| 283 | service_->SetPassphrase(cached_passphrase_, false); |
| 284 | cached_passphrase_.clear(); |
| 285 | } else { |
| 286 | // No gaia passphrase cached or set, so make sure the ProfileSyncService |
| 287 | // wasn't expecting one. |
| 288 | DCHECK(!service_->IsPassphraseRequiredForDecryption() || |
| 289 | service_->IsUsingSecondaryPassphrase()); |
[email protected] | 1a315b4 | 2011-08-04 17:44:18 | [diff] [blame] | 290 | } |
| 291 | |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 292 | // It's possible the user has to provide a secondary passphrase even when |
| 293 | // they have not set one previously. This occurs when the user has changed |
| 294 | // their gaia password and then sign in to a new machine for the first time. |
| 295 | // The new machine will download data encrypted with their old gaia password, |
| 296 | // which their current gaia password will not be able to decrypt, triggering |
| 297 | // a prompt for a passphrase. At this point, the user must enter their old |
| 298 | // password, which we store as a new secondary passphrase. |
| 299 | // TODO(zea): eventually use the above gaia_passphrase instead of the |
| 300 | // secondary passphrase in this case. |
[email protected] | 41f41e4 | 2011-07-22 04:27:58 | [diff] [blame] | 301 | if (configuration.use_secondary_passphrase) { |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 302 | service_->SetPassphrase(configuration.secondary_passphrase, true); |
| 303 | if (service_->IsUsingSecondaryPassphrase()) |
[email protected] | 41f41e4 | 2011-07-22 04:27:58 | [diff] [blame] | 304 | tried_setting_explicit_passphrase_ = true; |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 305 | else |
| 306 | tried_creating_explicit_passphrase_ = true; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | service_->OnUserChoseDatatypes(configuration.sync_everything, |
| 310 | configuration.data_types); |
| 311 | } |
| 312 | |
| 313 | void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) { |
| 314 | Advance(SyncSetupWizard::SETTING_UP); |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 315 | service_->SetPassphrase(passphrase, true); |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 316 | tried_setting_explicit_passphrase_ = true; |
| 317 | } |
| 318 | |
| 319 | void SyncSetupFlow::OnPassphraseCancel() { |
| 320 | // If the user cancels when being asked for the passphrase, |
| 321 | // just disable encrypted sync and continue setting up. |
| 322 | if (current_state_ == SyncSetupWizard::ENTER_PASSPHRASE) |
| 323 | DisablePasswordSync(service_); |
| 324 | |
| 325 | Advance(SyncSetupWizard::SETTING_UP); |
| 326 | } |
| 327 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 328 | // Use static Run method to get an instance. |
| 329 | SyncSetupFlow::SyncSetupFlow(SyncSetupWizard::State start_state, |
| 330 | SyncSetupWizard::State end_state, |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 331 | SyncSetupFlowContainer* container, |
| 332 | ProfileSyncService* service) |
| 333 | : container_(container), |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 334 | current_state_(start_state), |
| 335 | end_state_(end_state), |
| 336 | login_start_time_(base::TimeTicks::Now()), |
| 337 | flow_handler_(NULL), |
| 338 | service_(service), |
| 339 | tried_creating_explicit_passphrase_(false), |
| 340 | tried_setting_explicit_passphrase_(false) { |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 343 | // Returns true if the flow should advance to |state| based on |current_state_|. |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 344 | bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { |
| 345 | switch (state) { |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 346 | case SyncSetupWizard::OAUTH_LOGIN: |
| 347 | return current_state_ == SyncSetupWizard::FATAL_ERROR || |
| 348 | current_state_ == SyncSetupWizard::OAUTH_LOGIN || |
| 349 | current_state_ == SyncSetupWizard::SETTING_UP; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 350 | case SyncSetupWizard::GAIA_LOGIN: |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 351 | return current_state_ == SyncSetupWizard::FATAL_ERROR || |
[email protected] | 7155564 | 2011-02-23 18:51:04 | [diff] [blame] | 352 | current_state_ == SyncSetupWizard::GAIA_LOGIN || |
| 353 | current_state_ == SyncSetupWizard::SETTING_UP; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 354 | case SyncSetupWizard::GAIA_SUCCESS: |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 355 | return current_state_ == SyncSetupWizard::GAIA_LOGIN || |
| 356 | current_state_ == SyncSetupWizard::OAUTH_LOGIN; |
| 357 | case SyncSetupWizard::SYNC_EVERYTHING: // Intentionally fall through. |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 358 | case SyncSetupWizard::CONFIGURE: |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 359 | return current_state_ == SyncSetupWizard::GAIA_SUCCESS; |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 360 | case SyncSetupWizard::ENTER_PASSPHRASE: |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 361 | return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || |
| 362 | current_state_ == SyncSetupWizard::CONFIGURE || |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 363 | current_state_ == SyncSetupWizard::SETTING_UP; |
[email protected] | a47eeb5 | 2010-07-15 17:54:25 | [diff] [blame] | 364 | case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 365 | return current_state_ != SyncSetupWizard::ABORT; |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 366 | case SyncSetupWizard::SETTING_UP: |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 367 | return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || |
| 368 | current_state_ == SyncSetupWizard::CONFIGURE || |
[email protected] | 5c0ec92f | 2011-05-09 20:28:52 | [diff] [blame] | 369 | current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 370 | case SyncSetupWizard::NONFATAL_ERROR: // Intentionally fall through. |
[email protected] | fb42c98 | 2009-09-16 22:33:33 | [diff] [blame] | 371 | case SyncSetupWizard::FATAL_ERROR: |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 372 | return current_state_ != SyncSetupWizard::ABORT; |
| 373 | case SyncSetupWizard::ABORT: |
| 374 | return true; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 375 | case SyncSetupWizard::DONE: |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 376 | return current_state_ == SyncSetupWizard::SETTING_UP || |
| 377 | current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 378 | default: |
| 379 | NOTREACHED() << "Unhandled State: " << state; |
| 380 | return false; |
| 381 | } |
| 382 | } |
| 383 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 384 | void SyncSetupFlow::ActivateState(SyncSetupWizard::State state) { |
[email protected] | 7c72ecaf | 2011-06-15 20:42:47 | [diff] [blame] | 385 | DCHECK(flow_handler_); |
| 386 | |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 387 | if (state == SyncSetupWizard::NONFATAL_ERROR) |
| 388 | state = GetStepForNonFatalError(service_); |
| 389 | |
| 390 | current_state_ = state; |
| 391 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 392 | switch (state) { |
[email protected] | 6f5fa9f | 2011-07-28 03:39:57 | [diff] [blame] | 393 | case SyncSetupWizard::OAUTH_LOGIN: { |
| 394 | flow_handler_->ShowOAuthLogin(); |
| 395 | break; |
| 396 | } |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 397 | case SyncSetupWizard::GAIA_LOGIN: { |
| 398 | DictionaryValue args; |
| 399 | SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
| 400 | flow_handler_->ShowGaiaLogin(args); |
| 401 | break; |
| 402 | } |
| 403 | case SyncSetupWizard::GAIA_SUCCESS: |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 404 | if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 405 | flow_handler_->ShowGaiaSuccessAndClose(); |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 406 | break; |
| 407 | } |
[email protected] | d2c04f2 | 2011-06-22 17:39:04 | [diff] [blame] | 408 | flow_handler_->ShowGaiaSuccessAndSettingUp(); |
| 409 | break; |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 410 | case SyncSetupWizard::SYNC_EVERYTHING: { |
| 411 | DictionaryValue args; |
| 412 | SyncSetupFlow::GetArgsForConfigure(service_, &args); |
[email protected] | 56e2a440 | 2011-05-05 18:49:49 | [diff] [blame] | 413 | args.SetBoolean("showSyncEverythingPage", true); |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 414 | flow_handler_->ShowConfigure(args); |
| 415 | break; |
| 416 | } |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 417 | case SyncSetupWizard::CONFIGURE: { |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 418 | DictionaryValue args; |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 419 | SyncSetupFlow::GetArgsForConfigure(service_, &args); |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 420 | flow_handler_->ShowConfigure(args); |
| 421 | break; |
| 422 | } |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 423 | case SyncSetupWizard::ENTER_PASSPHRASE: { |
| 424 | DictionaryValue args; |
[email protected] | 503ff125 | 2011-06-01 20:36:24 | [diff] [blame] | 425 | SyncSetupFlow::GetArgsForConfigure(service_, &args); |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 426 | GetArgsForConfigure(service_, &args); |
| 427 | // TODO(atwilson): Remove ShowPassphraseEntry in favor of using |
| 428 | // ShowConfigure() - http://crbug.com/90786. |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 429 | flow_handler_->ShowPassphraseEntry(args); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 430 | break; |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 431 | } |
[email protected] | a47eeb5 | 2010-07-15 17:54:25 | [diff] [blame] | 432 | case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { |
| 433 | DictionaryValue args; |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 434 | SyncSetupFlow::GetArgsForConfigure(service_, &args); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 435 | args.SetBoolean("was_aborted", true); |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 436 | flow_handler_->ShowConfigure(args); |
| 437 | break; |
| 438 | } |
| 439 | case SyncSetupWizard::SETTING_UP: { |
| 440 | flow_handler_->ShowSettingUp(); |
[email protected] | a47eeb5 | 2010-07-15 17:54:25 | [diff] [blame] | 441 | break; |
| 442 | } |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 443 | case SyncSetupWizard::FATAL_ERROR: { |
| 444 | // This shows the user the "Could not connect to server" error. |
[email protected] | b862fc8b | 2011-08-17 17:59:24 | [diff] [blame] | 445 | // TODO(sync): Update this error handling to allow different platforms to |
| 446 | // display the error appropriately (http://crbug.com/92722). |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 447 | DictionaryValue args; |
| 448 | SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 449 | args.SetInteger("error", GoogleServiceAuthError::CONNECTION_FAILED); |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 450 | flow_handler_->ShowGaiaLogin(args); |
[email protected] | fb42c98 | 2009-09-16 22:33:33 | [diff] [blame] | 451 | break; |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 452 | } |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 453 | case SyncSetupWizard::DONE: |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 454 | case SyncSetupWizard::ABORT: |
[email protected] | d80033e | 2009-10-16 10:32:04 | [diff] [blame] | 455 | flow_handler_->ShowSetupDone( |
| 456 | UTF16ToWide(service_->GetAuthenticatedUsername())); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 457 | break; |
| 458 | default: |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 459 | NOTREACHED() << "Invalid advance state: " << state; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 460 | } |
[email protected] | 22d3eff | 2011-01-08 01:45:18 | [diff] [blame] | 461 | } |