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 | |
Andrew T Wilson (Slow)
2012/04/03 17:45:13
We should probably close the overlay here though,
kochi
2012/04/03 21:55:29
Done.
| |
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); | |
Andrew T Wilson (Slow)
2012/04/03 17:45:13
Are you sure that's what we want here (not the "Sy
kochi
2012/04/03 21:55:29
I thought this was the intention (before enabling
| |
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(); |
763 GetSignin()->SignOut(); | 783 GetSignin()->SignOut(); |
764 } | 784 } |
765 } | 785 } |
766 | 786 |
767 configuring_sync_ = false; | 787 configuring_sync_ = false; |
768 signin_tracker_.reset(); | 788 signin_tracker_.reset(); |
769 } | 789 } |
(...skipping 18 matching lines...) Expand all Loading... | |
788 | 808 |
789 // Notify services that we are now active. | 809 // Notify services that we are now active. |
790 GetLoginUIService()->SetLoginUI(web_ui()); | 810 GetLoginUIService()->SetLoginUI(web_ui()); |
791 service->set_setup_in_progress(true); | 811 service->set_setup_in_progress(true); |
792 | 812 |
793 if (!force_login && service->HasSyncSetupCompleted()) { | 813 if (!force_login && service->HasSyncSetupCompleted()) { |
794 // User is already logged in. They must have brought up the config wizard | 814 // User is already logged in. They must have brought up the config wizard |
795 // via the "Advanced..." button or the wrench menu. | 815 // via the "Advanced..." button or the wrench menu. |
796 DisplayConfigureSync(true, false); | 816 DisplayConfigureSync(true, false); |
797 } else { | 817 } else { |
818 #if !defined(OS_CHROMEOS) | |
798 // User is not logged in - need to display login UI. | 819 // User is not logged in - need to display login UI. |
799 DisplayGaiaLogin(false); | 820 DisplayGaiaLogin(false); |
821 #else | |
822 // On Chrome OS user is always logged in. Instead of showing login dialog, | |
823 // show spinner until the backend gets ready to configure sync. | |
824 | |
825 // 1. To make PSS:AreCredentialsAvailable() to return true, first we need | |
826 // to unsppress the flag. | |
827 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | |
Andrew T Wilson (Slow)
2012/04/03 17:45:13
Should probably just move this into a helper funct
kochi
2012/04/03 21:55:29
Split this part into a helper function.
For #ifde
| |
828 sync_prefs.SetStartSuppressed(false); | |
829 | |
830 // 2. To listen to the token available notifications, start SigninTracker. | |
831 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); | |
Andrew T Wilson (Slow)
2012/04/03 17:45:13
We don't need a signin tracker in the case that sy
kochi
2012/04/03 21:55:29
But for the case sync backend is stopped, we need
| |
832 TokenService* token_service = | |
833 TokenServiceFactory::GetForProfile(GetProfile()); | |
834 DCHECK(token_service); | |
835 if (token_service->AreCredentialsValid()) { | |
836 token_service->StartFetchingTokens(); | |
Andrew T Wilson (Slow)
2012/04/03 17:45:13
Shouldn't need to do this once you remove SigninMa
kochi
2012/04/03 21:55:29
Removed.
| |
837 } else { | |
838 LOG(WARNING) << "TokenService: credentials are invalid!"; | |
839 token_service->LoadTokensFromDB(); | |
840 } | |
841 if (!service->sync_initialized()) { | |
842 service->set_setup_in_progress(true); | |
Andrew T Wilson (Slow)
2012/04/03 17:45:13
This looks good. In fact, we might want to have th
kochi
2012/04/03 21:55:29
So as not to break non-ChromeOS for now, I'd like
| |
843 service->UnsuppressAndStart(); | |
844 DisplaySpinner(); | |
845 } else { | |
846 DisplayConfigureSync(true, false); | |
847 } | |
848 #endif | |
800 } | 849 } |
801 | 850 |
802 ShowSetupUI(); | 851 ShowSetupUI(); |
803 } | 852 } |
804 | 853 |
805 // Private member functions. | 854 // Private member functions. |
806 | 855 |
807 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 856 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
808 LoginUIService* service = GetLoginUIService(); | 857 LoginUIService* service = GetLoginUIService(); |
809 if (!service->current_login_ui()) | 858 if (!service->current_login_ui()) |
(...skipping 30 matching lines...) Expand all Loading... | |
840 if (i != current_profile_index && AreUserNamesEqual( | 889 if (i != current_profile_index && AreUserNamesEqual( |
841 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 890 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
842 *error_message = l10n_util::GetStringUTF16( | 891 *error_message = l10n_util::GetStringUTF16( |
843 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 892 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
844 return false; | 893 return false; |
845 } | 894 } |
846 } | 895 } |
847 | 896 |
848 return true; | 897 return true; |
849 } | 898 } |
OLD | NEW |