Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 9956097: suppress user/password dialog when re-enabling sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve Drew's comments. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (!error_message.empty()) 483 if (!error_message.empty())
484 args.SetString("error_message", error_message); 484 args.SetString("error_message", error_message);
485 if (fatal_error) 485 if (fatal_error)
486 args.SetBoolean("fatalError", true); 486 args.SetBoolean("fatalError", true);
487 args.SetString("captchaUrl", captcha); 487 args.SetString("captchaUrl", captcha);
488 StringValue page("login"); 488 StringValue page("login");
489 web_ui()->CallJavascriptFunction( 489 web_ui()->CallJavascriptFunction(
490 "SyncSetupOverlay.showSyncSetupPage", page, args); 490 "SyncSetupOverlay.showSyncSetupPage", page, args);
491 } 491 }
492 492
493 // TODO(kochi): Handle error conditions (timeout, other failures).
494 void SyncSetupHandler::DisplaySpinner() {
495 configuring_sync_ = true;
496 StringValue page("spinner");
497 web_ui()->CallJavascriptFunction(
498 "SyncSetupOverlay.showSyncSetupPage", page, DictionaryValue());
499 }
500
493 void SyncSetupHandler::RecordSignin() { 501 void SyncSetupHandler::RecordSignin() {
494 // By default, do nothing - subclasses can override. 502 // By default, do nothing - subclasses can override.
495 } 503 }
496 504
497 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { 505 void SyncSetupHandler::DisplayGaiaSuccessAndClose() {
498 RecordSignin(); 506 RecordSignin();
499 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); 507 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose");
500 } 508 }
501 509
502 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { 510 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() {
503 RecordSignin(); 511 RecordSignin();
504 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); 512 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp");
505 } 513 }
506 514
507 void SyncSetupHandler::ShowFatalError() { 515 void SyncSetupHandler::ShowFatalError() {
508 // For now, just send the user back to the login page. Ultimately may want 516 // For now, just send the user back to the login page. Ultimately may want
509 // to give different feedback (especially for chromeos). 517 // to give different feedback (especially for chromeos).
518 #if !defined(OS_CHROMEOS)
510 DisplayGaiaLogin(true); 519 DisplayGaiaLogin(true);
520 #endif
511 } 521 }
512 522
513 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { 523 void SyncSetupHandler::OnDidClosePage(const ListValue* args) {
514 CloseSyncSetup(); 524 CloseSyncSetup();
515 } 525 }
516 526
517 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { 527 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) {
518 std::string json; 528 std::string json;
519 if (!args->GetString(0, &json)) { 529 if (!args->GetString(0, &json)) {
520 NOTREACHED() << "Could not read JSON argument"; 530 NOTREACHED() << "Could not read JSON argument";
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 DCHECK(IsActiveLogin()); 589 DCHECK(IsActiveLogin());
580 590
581 // Gaia credentials are valid - update the UI. 591 // Gaia credentials are valid - update the UI.
582 DisplayGaiaSuccessAndSettingUp(); 592 DisplayGaiaSuccessAndSettingUp();
583 } 593 }
584 594
585 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { 595 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) {
586 last_signin_error_ = error; 596 last_signin_error_ = error;
587 // Got a failed signin - this is either just a typical auth error, or a 597 // Got a failed signin - this is either just a typical auth error, or a
588 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). 598 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors).
599 // On ChromeOS, this condition should trigger the orange badge on wrench menu
600 // and prompt to sign out.
601 #if !defined(OS_CHROMEOS)
589 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); 602 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected());
603 #else
604 CloseOverlay();
605 #endif
590 } 606 }
591 607
592 Profile* SyncSetupHandler::GetProfile() const { 608 Profile* SyncSetupHandler::GetProfile() const {
593 return Profile::FromWebUI(web_ui()); 609 return Profile::FromWebUI(web_ui());
594 } 610 }
595 611
596 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 612 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
597 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); 613 return ProfileSyncServiceFactory::GetForProfile(GetProfile());
598 } 614 }
599 615
600 void SyncSetupHandler::SigninSuccess() { 616 void SyncSetupHandler::SigninSuccess() {
617 LOG(WARNING) << "SigninSuccess()";
601 DCHECK(GetSyncService()->sync_initialized()); 618 DCHECK(GetSyncService()->sync_initialized());
602 // If we have signed in while sync is already setup, it must be due to some 619 // If we have signed in while sync is already setup, it must be due to some
603 // kind of re-authentication flow. In that case, just close the signin dialog 620 // kind of re-authentication flow. In that case, just close the signin dialog
604 // rather than forcing the user to go through sync configuration. 621 // rather than forcing the user to go through sync configuration.
605 if (GetSyncService()->HasSyncSetupCompleted()) 622 if (GetSyncService()->HasSyncSetupCompleted()) {
Andrew T Wilson (Slow) 2012/04/03 22:22:33 nit: No need to modify this code by adding braces.
kochi 2012/04/03 23:21:48 Done.
606 DisplayGaiaSuccessAndClose(); 623 DisplayGaiaSuccessAndClose();
607 else 624 } else {
608 DisplayConfigureSync(false, false); 625 DisplayConfigureSync(false, false);
626 }
609 } 627 }
610 628
611 void SyncSetupHandler::HandleConfigure(const ListValue* args) { 629 void SyncSetupHandler::HandleConfigure(const ListValue* args) {
612 std::string json; 630 std::string json;
613 if (!args->GetString(0, &json)) { 631 if (!args->GetString(0, &json)) {
614 NOTREACHED() << "Could not read JSON argument"; 632 NOTREACHED() << "Could not read JSON argument";
615 return; 633 return;
616 } 634 }
617 if (json.empty()) { 635 if (json.empty()) {
618 NOTREACHED(); 636 NOTREACHED();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 } 767 }
750 768
751 // Let the various services know that we're no longer active. 769 // Let the various services know that we're no longer active.
752 GetLoginUIService()->LoginUIClosed(web_ui()); 770 GetLoginUIService()->LoginUIClosed(web_ui());
753 if (sync_service) 771 if (sync_service)
754 sync_service->set_setup_in_progress(false); 772 sync_service->set_setup_in_progress(false);
755 773
756 // Make sure user isn't left half-logged-in (signed in, but without sync 774 // Make sure user isn't left half-logged-in (signed in, but without sync
757 // started up). If the user hasn't finished setting up sync, then sign out 775 // started up). If the user hasn't finished setting up sync, then sign out
758 // and shut down sync. 776 // and shut down sync.
759
760 if (sync_service && !sync_service->HasSyncSetupCompleted()) { 777 if (sync_service && !sync_service->HasSyncSetupCompleted()) {
761 DVLOG(1) << "Signin aborted by user action"; 778 DVLOG(1) << "Signin aborted by user action";
762 sync_service->DisableForUser(); 779 sync_service->DisableForUser();
780 #if !defined(OS_CHROMEOS)
763 GetSignin()->SignOut(); 781 GetSignin()->SignOut();
782 #endif
764 } 783 }
765 } 784 }
766 785
767 configuring_sync_ = false; 786 configuring_sync_ = false;
768 signin_tracker_.reset(); 787 signin_tracker_.reset();
769 } 788 }
770 789
771 void SyncSetupHandler::OpenSyncSetup(bool force_login) { 790 void SyncSetupHandler::OpenSyncSetup(bool force_login) {
772 ProfileSyncService* service = GetSyncService(); 791 ProfileSyncService* service = GetSyncService();
773 if (!service) { 792 if (!service) {
(...skipping 14 matching lines...) Expand all
788 807
789 // Notify services that we are now active. 808 // Notify services that we are now active.
790 GetLoginUIService()->SetLoginUI(web_ui()); 809 GetLoginUIService()->SetLoginUI(web_ui());
791 service->set_setup_in_progress(true); 810 service->set_setup_in_progress(true);
792 811
793 if (!force_login && service->HasSyncSetupCompleted()) { 812 if (!force_login && service->HasSyncSetupCompleted()) {
794 // User is already logged in. They must have brought up the config wizard 813 // User is already logged in. They must have brought up the config wizard
795 // via the "Advanced..." button or the wrench menu. 814 // via the "Advanced..." button or the wrench menu.
796 DisplayConfigureSync(true, false); 815 DisplayConfigureSync(true, false);
797 } else { 816 } else {
817 #if !defined(OS_CHROMEOS)
798 // User is not logged in - need to display login UI. 818 // User is not logged in - need to display login UI.
799 DisplayGaiaLogin(false); 819 DisplayGaiaLogin(false);
820 #else
821 PrepareConfigDialog();
822 #endif
800 } 823 }
801 824
802 ShowSetupUI(); 825 ShowSetupUI();
803 } 826 }
804 827
828 void SyncSetupHandler::PrepareConfigDialog() {
829 // On Chrome OS user is always logged in. Instead of showing login dialog,
830 // show spinner until the backend gets ready to configure sync.
831
832 // To make PSS:AreCredentialsAvailable() to return true, first we need
833 // to unsppress the flag.
834 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
835 sync_prefs.SetStartSuppressed(false);
Andrew T Wilson (Slow) 2012/04/03 22:22:33 Do we need to call SetStartSuppressed? Doesn't Uns
kochi 2012/04/03 23:21:48 I think so. Removed. This was done when I did som
836
837 ProfileSyncService* service = GetSyncService();
838 if (!service->sync_initialized()) {
839 // To listen to the token available notifications, start SigninTracker.
840 signin_tracker_.reset(
841 new SigninTracker(GetProfile(), this,
842 SigninTracker::SERVICES_INITIALIZING));
843 service->set_setup_in_progress(true);
844 service->UnsuppressAndStart();
845 DisplaySpinner();
846 } else {
847 DisplayConfigureSync(true, false);
848 }
849 }
850
805 // Private member functions. 851 // Private member functions.
806 852
807 bool SyncSetupHandler::FocusExistingWizardIfPresent() { 853 bool SyncSetupHandler::FocusExistingWizardIfPresent() {
808 LoginUIService* service = GetLoginUIService(); 854 LoginUIService* service = GetLoginUIService();
809 if (!service->current_login_ui()) 855 if (!service->current_login_ui())
810 return false; 856 return false;
811 service->FocusLoginUI(); 857 service->FocusLoginUI();
812 return true; 858 return true;
813 } 859 }
814 860
(...skipping 25 matching lines...) Expand all
840 if (i != current_profile_index && AreUserNamesEqual( 886 if (i != current_profile_index && AreUserNamesEqual(
841 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 887 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
842 *error_message = l10n_util::GetStringUTF16( 888 *error_message = l10n_util::GetStringUTF16(
843 IDS_SYNC_USER_NAME_IN_USE_ERROR); 889 IDS_SYNC_USER_NAME_IN_USE_ERROR);
844 return false; 890 return false;
845 } 891 }
846 } 892 }
847 893
848 return true; 894 return true;
849 } 895 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698