OLD | NEW |
1 // Copyright (c) 2012 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/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 ProfileSyncService* service = GetSyncService(); | 392 ProfileSyncService* service = GetSyncService(); |
393 if (!service->sync_initialized()) { | 393 if (!service->sync_initialized()) { |
394 // When user tries to setup sync while the sync backend is not initialized, | 394 // When user tries to setup sync while the sync backend is not initialized, |
395 // kick the sync backend and wait for it to be ready and show spinner until | 395 // kick the sync backend and wait for it to be ready and show spinner until |
396 // the backend gets ready. | 396 // the backend gets ready. |
397 retry_on_signin_failure_ = false; | 397 retry_on_signin_failure_ = false; |
398 | 398 |
399 service->UnsuppressAndStart(); | 399 service->UnsuppressAndStart(); |
400 DisplaySpinner(); | 400 DisplaySpinner(); |
401 // To listen to the token available notifications, start SigninTracker. | 401 // To listen to the token available notifications, start SigninTracker. |
402 signin_tracker_.reset( | 402 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); |
403 new SigninTracker(GetProfile(), this, | |
404 SigninTracker::SERVICES_INITIALIZING)); | |
405 return; | 403 return; |
406 } | 404 } |
407 | 405 |
408 // Should only be called if user is signed in, so no longer need our | 406 // Should only be called if user is signed in, so no longer need our |
409 // SigninTracker. | 407 // SigninTracker. |
410 signin_tracker_.reset(); | 408 signin_tracker_.reset(); |
411 configuring_sync_ = true; | 409 configuring_sync_ = true; |
412 DCHECK(service->sync_initialized()) << | 410 DCHECK(service->sync_initialized()) << |
413 "Cannot configure sync until the sync backend is initialized"; | 411 "Cannot configure sync until the sync backend is initialized"; |
414 | 412 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); | 498 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
501 } | 499 } |
502 | 500 |
503 StringValue page("configure"); | 501 StringValue page("configure"); |
504 web_ui()->CallJavascriptFunction( | 502 web_ui()->CallJavascriptFunction( |
505 "SyncSetupOverlay.showSyncSetupPage", page, args); | 503 "SyncSetupOverlay.showSyncSetupPage", page, args); |
506 | 504 |
507 if (UseWebBasedSigninFlow()) { | 505 if (UseWebBasedSigninFlow()) { |
508 // Make sure the tab used for the Gaia sign in does not cover the settings | 506 // Make sure the tab used for the Gaia sign in does not cover the settings |
509 // tab. | 507 // tab. |
510 BringTabToFront(web_ui()->GetWebContents()); | 508 FocusUI(); |
511 } | 509 } |
512 } | 510 } |
513 | 511 |
514 void SyncSetupHandler::ConfigureSyncDone() { | 512 void SyncSetupHandler::ConfigureSyncDone() { |
515 StringValue page("done"); | 513 StringValue page("done"); |
516 web_ui()->CallJavascriptFunction( | 514 web_ui()->CallJavascriptFunction( |
517 "SyncSetupOverlay.showSyncSetupPage", page); | 515 "SyncSetupOverlay.showSyncSetupPage", page); |
518 | 516 |
519 // Suppress the sync promo once the user signs into sync. This way the user | 517 // Suppress the sync promo once the user signs into sync. This way the user |
520 // doesn't see the sync promo even if they sign out of sync later on. | 518 // doesn't see the sync promo even if they sign out of sync later on. |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 832 |
835 // Gaia credentials are valid - update the UI. | 833 // Gaia credentials are valid - update the UI. |
836 DisplayGaiaSuccessAndSettingUp(); | 834 DisplayGaiaSuccessAndSettingUp(); |
837 } | 835 } |
838 | 836 |
839 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 837 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
840 // Stop a timer to handle timeout in waiting for checking network connection. | 838 // Stop a timer to handle timeout in waiting for checking network connection. |
841 backend_start_timer_.reset(); | 839 backend_start_timer_.reset(); |
842 | 840 |
843 last_signin_error_ = error; | 841 last_signin_error_ = error; |
844 // Got a failed signin - this is either just a typical auth error, or a | 842 |
845 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 843 // If using web-based sign in flow, don't show the gaia sign in page again |
846 // On ChromeOS, this condition can happen when auth token is invalid and | 844 // since there is no way to show the user an error message. |
847 // cannot start sync backend. | 845 if (UseWebBasedSigninFlow()) { |
848 if (retry_on_signin_failure_) { | 846 CloseSyncSetup(); |
| 847 } else if (retry_on_signin_failure_) { |
| 848 // Got a failed signin - this is either just a typical auth error, or a |
| 849 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
| 850 // On ChromeOS, this condition can happen when auth token is invalid and |
| 851 // cannot start sync backend. |
| 852 // If using web-based sign in flow, don't show the gaia sign in page again |
| 853 // since there is no way to show the user an error message. |
849 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); | 854 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); |
850 } else { | 855 } else { |
851 // TODO(peria): Show error dialog for prompting sign in and out on | 856 // TODO(peria): Show error dialog for prompting sign in and out on |
852 // Chrome OS. http://crbug.com/128692 | 857 // Chrome OS. http://crbug.com/128692 |
853 CloseOverlay(); | 858 CloseOverlay(); |
854 } | 859 } |
855 } | 860 } |
856 | 861 |
857 Profile* SyncSetupHandler::GetProfile() const { | 862 Profile* SyncSetupHandler::GetProfile() const { |
858 return Profile::FromWebUI(web_ui()); | 863 return Profile::FromWebUI(web_ui()); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 if (i != current_profile_index && AreUserNamesEqual( | 1220 if (i != current_profile_index && AreUserNamesEqual( |
1216 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1221 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1217 *error_message = l10n_util::GetStringUTF16( | 1222 *error_message = l10n_util::GetStringUTF16( |
1218 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1223 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1219 return false; | 1224 return false; |
1220 } | 1225 } |
1221 } | 1226 } |
1222 | 1227 |
1223 return true; | 1228 return true; |
1224 } | 1229 } |
OLD | NEW |