blob: a5d7ebf838b42b683c0b2a5f457e7b6c234de472 [file] [log] [blame]
[email protected]0865c1342011-01-28 20:29:371// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]132c85652009-08-05 01:18:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d80033e2009-10-16 10:32:045#include "chrome/browser/sync/sync_setup_flow.h"
[email protected]8ac2dc112009-10-01 23:19:136
[email protected]2041cf342010-02-19 03:15:597#include "base/callback.h"
[email protected]23ec1802011-05-24 17:40:318#include "base/command_line.h"
[email protected]93d49d72009-10-23 20:00:209#include "base/json/json_reader.h"
10#include "base/json/json_writer.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/histogram.h"
[email protected]132c85652009-08-05 01:18:2712#include "base/string_util.h"
[email protected]d80033e2009-10-16 10:32:0413#include "base/utf_string_conversions.h"
[email protected]132c85652009-08-05 01:18:2714#include "base/values.h"
[email protected]37858e52010-08-26 00:22:0215#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3316#include "chrome/browser/profiles/profile.h"
[email protected]132c85652009-08-05 01:18:2717#include "chrome/browser/sync/profile_sync_service.h"
[email protected]a1595962011-04-22 21:56:2418#include "chrome/browser/sync/sync_setup_flow_handler.h"
[email protected]80772ed2011-08-09 21:11:3819#include "chrome/browser/sync/syncable/model_type.h"
[email protected]2ad4a902010-11-17 06:05:1320#include "chrome/browser/ui/browser_list.h"
[email protected]23ec1802011-05-24 17:40:3121#include "chrome/common/chrome_switches.h"
[email protected]99074c52010-08-19 18:44:1922#include "chrome/common/net/gaia/google_service_auth_error.h"
[email protected]24f83712009-10-08 22:52:4523#include "chrome/common/pref_names.h"
[email protected]a1595962011-04-22 21:56:2424#include "chrome/common/url_constants.h"
[email protected]d2912a22011-03-15 15:20:5025#include "grit/generated_resources.h"
[email protected]9dd7e3d72011-01-20 18:27:0626
[email protected]a1595962011-04-22 21:56:2427namespace {
28
29// Helper function to disable password sync.
30void 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]87d5eb42011-06-14 01:21:2537// Returns the next step for the non-fatal error case.
38SyncSetupWizard::State GetStepForNonFatalError(ProfileSyncService* service) {
[email protected]b862fc8b2011-08-17 17:59:2439 // 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]bc44b8d82011-07-22 08:39:1142 if (service->IsPassphraseRequired()) {
43 if (service->IsUsingSecondaryPassphrase())
[email protected]87d5eb42011-06-14 01:21:2544 return SyncSetupWizard::ENTER_PASSPHRASE;
[email protected]6f5fa9f2011-07-28 03:39:5745 return SyncSetupWizard::GetLoginState();
[email protected]bc44b8d82011-07-22 08:39:1146 }
[email protected]87d5eb42011-06-14 01:21:2547
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]6f5fa9f2011-07-28 03:39:5754 return SyncSetupWizard::GetLoginState();
[email protected]87d5eb42011-06-14 01:21:2555
56 NOTREACHED();
57 return SyncSetupWizard::FATAL_ERROR;
58}
59
[email protected]a1595962011-04-22 21:56:2460} // namespace
[email protected]132c85652009-08-05 01:18:2761
[email protected]0865c1342011-01-28 20:29:3762SyncConfiguration::SyncConfiguration()
[email protected]d45f7512011-06-21 21:18:2763 : encrypt_all(false),
64 sync_everything(false),
[email protected]0865c1342011-01-28 20:29:3765 use_secondary_passphrase(false) {
66}
67
68SyncConfiguration::~SyncConfiguration() {}
69
[email protected]132c85652009-08-05 01:18:2770SyncSetupFlow::~SyncSetupFlow() {
[email protected]a1595962011-04-22 21:56:2471 flow_handler_->SetFlow(NULL);
[email protected]132c85652009-08-05 01:18:2772}
73
[email protected]a1595962011-04-22 21:56:2474// static
75SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service,
76 SyncSetupFlowContainer* container,
77 SyncSetupWizard::State start,
78 SyncSetupWizard::State end) {
[email protected]87d5eb42011-06-14 01:21:2579 if (start == SyncSetupWizard::NONFATAL_ERROR)
80 start = GetStepForNonFatalError(service);
[email protected]d6930242011-09-03 01:52:1981 return new SyncSetupFlow(start, end, container, service);
[email protected]e4be2dd2010-12-14 00:44:3982}
83
[email protected]132c85652009-08-05 01:18:2784// static
85void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service,
86 DictionaryValue* args) {
[email protected]712257e2009-11-11 22:57:4687 const GoogleServiceAuthError& error = service->GetAuthError();
[email protected]132c85652009-08-05 01:18:2788 if (!service->last_attempted_user_email().empty()) {
[email protected]dc9a6762010-08-16 07:13:5389 args->SetString("user", service->last_attempted_user_email());
90 args->SetInteger("error", error.state());
91 args->SetBoolean("editable_user", true);
[email protected]132c85652009-08-05 01:18:2792 } else {
[email protected]bb868b42010-11-18 22:33:0093 string16 user;
94 if (!service->cros_user().empty())
95 user = UTF8ToUTF16(service->cros_user());
96 else
97 user = service->GetAuthenticatedUsername();
[email protected]dc9a6762010-08-16 07:13:5398 args->SetString("user", user);
99 args->SetInteger("error", 0);
100 args->SetBoolean("editable_user", user.empty());
[email protected]132c85652009-08-05 01:18:27101 }
[email protected]1fc9b3f2009-11-12 21:22:09102
[email protected]dc9a6762010-08-16 07:13:53103 args->SetString("captchaUrl", error.captcha().image_url.spec());
[email protected]132c85652009-08-05 01:18:27104}
105
[email protected]c976938f2010-10-12 04:55:44106void SyncSetupFlow::GetArgsForConfigure(ProfileSyncService* service,
107 DictionaryValue* args) {
[email protected]5d0e7c22011-04-19 23:09:07108 // The SYNC_EVERYTHING case will set this to true.
[email protected]56e2a4402011-05-05 18:49:49109 args->SetBoolean("showSyncEverythingPage", false);
[email protected]c976938f2010-10-12 04:55:44110
[email protected]dc9a6762010-08-16 07:13:53111 args->SetBoolean("keepEverythingSynced",
[email protected]8c94d632010-06-25 22:38:00112 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(&registered_types);
[email protected]dc9a6762010-08-16 07:13:53118 args->SetBoolean("passwordsRegistered",
[email protected]8c94d632010-06-25 22:38:00119 registered_types.count(syncable::PASSWORDS) > 0);
[email protected]dc9a6762010-08-16 07:13:53120 args->SetBoolean("autofillRegistered",
[email protected]8c94d632010-06-25 22:38:00121 registered_types.count(syncable::AUTOFILL) > 0);
[email protected]dc9a6762010-08-16 07:13:53122 args->SetBoolean("extensionsRegistered",
[email protected]8c94d632010-06-25 22:38:00123 registered_types.count(syncable::EXTENSIONS) > 0);
[email protected]dc9a6762010-08-16 07:13:53124 args->SetBoolean("typedUrlsRegistered",
[email protected]8c94d632010-06-25 22:38:00125 registered_types.count(syncable::TYPED_URLS) > 0);
[email protected]75b362b2010-08-17 04:18:13126 args->SetBoolean("appsRegistered",
[email protected]06e33202010-08-16 23:45:15127 registered_types.count(syncable::APPS) > 0);
[email protected]d9e33092011-09-01 03:34:05128 args->SetBoolean("searchEnginesRegistered",
129 registered_types.count(syncable::SEARCH_ENGINES) > 0);
[email protected]5edb9222010-08-18 00:23:29130 args->SetBoolean("sessionsRegistered",
131 registered_types.count(syncable::SESSIONS) > 0);
[email protected]dc9a6762010-08-16 07:13:53132 args->SetBoolean("syncBookmarks",
[email protected]8c94d632010-06-25 22:38:00133 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncBookmarks));
[email protected]dc9a6762010-08-16 07:13:53134 args->SetBoolean("syncPreferences",
[email protected]8c94d632010-06-25 22:38:00135 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPreferences));
[email protected]dc9a6762010-08-16 07:13:53136 args->SetBoolean("syncThemes",
[email protected]8c94d632010-06-25 22:38:00137 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncThemes));
[email protected]dc9a6762010-08-16 07:13:53138 args->SetBoolean("syncPasswords",
[email protected]8c94d632010-06-25 22:38:00139 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPasswords));
[email protected]dc9a6762010-08-16 07:13:53140 args->SetBoolean("syncAutofill",
[email protected]8c94d632010-06-25 22:38:00141 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill));
[email protected]dc9a6762010-08-16 07:13:53142 args->SetBoolean("syncExtensions",
[email protected]8c94d632010-06-25 22:38:00143 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions));
[email protected]d9e33092011-09-01 03:34:05144 args->SetBoolean("syncSearchEngines",
145 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncSearchEngines));
[email protected]5edb9222010-08-18 00:23:29146 args->SetBoolean("syncSessions",
147 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncSessions));
[email protected]dc9a6762010-08-16 07:13:53148 args->SetBoolean("syncTypedUrls",
[email protected]8c94d632010-06-25 22:38:00149 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls));
[email protected]75b362b2010-08-17 04:18:13150 args->SetBoolean("syncApps",
[email protected]06e33202010-08-16 23:45:15151 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncApps));
[email protected]23ec1802011-05-24 17:40:31152 args->SetBoolean("encryptionEnabled",
[email protected]a57c07c2011-07-20 00:59:13153 !CommandLine::ForCurrentProcess()->HasSwitch(
154 switches::kDisableSyncEncryption));
[email protected]23ec1802011-05-24 17:40:31155
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]cc10e7c2011-08-06 00:17:50160 if (service->HasPendingEncryptedTypes())
161 encrypt_all = true;
[email protected]23ec1802011-05-24 17:40:31162 args->SetBoolean("encryptAllData", encrypt_all);
[email protected]c976938f2010-10-12 04:55:44163
164 // Load the parameters for the encryption tab.
165 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase());
[email protected]d6930242011-09-03 01:52:19166
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]8c94d632010-06-25 22:38:00178}
179
[email protected]7c72ecaf2011-06-15 20:42:47180bool SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) {
181 if (flow_handler_)
182 return false;
183
[email protected]a1595962011-04-22 21:56:24184 flow_handler_ = handler;
[email protected]87d5eb42011-06-14 01:21:25185 handler->SetFlow(this);
[email protected]a1595962011-04-22 21:56:24186 ActivateState(current_state_);
[email protected]7c72ecaf2011-06-15 20:42:47187 return true;
[email protected]a1595962011-04-22 21:56:24188}
189
[email protected]3c9e1092011-08-04 18:41:15190bool SyncSetupFlow::IsAttached() const {
191 return flow_handler_ != NULL;
192}
193
[email protected]a1595962011-04-22 21:56:24194void 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]3c9e1092011-08-04 18:41:15201 if (flow_handler_)
202 ActivateState(advance_state);
[email protected]a1595962011-04-22 21:56:24203}
204
205void SyncSetupFlow::Focus() {
[email protected]6783bdd2011-06-28 23:51:47206 // 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]a1595962011-04-22 21:56:24211}
212
213// A callback to notify the delegate that the dialog closed.
[email protected]6f5fa9f2011-07-28 03:39:57214// TODO(rickcam): Bug 90713: Handle OAUTH_LOGIN case here
[email protected]a1595962011-04-22 21:56:24215void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) {
216 DCHECK(json_retval.empty());
217 container_->set_flow(NULL); // Sever ties from the wizard.
[email protected]7ad97cf2011-07-29 21:42:16218 // 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]a1595962011-04-22 21:56:24221 service_->SetSyncSetupCompleted();
[email protected]a1595962011-04-22 21:56:24222
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]a1595962011-04-22 21:56:24241 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
255void SyncSetupFlow::OnUserSubmittedAuth(const std::string& username,
256 const std::string& password,
257 const std::string& captcha,
258 const std::string& access_code) {
[email protected]d6930242011-09-03 01:52:19259 cached_passphrase_ = password;
[email protected]a1595962011-04-22 21:56:24260 service_->OnUserSubmittedAuth(username, password, captcha, access_code);
261}
262
263void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) {
264 // Go to the "loading..." screen.
265 Advance(SyncSetupWizard::SETTING_UP);
266
[email protected]cc10e7c2011-08-06 00:17:50267 // Note: encryption will not occur until OnUserChoseDatatypes is called.
268 syncable::ModelTypeSet encrypted_types;
[email protected]23ec1802011-05-24 17:40:31269 if (configuration.encrypt_all) {
[email protected]cc10e7c2011-08-06 00:17:50270 // 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]a1595962011-04-22 21:56:24274
[email protected]1a315b42011-08-04 17:44:18275 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]d6930242011-09-03 01:52:19279 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]1a315b42011-08-04 17:44:18290 }
291
[email protected]cc10e7c2011-08-06 00:17:50292 // 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]41f41e42011-07-22 04:27:58301 if (configuration.use_secondary_passphrase) {
[email protected]d6930242011-09-03 01:52:19302 service_->SetPassphrase(configuration.secondary_passphrase, true);
303 if (service_->IsUsingSecondaryPassphrase())
[email protected]41f41e42011-07-22 04:27:58304 tried_setting_explicit_passphrase_ = true;
[email protected]d6930242011-09-03 01:52:19305 else
306 tried_creating_explicit_passphrase_ = true;
[email protected]a1595962011-04-22 21:56:24307 }
308
309 service_->OnUserChoseDatatypes(configuration.sync_everything,
310 configuration.data_types);
311}
312
313void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) {
314 Advance(SyncSetupWizard::SETTING_UP);
[email protected]d6930242011-09-03 01:52:19315 service_->SetPassphrase(passphrase, true);
[email protected]a1595962011-04-22 21:56:24316 tried_setting_explicit_passphrase_ = true;
317}
318
319void 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]a1595962011-04-22 21:56:24328// Use static Run method to get an instance.
329SyncSetupFlow::SyncSetupFlow(SyncSetupWizard::State start_state,
330 SyncSetupWizard::State end_state,
[email protected]a1595962011-04-22 21:56:24331 SyncSetupFlowContainer* container,
332 ProfileSyncService* service)
333 : container_(container),
[email protected]a1595962011-04-22 21:56:24334 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]132c85652009-08-05 01:18:27341}
342
[email protected]c976938f2010-10-12 04:55:44343// Returns true if the flow should advance to |state| based on |current_state_|.
[email protected]132c85652009-08-05 01:18:27344bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) {
345 switch (state) {
[email protected]6f5fa9f2011-07-28 03:39:57346 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]132c85652009-08-05 01:18:27350 case SyncSetupWizard::GAIA_LOGIN:
[email protected]8c94d632010-06-25 22:38:00351 return current_state_ == SyncSetupWizard::FATAL_ERROR ||
[email protected]71555642011-02-23 18:51:04352 current_state_ == SyncSetupWizard::GAIA_LOGIN ||
353 current_state_ == SyncSetupWizard::SETTING_UP;
[email protected]132c85652009-08-05 01:18:27354 case SyncSetupWizard::GAIA_SUCCESS:
[email protected]6f5fa9f2011-07-28 03:39:57355 return current_state_ == SyncSetupWizard::GAIA_LOGIN ||
356 current_state_ == SyncSetupWizard::OAUTH_LOGIN;
357 case SyncSetupWizard::SYNC_EVERYTHING: // Intentionally fall through.
[email protected]c976938f2010-10-12 04:55:44358 case SyncSetupWizard::CONFIGURE:
[email protected]8c94d632010-06-25 22:38:00359 return current_state_ == SyncSetupWizard::GAIA_SUCCESS;
[email protected]66d81002010-10-18 16:52:09360 case SyncSetupWizard::ENTER_PASSPHRASE:
[email protected]5d0e7c22011-04-19 23:09:07361 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING ||
362 current_state_ == SyncSetupWizard::CONFIGURE ||
[email protected]66d81002010-10-18 16:52:09363 current_state_ == SyncSetupWizard::SETTING_UP;
[email protected]a47eeb52010-07-15 17:54:25364 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR:
[email protected]cb5199b2011-09-04 01:55:52365 return current_state_ != SyncSetupWizard::ABORT;
[email protected]c976938f2010-10-12 04:55:44366 case SyncSetupWizard::SETTING_UP:
[email protected]5d0e7c22011-04-19 23:09:07367 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING ||
368 current_state_ == SyncSetupWizard::CONFIGURE ||
[email protected]5c0ec92f2011-05-09 20:28:52369 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE;
[email protected]6f5fa9f2011-07-28 03:39:57370 case SyncSetupWizard::NONFATAL_ERROR: // Intentionally fall through.
[email protected]fb42c982009-09-16 22:33:33371 case SyncSetupWizard::FATAL_ERROR:
[email protected]cb5199b2011-09-04 01:55:52372 return current_state_ != SyncSetupWizard::ABORT;
373 case SyncSetupWizard::ABORT:
374 return true;
[email protected]132c85652009-08-05 01:18:27375 case SyncSetupWizard::DONE:
[email protected]66d81002010-10-18 16:52:09376 return current_state_ == SyncSetupWizard::SETTING_UP ||
377 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE;
[email protected]132c85652009-08-05 01:18:27378 default:
379 NOTREACHED() << "Unhandled State: " << state;
380 return false;
381 }
382}
383
[email protected]a1595962011-04-22 21:56:24384void SyncSetupFlow::ActivateState(SyncSetupWizard::State state) {
[email protected]7c72ecaf2011-06-15 20:42:47385 DCHECK(flow_handler_);
386
[email protected]87d5eb42011-06-14 01:21:25387 if (state == SyncSetupWizard::NONFATAL_ERROR)
388 state = GetStepForNonFatalError(service_);
389
390 current_state_ = state;
391
[email protected]a1595962011-04-22 21:56:24392 switch (state) {
[email protected]6f5fa9f2011-07-28 03:39:57393 case SyncSetupWizard::OAUTH_LOGIN: {
394 flow_handler_->ShowOAuthLogin();
395 break;
396 }
[email protected]132c85652009-08-05 01:18:27397 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]8c94d632010-06-25 22:38:00404 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) {
[email protected]132c85652009-08-05 01:18:27405 flow_handler_->ShowGaiaSuccessAndClose();
[email protected]8c94d632010-06-25 22:38:00406 break;
407 }
[email protected]d2c04f22011-06-22 17:39:04408 flow_handler_->ShowGaiaSuccessAndSettingUp();
409 break;
[email protected]5d0e7c22011-04-19 23:09:07410 case SyncSetupWizard::SYNC_EVERYTHING: {
411 DictionaryValue args;
412 SyncSetupFlow::GetArgsForConfigure(service_, &args);
[email protected]56e2a4402011-05-05 18:49:49413 args.SetBoolean("showSyncEverythingPage", true);
[email protected]5d0e7c22011-04-19 23:09:07414 flow_handler_->ShowConfigure(args);
415 break;
416 }
[email protected]c976938f2010-10-12 04:55:44417 case SyncSetupWizard::CONFIGURE: {
[email protected]8c94d632010-06-25 22:38:00418 DictionaryValue args;
[email protected]c976938f2010-10-12 04:55:44419 SyncSetupFlow::GetArgsForConfigure(service_, &args);
[email protected]c976938f2010-10-12 04:55:44420 flow_handler_->ShowConfigure(args);
421 break;
422 }
[email protected]c976938f2010-10-12 04:55:44423 case SyncSetupWizard::ENTER_PASSPHRASE: {
424 DictionaryValue args;
[email protected]503ff1252011-06-01 20:36:24425 SyncSetupFlow::GetArgsForConfigure(service_, &args);
[email protected]d6930242011-09-03 01:52:19426 GetArgsForConfigure(service_, &args);
427 // TODO(atwilson): Remove ShowPassphraseEntry in favor of using
428 // ShowConfigure() - http://crbug.com/90786.
[email protected]c976938f2010-10-12 04:55:44429 flow_handler_->ShowPassphraseEntry(args);
[email protected]132c85652009-08-05 01:18:27430 break;
[email protected]8c94d632010-06-25 22:38:00431 }
[email protected]a47eeb52010-07-15 17:54:25432 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: {
433 DictionaryValue args;
[email protected]c976938f2010-10-12 04:55:44434 SyncSetupFlow::GetArgsForConfigure(service_, &args);
[email protected]dc9a6762010-08-16 07:13:53435 args.SetBoolean("was_aborted", true);
[email protected]c976938f2010-10-12 04:55:44436 flow_handler_->ShowConfigure(args);
437 break;
438 }
439 case SyncSetupWizard::SETTING_UP: {
440 flow_handler_->ShowSettingUp();
[email protected]a47eeb52010-07-15 17:54:25441 break;
442 }
[email protected]2be7bf22010-04-23 21:02:37443 case SyncSetupWizard::FATAL_ERROR: {
444 // This shows the user the "Could not connect to server" error.
[email protected]b862fc8b2011-08-17 17:59:24445 // TODO(sync): Update this error handling to allow different platforms to
446 // display the error appropriately (http://crbug.com/92722).
[email protected]2be7bf22010-04-23 21:02:37447 DictionaryValue args;
448 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args);
[email protected]dc9a6762010-08-16 07:13:53449 args.SetInteger("error", GoogleServiceAuthError::CONNECTION_FAILED);
[email protected]2be7bf22010-04-23 21:02:37450 flow_handler_->ShowGaiaLogin(args);
[email protected]fb42c982009-09-16 22:33:33451 break;
[email protected]2be7bf22010-04-23 21:02:37452 }
[email protected]132c85652009-08-05 01:18:27453 case SyncSetupWizard::DONE:
[email protected]cb5199b2011-09-04 01:55:52454 case SyncSetupWizard::ABORT:
[email protected]d80033e2009-10-16 10:32:04455 flow_handler_->ShowSetupDone(
456 UTF16ToWide(service_->GetAuthenticatedUsername()));
[email protected]132c85652009-08-05 01:18:27457 break;
458 default:
[email protected]a1595962011-04-22 21:56:24459 NOTREACHED() << "Invalid advance state: " << state;
[email protected]132c85652009-08-05 01:18:27460 }
[email protected]22d3eff2011-01-08 01:45:18461}