| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
| 20 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
| 21 #include "chrome/browser/lifetime/application_lifetime.h" | 21 #include "chrome/browser/lifetime/application_lifetime.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_info_cache.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/profiles/profile_metrics.h" | 25 #include "chrome/browser/profiles/profile_metrics.h" |
| 26 #include "chrome/browser/signin/signin_manager.h" | |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
| 28 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 30 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
| 31 #include "chrome/browser/ui/browser_navigator.h" | 30 #include "chrome/browser/ui/browser_navigator.h" |
| 32 #include "chrome/browser/ui/sync/signin_histogram.h" | 31 #include "chrome/browser/ui/sync/signin_histogram.h" |
| 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 34 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 33 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 34 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 36 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 35 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 37 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 40 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 41 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/browser/web_contents_delegate.h" | 41 #include "content/public/browser/web_contents_delegate.h" |
| 43 #include "google_apis/gaia/gaia_auth_util.h" | 42 #include "google_apis/gaia/gaia_auth_util.h" |
| 44 #include "google_apis/gaia/gaia_constants.h" | 43 #include "google_apis/gaia/gaia_constants.h" |
| 45 #include "grit/chromium_strings.h" | 44 #include "grit/chromium_strings.h" |
| 46 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 47 #include "grit/locale_settings.h" | 46 #include "grit/locale_settings.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 49 | 48 |
| 49 #if defined(OS_CHROMEOS) |
| 50 #include "chrome/browser/signin/signin_manager_base.h" |
| 51 #else |
| 52 #include "chrome/browser/signin/signin_manager.h" |
| 53 #endif |
| 54 |
| 50 using content::WebContents; | 55 using content::WebContents; |
| 51 using l10n_util::GetStringFUTF16; | 56 using l10n_util::GetStringFUTF16; |
| 52 using l10n_util::GetStringUTF16; | 57 using l10n_util::GetStringUTF16; |
| 53 | 58 |
| 54 namespace { | 59 namespace { |
| 55 | 60 |
| 56 // A structure which contains all the configuration information for sync. | 61 // A structure which contains all the configuration information for sync. |
| 57 struct SyncConfigInfo { | 62 struct SyncConfigInfo { |
| 58 SyncConfigInfo(); | 63 SyncConfigInfo(); |
| 59 ~SyncConfigInfo(); | 64 ~SyncConfigInfo(); |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 LoginUIService* service = GetLoginUIService(); | 568 LoginUIService* service = GetLoginUIService(); |
| 564 return service && (service->current_login_ui() == this); | 569 return service && (service->current_login_ui() == this); |
| 565 } | 570 } |
| 566 | 571 |
| 567 void SyncSetupHandler::RegisterMessages() { | 572 void SyncSetupHandler::RegisterMessages() { |
| 568 web_ui()->RegisterMessageCallback( | 573 web_ui()->RegisterMessageCallback( |
| 569 "SyncSetupDidClosePage", | 574 "SyncSetupDidClosePage", |
| 570 base::Bind(&SyncSetupHandler::OnDidClosePage, | 575 base::Bind(&SyncSetupHandler::OnDidClosePage, |
| 571 base::Unretained(this))); | 576 base::Unretained(this))); |
| 572 web_ui()->RegisterMessageCallback( | 577 web_ui()->RegisterMessageCallback( |
| 573 "SyncSetupSubmitAuth", | |
| 574 base::Bind(&SyncSetupHandler::HandleSubmitAuth, | |
| 575 base::Unretained(this))); | |
| 576 web_ui()->RegisterMessageCallback( | |
| 577 "SyncSetupConfigure", | 578 "SyncSetupConfigure", |
| 578 base::Bind(&SyncSetupHandler::HandleConfigure, | 579 base::Bind(&SyncSetupHandler::HandleConfigure, |
| 579 base::Unretained(this))); | 580 base::Unretained(this))); |
| 580 web_ui()->RegisterMessageCallback( | 581 web_ui()->RegisterMessageCallback( |
| 581 "SyncSetupShowErrorUI", | 582 "SyncSetupShowErrorUI", |
| 582 base::Bind(&SyncSetupHandler::HandleShowErrorUI, | 583 base::Bind(&SyncSetupHandler::HandleShowErrorUI, |
| 583 base::Unretained(this))); | 584 base::Unretained(this))); |
| 584 web_ui()->RegisterMessageCallback( | 585 web_ui()->RegisterMessageCallback( |
| 585 "SyncSetupShowSetupUI", | 586 "SyncSetupShowSetupUI", |
| 586 base::Bind(&SyncSetupHandler::HandleShowSetupUI, | 587 base::Bind(&SyncSetupHandler::HandleShowSetupUI, |
| 587 base::Unretained(this))); | 588 base::Unretained(this))); |
| 588 web_ui()->RegisterMessageCallback( | 589 web_ui()->RegisterMessageCallback( |
| 589 "SyncSetupShowSetupUIWithoutLogin", | 590 "SyncSetupShowSetupUIWithoutLogin", |
| 590 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin, | 591 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin, |
| 591 base::Unretained(this))); | 592 base::Unretained(this))); |
| 592 web_ui()->RegisterMessageCallback( | 593 web_ui()->RegisterMessageCallback( |
| 593 "SyncSetupDoSignOutOnAuthError", | 594 "SyncSetupDoSignOutOnAuthError", |
| 594 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError, | 595 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError, |
| 595 base::Unretained(this))); | 596 base::Unretained(this))); |
| 596 web_ui()->RegisterMessageCallback("CloseTimeout", | 597 web_ui()->RegisterMessageCallback("CloseTimeout", |
| 597 base::Bind(&SyncSetupHandler::HandleCloseTimeout, | 598 base::Bind(&SyncSetupHandler::HandleCloseTimeout, |
| 598 base::Unretained(this))); | 599 base::Unretained(this))); |
| 599 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", | 600 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", |
| 600 base::Bind(&SyncSetupHandler::HandleStopSyncing, | 601 base::Bind(&SyncSetupHandler::HandleStopSyncing, |
| 601 base::Unretained(this))); | 602 base::Unretained(this))); |
| 602 } | 603 #if !defined(OS_CHROMEOS) |
| 603 | 604 web_ui()->RegisterMessageCallback( |
| 604 SigninManager* SyncSetupHandler::GetSignin() const { | 605 "SyncSetupSubmitAuth", |
| 605 return SigninManagerFactory::GetForProfile(GetProfile()); | 606 base::Bind(&SyncSetupHandler::HandleSubmitAuth, |
| 607 base::Unretained(this))); |
| 608 #endif |
| 606 } | 609 } |
| 607 | 610 |
| 608 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { | 611 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { |
| 609 if (SyncPromoUI::UseWebBasedSigninFlow()) { | 612 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 610 // Advanced options are no longer being configured if the login screen is | 613 // Advanced options are no longer being configured if the login screen is |
| 611 // visible. If the user exits the signin wizard after this without | 614 // visible. If the user exits the signin wizard after this without |
| 612 // configuring sync, CloseSyncSetup() will ensure they are logged out. | 615 // configuring sync, CloseSyncSetup() will ensure they are logged out. |
| 613 configuring_sync_ = false; | 616 configuring_sync_ = false; |
| 614 | 617 |
| 615 DisplayGaiaLoginInNewTabOrWindow(); | 618 DisplayGaiaLoginInNewTabOrWindow(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 user = last_attempted_user_email_; | 683 user = last_attempted_user_email_; |
| 681 error = last_signin_error_.state(); | 684 error = last_signin_error_.state(); |
| 682 captcha = last_signin_error_.captcha().image_url.spec(); | 685 captcha = last_signin_error_.captcha().image_url.spec(); |
| 683 editable_user = true; | 686 editable_user = true; |
| 684 | 687 |
| 685 if (local_error_message.empty()) | 688 if (local_error_message.empty()) |
| 686 local_error_message = UTF8ToUTF16(last_signin_error_.error_message()); | 689 local_error_message = UTF8ToUTF16(last_signin_error_.error_message()); |
| 687 } else { | 690 } else { |
| 688 // Fresh login attempt - lock in the authenticated username if there is | 691 // Fresh login attempt - lock in the authenticated username if there is |
| 689 // one (don't let the user change it). | 692 // one (don't let the user change it). |
| 690 user = GetSignin()->GetAuthenticatedUsername(); | 693 user = SigninManagerFactory::GetForProfile(GetProfile())-> |
| 694 GetAuthenticatedUsername(); |
| 691 error = 0; | 695 error = 0; |
| 692 editable_user = user.empty(); | 696 editable_user = user.empty(); |
| 693 } | 697 } |
| 694 DictionaryValue args; | 698 DictionaryValue args; |
| 695 args.SetString("user", user); | 699 args.SetString("user", user); |
| 696 args.SetInteger("error", error); | 700 args.SetInteger("error", error); |
| 697 | 701 |
| 698 // If the error is two-factor, then ask for an OTP if the ClientOAuth flow | 702 // If the error is two-factor, then ask for an OTP if the ClientOAuth flow |
| 699 // is enasbled. Otherwise ask for an ASP. If the error is catptcha required, | 703 // is enasbled. Otherwise ask for an ASP. If the error is catptcha required, |
| 700 // then we don't want to show username and password fields if ClientOAuth is | 704 // then we don't want to show username and password fields if ClientOAuth is |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 if (SyncPromoUI::UseWebBasedSigninFlow()) | 789 if (SyncPromoUI::UseWebBasedSigninFlow()) |
| 786 CloseGaiaSigninPage(); | 790 CloseGaiaSigninPage(); |
| 787 | 791 |
| 788 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); | 792 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); |
| 789 } | 793 } |
| 790 | 794 |
| 791 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 795 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
| 792 CloseSyncSetup(); | 796 CloseSyncSetup(); |
| 793 } | 797 } |
| 794 | 798 |
| 799 #if !defined (OS_CHROMEOS) |
| 795 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 800 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
| 796 std::string json; | 801 std::string json; |
| 797 if (!args->GetString(0, &json)) { | 802 if (!args->GetString(0, &json)) { |
| 798 NOTREACHED() << "Could not read JSON argument"; | 803 NOTREACHED() << "Could not read JSON argument"; |
| 799 return; | 804 return; |
| 800 } | 805 } |
| 801 | 806 |
| 802 if (json.empty()) | 807 if (json.empty()) |
| 803 return; | 808 return; |
| 804 | 809 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 // Make sure we are listening for signin traffic. | 847 // Make sure we are listening for signin traffic. |
| 843 if (!signin_tracker_.get()) | 848 if (!signin_tracker_.get()) |
| 844 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); | 849 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); |
| 845 | 850 |
| 846 last_attempted_user_email_ = username; | 851 last_attempted_user_email_ = username; |
| 847 | 852 |
| 848 // User is trying to log in again so reset the cached error. | 853 // User is trying to log in again so reset the cached error. |
| 849 GoogleServiceAuthError current_error = last_signin_error_; | 854 GoogleServiceAuthError current_error = last_signin_error_; |
| 850 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone(); | 855 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 851 | 856 |
| 852 SigninManager* signin = GetSignin(); | 857 SigninManager* signin = SigninManagerFactory::GetForProfile(GetProfile()); |
| 853 | 858 |
| 854 // If we're just being called to provide an ASP, then pass it to the | 859 // If we're just being called to provide an ASP, then pass it to the |
| 855 // SigninManager and wait for the next step. | 860 // SigninManager and wait for the next step. |
| 856 if (!access_code.empty()) { | 861 if (!access_code.empty()) { |
| 857 signin->ProvideSecondFactorAccessCode(access_code); | 862 signin->ProvideSecondFactorAccessCode(access_code); |
| 858 return; | 863 return; |
| 859 } | 864 } |
| 860 | 865 |
| 861 // The user has submitted credentials, which indicates they don't want to | 866 // The user has submitted credentials, which indicates they don't want to |
| 862 // suppress start up anymore. We do this before starting the signin process, | 867 // suppress start up anymore. We do this before starting the signin process, |
| 863 // so the ProfileSyncService knows to listen to the cached password. | 868 // so the ProfileSyncService knows to listen to the cached password. |
| 864 ProfileSyncService* service = GetSyncService(); | 869 ProfileSyncService* service = GetSyncService(); |
| 865 if (service) | 870 if (service) |
| 866 service->UnsuppressAndStart(); | 871 service->UnsuppressAndStart(); |
| 867 | 872 |
| 868 // Kick off a sign-in through the signin manager. | 873 // Kick off a sign-in through the signin manager. |
| 869 signin->StartSignIn(username, password, current_error.captcha().token, | 874 signin->StartSignIn(username, password, current_error.captcha().token, |
| 870 solution); | 875 solution); |
| 871 } | 876 } |
| 877 #endif // !defined (OS_CHROMEOS) |
| 872 | 878 |
| 873 void SyncSetupHandler::GaiaCredentialsValid() { | 879 void SyncSetupHandler::GaiaCredentialsValid() { |
| 874 DCHECK(IsActiveLogin()); | 880 DCHECK(IsActiveLogin()); |
| 875 | 881 |
| 876 // Gaia credentials are valid - update the UI. | 882 // Gaia credentials are valid - update the UI. |
| 877 DisplayGaiaSuccessAndSettingUp(); | 883 DisplayGaiaSuccessAndSettingUp(); |
| 878 } | 884 } |
| 879 | 885 |
| 880 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 886 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
| 881 // Stop a timer to handle timeout in waiting for checking network connection. | 887 // Stop a timer to handle timeout in waiting for checking network connection. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 | 1061 |
| 1056 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) { | 1062 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) { |
| 1057 DLOG(INFO) << "Signing out the user to fix a sync error."; | 1063 DLOG(INFO) << "Signing out the user to fix a sync error."; |
| 1058 chrome::AttemptUserExit(); | 1064 chrome::AttemptUserExit(); |
| 1059 } | 1065 } |
| 1060 | 1066 |
| 1061 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { | 1067 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { |
| 1062 if (GetSyncService()) | 1068 if (GetSyncService()) |
| 1063 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 1069 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 1064 | 1070 |
| 1065 GetSignin()->SignOut(); | 1071 SigninManagerFactory::GetForProfile(GetProfile())->SignOut(); |
| 1066 } | 1072 } |
| 1067 | 1073 |
| 1068 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) { | 1074 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) { |
| 1069 CloseSyncSetup(); | 1075 CloseSyncSetup(); |
| 1070 } | 1076 } |
| 1071 | 1077 |
| 1072 void SyncSetupHandler::CloseSyncSetup() { | 1078 void SyncSetupHandler::CloseSyncSetup() { |
| 1073 // TODO(atwilson): Move UMA tracking of signin events out of sync module. | 1079 // TODO(atwilson): Move UMA tracking of signin events out of sync module. |
| 1074 ProfileSyncService* sync_service = GetSyncService(); | 1080 ProfileSyncService* sync_service = GetSyncService(); |
| 1075 if (IsActiveLogin()) { | 1081 if (IsActiveLogin()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 // scenario: | 1114 // scenario: |
| 1109 // * User signs in while sync is disabled by policy. | 1115 // * User signs in while sync is disabled by policy. |
| 1110 // * Sync is re-enabled by policy. | 1116 // * Sync is re-enabled by policy. |
| 1111 // * User brings up sync setup dialog to do initial sync config. | 1117 // * User brings up sync setup dialog to do initial sync config. |
| 1112 // * User cancels out of the dialog. | 1118 // * User cancels out of the dialog. |
| 1113 // | 1119 // |
| 1114 // This case is indistinguishable from the "one click signin" case where | 1120 // This case is indistinguishable from the "one click signin" case where |
| 1115 // the user checks the "advanced setup" checkbox, then cancels out of | 1121 // the user checks the "advanced setup" checkbox, then cancels out of |
| 1116 // the setup box, which is a much more common scenario, so we do the | 1122 // the setup box, which is a much more common scenario, so we do the |
| 1117 // right thing for the one-click case. | 1123 // right thing for the one-click case. |
| 1118 GetSignin()->SignOut(); | 1124 SigninManagerFactory::GetForProfile(GetProfile())->SignOut(); |
| 1119 } | 1125 } |
| 1120 sync_service->DisableForUser(); | 1126 sync_service->DisableForUser(); |
| 1121 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | 1127 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
| 1122 sync_prefs.SetStartSuppressed(true); | 1128 sync_prefs.SetStartSuppressed(true); |
| 1123 } | 1129 } |
| 1124 sync_service->SetSetupInProgress(false); | 1130 sync_service->SetSetupInProgress(false); |
| 1125 } | 1131 } |
| 1126 | 1132 |
| 1127 // Reset the attempted email address and error, otherwise the sync setup | 1133 // Reset the attempted email address and error, otherwise the sync setup |
| 1128 // overlay in the settings page will stay in whatever error state it was last | 1134 // overlay in the settings page will stay in whatever error state it was last |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1148 // 3) Previously working credentials have expired. | 1154 // 3) Previously working credentials have expired. |
| 1149 // 4) User is already signed in, but App Notifications needs to force another | 1155 // 4) User is already signed in, but App Notifications needs to force another |
| 1150 // login so it can fetch an oauth token (passes force_login=true) | 1156 // login so it can fetch an oauth token (passes force_login=true) |
| 1151 // 5) User is signed in, but has stopped sync via the google dashboard, and | 1157 // 5) User is signed in, but has stopped sync via the google dashboard, and |
| 1152 // signout is prohibited by policy so we need to force a re-auth. | 1158 // signout is prohibited by policy so we need to force a re-auth. |
| 1153 // 6) User clicks [Advanced Settings] button on options page while already | 1159 // 6) User clicks [Advanced Settings] button on options page while already |
| 1154 // logged in. | 1160 // logged in. |
| 1155 // 7) One-click signin (credentials are already available, so should display | 1161 // 7) One-click signin (credentials are already available, so should display |
| 1156 // sync configure UI, not login UI). | 1162 // sync configure UI, not login UI). |
| 1157 // 8) ChromeOS re-enable after disabling sync. | 1163 // 8) ChromeOS re-enable after disabling sync. |
| 1158 SigninManager* signin = GetSignin(); | 1164 SigninManagerBase* signin = |
| 1165 SigninManagerFactory::GetForProfile(GetProfile()); |
| 1159 if (force_login || | 1166 if (force_login || |
| 1160 signin->GetAuthenticatedUsername().empty() || | 1167 signin->GetAuthenticatedUsername().empty() || |
| 1161 #if !defined(OS_CHROMEOS) | 1168 #if !defined(OS_CHROMEOS) |
| 1162 (GetSyncService() && GetSyncService()->IsStartSuppressed()) || | 1169 (GetSyncService() && GetSyncService()->IsStartSuppressed()) || |
| 1163 #endif | 1170 #endif |
| 1164 signin->signin_global_error()->HasMenuItem()) { | 1171 signin->signin_global_error()->HasMenuItem()) { |
| 1165 // User is not logged in, or login has been specially requested - need to | 1172 // User is not logged in, or login has been specially requested - need to |
| 1166 // display login UI (cases 1-4). | 1173 // display login UI (cases 1-4). |
| 1167 DisplayGaiaLogin(false); | 1174 DisplayGaiaLogin(false); |
| 1168 } else { | 1175 } else { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 | 1292 |
| 1286 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, | 1293 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, |
| 1287 string16* error_message) { | 1294 string16* error_message) { |
| 1288 if (username.empty()) | 1295 if (username.empty()) |
| 1289 return true; | 1296 return true; |
| 1290 | 1297 |
| 1291 // Can be null during some unit tests. | 1298 // Can be null during some unit tests. |
| 1292 if (!web_ui()) | 1299 if (!web_ui()) |
| 1293 return true; | 1300 return true; |
| 1294 | 1301 |
| 1295 if (!GetSignin()->IsAllowedUsername(username)) { | 1302 if (!SigninManagerFactory::GetForProfile( |
| 1303 GetProfile())->IsAllowedUsername(username)) { |
| 1296 *error_message = l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_NAME_PROHIBITED); | 1304 *error_message = l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_NAME_PROHIBITED); |
| 1297 return false; | 1305 return false; |
| 1298 } | 1306 } |
| 1299 | 1307 |
| 1300 // If running in a unit test, skip profile check. | 1308 // If running in a unit test, skip profile check. |
| 1301 if (!profile_manager_) | 1309 if (!profile_manager_) |
| 1302 return true; | 1310 return true; |
| 1303 | 1311 |
| 1304 // Check if the username is already in use by another profile. | 1312 // Check if the username is already in use by another profile. |
| 1305 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 1313 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 1306 size_t current_profile_index = | 1314 size_t current_profile_index = |
| 1307 cache.GetIndexOfProfileWithPath(GetProfile()->GetPath()); | 1315 cache.GetIndexOfProfileWithPath(GetProfile()->GetPath()); |
| 1308 string16 username_utf16 = UTF8ToUTF16(username); | 1316 string16 username_utf16 = UTF8ToUTF16(username); |
| 1309 | 1317 |
| 1310 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1318 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 1311 if (i != current_profile_index && AreUserNamesEqual( | 1319 if (i != current_profile_index && AreUserNamesEqual( |
| 1312 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1320 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
| 1313 *error_message = l10n_util::GetStringUTF16( | 1321 *error_message = l10n_util::GetStringUTF16( |
| 1314 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1322 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 1315 return false; | 1323 return false; |
| 1316 } | 1324 } |
| 1317 } | 1325 } |
| 1318 | 1326 |
| 1319 return true; | 1327 return true; |
| 1320 } | 1328 } |
| OLD | NEW |