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/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" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/google/google_util.h" | 16 #include "chrome/browser/google/google_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_info_cache.h" | 18 #include "chrome/browser/profiles/profile_info_cache.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
21 #include "chrome/browser/signin/signin_manager.h" | 21 #include "chrome/browser/signin/signin_manager.h" |
22 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/browser/signin/token_service.h" |
| 24 #include "chrome/browser/signin/token_service_factory.h" |
23 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 28 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
27 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 29 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
28 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 30 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
29 #include "chrome/common/net/gaia/gaia_constants.h" | 31 #include "chrome/common/net/gaia/gaia_constants.h" |
30 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
31 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/render_view_host_delegate.h" | 34 #include "content/public/browser/render_view_host_delegate.h" |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 if (!error_message.empty()) | 485 if (!error_message.empty()) |
484 args.SetString("error_message", error_message); | 486 args.SetString("error_message", error_message); |
485 if (fatal_error) | 487 if (fatal_error) |
486 args.SetBoolean("fatalError", true); | 488 args.SetBoolean("fatalError", true); |
487 args.SetString("captchaUrl", captcha); | 489 args.SetString("captchaUrl", captcha); |
488 StringValue page("login"); | 490 StringValue page("login"); |
489 web_ui()->CallJavascriptFunction( | 491 web_ui()->CallJavascriptFunction( |
490 "SyncSetupOverlay.showSyncSetupPage", page, args); | 492 "SyncSetupOverlay.showSyncSetupPage", page, args); |
491 } | 493 } |
492 | 494 |
| 495 // TODO(kochi): Handle error conditions (timeout, other failures). |
| 496 void SyncSetupHandler::DisplaySpinner() { |
| 497 configuring_sync_ = true; |
| 498 StringValue page("spinner"); |
| 499 web_ui()->CallJavascriptFunction( |
| 500 "SyncSetupOverlay.showSyncSetupPage", page, DictionaryValue()); |
| 501 } |
| 502 |
493 void SyncSetupHandler::RecordSignin() { | 503 void SyncSetupHandler::RecordSignin() { |
494 // By default, do nothing - subclasses can override. | 504 // By default, do nothing - subclasses can override. |
495 } | 505 } |
496 | 506 |
497 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 507 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
498 RecordSignin(); | 508 RecordSignin(); |
499 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 509 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
500 } | 510 } |
501 | 511 |
502 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { | 512 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #endif |
590 } | 604 } |
591 | 605 |
592 Profile* SyncSetupHandler::GetProfile() const { | 606 Profile* SyncSetupHandler::GetProfile() const { |
593 return Profile::FromWebUI(web_ui()); | 607 return Profile::FromWebUI(web_ui()); |
594 } | 608 } |
595 | 609 |
596 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 610 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
597 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 611 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
598 } | 612 } |
599 | 613 |
600 void SyncSetupHandler::SigninSuccess() { | 614 void SyncSetupHandler::SigninSuccess() { |
| 615 LOG(WARNING) << "SigninSuccess()"; |
601 DCHECK(GetSyncService()->sync_initialized()); | 616 DCHECK(GetSyncService()->sync_initialized()); |
602 // If we have signed in while sync is already setup, it must be due to some | 617 // 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 | 618 // kind of re-authentication flow. In that case, just close the signin dialog |
604 // rather than forcing the user to go through sync configuration. | 619 // rather than forcing the user to go through sync configuration. |
605 if (GetSyncService()->HasSyncSetupCompleted()) | 620 if (GetSyncService()->HasSyncSetupCompleted()) { |
606 DisplayGaiaSuccessAndClose(); | 621 DisplayGaiaSuccessAndClose(); |
607 else | 622 } else { |
| 623 #if !defined(OS_CHROMEOS) |
608 DisplayConfigureSync(false, false); | 624 DisplayConfigureSync(false, false); |
| 625 #else |
| 626 // On ChromeOS, clicking on "Set up Sync" should show advanced settings. |
| 627 DisplayConfigureSync(true, false); |
| 628 #endif |
| 629 } |
609 } | 630 } |
610 | 631 |
611 void SyncSetupHandler::HandleConfigure(const ListValue* args) { | 632 void SyncSetupHandler::HandleConfigure(const ListValue* args) { |
612 std::string json; | 633 std::string json; |
613 if (!args->GetString(0, &json)) { | 634 if (!args->GetString(0, &json)) { |
614 NOTREACHED() << "Could not read JSON argument"; | 635 NOTREACHED() << "Could not read JSON argument"; |
615 return; | 636 return; |
616 } | 637 } |
617 if (json.empty()) { | 638 if (json.empty()) { |
618 NOTREACHED(); | 639 NOTREACHED(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 } | 770 } |
750 | 771 |
751 // Let the various services know that we're no longer active. | 772 // Let the various services know that we're no longer active. |
752 GetLoginUIService()->LoginUIClosed(web_ui()); | 773 GetLoginUIService()->LoginUIClosed(web_ui()); |
753 if (sync_service) | 774 if (sync_service) |
754 sync_service->set_setup_in_progress(false); | 775 sync_service->set_setup_in_progress(false); |
755 | 776 |
756 // Make sure user isn't left half-logged-in (signed in, but without sync | 777 // 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 | 778 // started up). If the user hasn't finished setting up sync, then sign out |
758 // and shut down sync. | 779 // and shut down sync. |
759 | |
760 if (sync_service && !sync_service->HasSyncSetupCompleted()) { | 780 if (sync_service && !sync_service->HasSyncSetupCompleted()) { |
761 DVLOG(1) << "Signin aborted by user action"; | 781 DVLOG(1) << "Signin aborted by user action"; |
762 sync_service->DisableForUser(); | 782 sync_service->DisableForUser(); |
| 783 #if !defined(OS_CHROMEOS) |
763 GetSignin()->SignOut(); | 784 GetSignin()->SignOut(); |
| 785 #endif |
764 } | 786 } |
765 } | 787 } |
766 | 788 |
767 configuring_sync_ = false; | 789 configuring_sync_ = false; |
768 signin_tracker_.reset(); | 790 signin_tracker_.reset(); |
769 } | 791 } |
770 | 792 |
771 void SyncSetupHandler::OpenSyncSetup(bool force_login) { | 793 void SyncSetupHandler::OpenSyncSetup(bool force_login) { |
772 ProfileSyncService* service = GetSyncService(); | 794 ProfileSyncService* service = GetSyncService(); |
773 if (!service) { | 795 if (!service) { |
(...skipping 14 matching lines...) Expand all Loading... |
788 | 810 |
789 // Notify services that we are now active. | 811 // Notify services that we are now active. |
790 GetLoginUIService()->SetLoginUI(web_ui()); | 812 GetLoginUIService()->SetLoginUI(web_ui()); |
791 service->set_setup_in_progress(true); | 813 service->set_setup_in_progress(true); |
792 | 814 |
793 if (!force_login && service->HasSyncSetupCompleted()) { | 815 if (!force_login && service->HasSyncSetupCompleted()) { |
794 // User is already logged in. They must have brought up the config wizard | 816 // User is already logged in. They must have brought up the config wizard |
795 // via the "Advanced..." button or the wrench menu. | 817 // via the "Advanced..." button or the wrench menu. |
796 DisplayConfigureSync(true, false); | 818 DisplayConfigureSync(true, false); |
797 } else { | 819 } else { |
| 820 #if !defined(OS_CHROMEOS) |
798 // User is not logged in - need to display login UI. | 821 // User is not logged in - need to display login UI. |
799 DisplayGaiaLogin(false); | 822 DisplayGaiaLogin(false); |
| 823 #else |
| 824 // On Chrome OS user is always logged in. Instead of showing login dialog, |
| 825 // show spinner until the backend gets ready to configure sync. |
| 826 |
| 827 // 1. To make PSS:AreCredentialsAvailable() to return true, first we need |
| 828 // to unsppress the flag. |
| 829 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
| 830 sync_prefs.SetStartSuppressed(false); |
| 831 |
| 832 // 2. To listen to the token available notifications, start SigninTracker. |
| 833 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); |
| 834 TokenService* token_service = |
| 835 TokenServiceFactory::GetForProfile(GetProfile()); |
| 836 DCHECK(token_service); |
| 837 if (token_service->AreCredentialsValid()) { |
| 838 token_service->StartFetchingTokens(); |
| 839 } else { |
| 840 LOG(WARNING) << "TokenService: credentials are invalid!"; |
| 841 token_service->LoadTokensFromDB(); |
| 842 } |
| 843 if (!service->sync_initialized()) { |
| 844 service->set_setup_in_progress(true); |
| 845 service->UnsuppressAndStart(); |
| 846 DisplaySpinner(); |
| 847 } else { |
| 848 DisplayConfigureSync(true, false); |
| 849 } |
| 850 #endif |
800 } | 851 } |
801 | 852 |
802 ShowSetupUI(); | 853 ShowSetupUI(); |
803 } | 854 } |
804 | 855 |
805 // Private member functions. | 856 // Private member functions. |
806 | 857 |
807 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 858 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
808 LoginUIService* service = GetLoginUIService(); | 859 LoginUIService* service = GetLoginUIService(); |
809 if (!service->current_login_ui()) | 860 if (!service->current_login_ui()) |
(...skipping 30 matching lines...) Expand all Loading... |
840 if (i != current_profile_index && AreUserNamesEqual( | 891 if (i != current_profile_index && AreUserNamesEqual( |
841 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 892 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
842 *error_message = l10n_util::GetStringUTF16( | 893 *error_message = l10n_util::GetStringUTF16( |
843 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 894 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
844 return false; | 895 return false; |
845 } | 896 } |
846 } | 897 } |
847 | 898 |
848 return true; | 899 return true; |
849 } | 900 } |
OLD | NEW |