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

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

Issue 12502017: signin: pull basic SigninManager functionality into new SigninManagerBase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: megarebase Created 7 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/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
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 "SyncSetupAttachHandler", 582 "SyncSetupAttachHandler",
582 base::Bind(&SyncSetupHandler::HandleAttachHandler, 583 base::Bind(&SyncSetupHandler::HandleAttachHandler,
583 base::Unretained(this))); 584 base::Unretained(this)));
584 web_ui()->RegisterMessageCallback( 585 web_ui()->RegisterMessageCallback(
585 "SyncSetupShowErrorUI", 586 "SyncSetupShowErrorUI",
586 base::Bind(&SyncSetupHandler::HandleShowErrorUI, 587 base::Bind(&SyncSetupHandler::HandleShowErrorUI,
587 base::Unretained(this))); 588 base::Unretained(this)));
588 web_ui()->RegisterMessageCallback( 589 web_ui()->RegisterMessageCallback(
589 "SyncSetupShowSetupUI", 590 "SyncSetupShowSetupUI",
590 base::Bind(&SyncSetupHandler::HandleShowSetupUI, 591 base::Bind(&SyncSetupHandler::HandleShowSetupUI,
591 base::Unretained(this))); 592 base::Unretained(this)));
592 web_ui()->RegisterMessageCallback( 593 web_ui()->RegisterMessageCallback(
593 "SyncSetupShowSetupUIWithoutLogin", 594 "SyncSetupShowSetupUIWithoutLogin",
594 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin, 595 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin,
595 base::Unretained(this))); 596 base::Unretained(this)));
596 web_ui()->RegisterMessageCallback( 597 web_ui()->RegisterMessageCallback(
597 "SyncSetupDoSignOutOnAuthError", 598 "SyncSetupDoSignOutOnAuthError",
598 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError, 599 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError,
599 base::Unretained(this))); 600 base::Unretained(this)));
600 web_ui()->RegisterMessageCallback("CloseTimeout", 601 web_ui()->RegisterMessageCallback("CloseTimeout",
601 base::Bind(&SyncSetupHandler::HandleCloseTimeout, 602 base::Bind(&SyncSetupHandler::HandleCloseTimeout,
602 base::Unretained(this))); 603 base::Unretained(this)));
603 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", 604 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing",
604 base::Bind(&SyncSetupHandler::HandleStopSyncing, 605 base::Bind(&SyncSetupHandler::HandleStopSyncing,
605 base::Unretained(this))); 606 base::Unretained(this)));
606 } 607 #if !defined(OS_CHROMEOS)
607 608 web_ui()->RegisterMessageCallback(
608 SigninManager* SyncSetupHandler::GetSignin() const { 609 "SyncSetupSubmitAuth",
609 return SigninManagerFactory::GetForProfile(GetProfile()); 610 base::Bind(&SyncSetupHandler::HandleSubmitAuth,
611 base::Unretained(this)));
612 #endif
610 } 613 }
611 614
612 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { 615 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) {
613 if (SyncPromoUI::UseWebBasedSigninFlow()) { 616 if (SyncPromoUI::UseWebBasedSigninFlow()) {
614 // Advanced options are no longer being configured if the login screen is 617 // Advanced options are no longer being configured if the login screen is
615 // visible. If the user exits the signin wizard after this without 618 // visible. If the user exits the signin wizard after this without
616 // configuring sync, CloseSyncSetup() will ensure they are logged out. 619 // configuring sync, CloseSyncSetup() will ensure they are logged out.
617 configuring_sync_ = false; 620 configuring_sync_ = false;
618 621
619 DisplayGaiaLoginInNewTabOrWindow(); 622 DisplayGaiaLoginInNewTabOrWindow();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 user = last_attempted_user_email_; 687 user = last_attempted_user_email_;
685 error = last_signin_error_.state(); 688 error = last_signin_error_.state();
686 captcha = last_signin_error_.captcha().image_url.spec(); 689 captcha = last_signin_error_.captcha().image_url.spec();
687 editable_user = true; 690 editable_user = true;
688 691
689 if (local_error_message.empty()) 692 if (local_error_message.empty())
690 local_error_message = UTF8ToUTF16(last_signin_error_.error_message()); 693 local_error_message = UTF8ToUTF16(last_signin_error_.error_message());
691 } else { 694 } else {
692 // Fresh login attempt - lock in the authenticated username if there is 695 // Fresh login attempt - lock in the authenticated username if there is
693 // one (don't let the user change it). 696 // one (don't let the user change it).
694 user = GetSignin()->GetAuthenticatedUsername(); 697 user = SigninManagerFactory::GetForProfile(GetProfile())->
698 GetAuthenticatedUsername();
695 error = 0; 699 error = 0;
696 editable_user = user.empty(); 700 editable_user = user.empty();
697 } 701 }
698 DictionaryValue args; 702 DictionaryValue args;
699 args.SetString("user", user); 703 args.SetString("user", user);
700 args.SetInteger("error", error); 704 args.SetInteger("error", error);
701 705
702 // If the error is two-factor, then ask for an OTP if the ClientOAuth flow 706 // If the error is two-factor, then ask for an OTP if the ClientOAuth flow
703 // is enasbled. Otherwise ask for an ASP. If the error is catptcha required, 707 // is enasbled. Otherwise ask for an ASP. If the error is catptcha required,
704 // then we don't want to show username and password fields if ClientOAuth is 708 // 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
789 if (SyncPromoUI::UseWebBasedSigninFlow()) 793 if (SyncPromoUI::UseWebBasedSigninFlow())
790 CloseGaiaSigninPage(); 794 CloseGaiaSigninPage();
791 795
792 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); 796 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp");
793 } 797 }
794 798
795 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { 799 void SyncSetupHandler::OnDidClosePage(const ListValue* args) {
796 CloseSyncSetup(); 800 CloseSyncSetup();
797 } 801 }
798 802
803 #if !defined (OS_CHROMEOS)
799 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { 804 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) {
800 std::string json; 805 std::string json;
801 if (!args->GetString(0, &json)) { 806 if (!args->GetString(0, &json)) {
802 NOTREACHED() << "Could not read JSON argument"; 807 NOTREACHED() << "Could not read JSON argument";
803 return; 808 return;
804 } 809 }
805 810
806 if (json.empty()) 811 if (json.empty())
807 return; 812 return;
808 813
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 // Make sure we are listening for signin traffic. 851 // Make sure we are listening for signin traffic.
847 if (!signin_tracker_.get()) 852 if (!signin_tracker_.get())
848 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); 853 signin_tracker_.reset(new SigninTracker(GetProfile(), this));
849 854
850 last_attempted_user_email_ = username; 855 last_attempted_user_email_ = username;
851 856
852 // User is trying to log in again so reset the cached error. 857 // User is trying to log in again so reset the cached error.
853 GoogleServiceAuthError current_error = last_signin_error_; 858 GoogleServiceAuthError current_error = last_signin_error_;
854 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone(); 859 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone();
855 860
856 SigninManager* signin = GetSignin(); 861 SigninManager* signin = SigninManagerFactory::GetForProfile(GetProfile());
857 862
858 // If we're just being called to provide an ASP, then pass it to the 863 // If we're just being called to provide an ASP, then pass it to the
859 // SigninManager and wait for the next step. 864 // SigninManager and wait for the next step.
860 if (!access_code.empty()) { 865 if (!access_code.empty()) {
861 signin->ProvideSecondFactorAccessCode(access_code); 866 signin->ProvideSecondFactorAccessCode(access_code);
862 return; 867 return;
863 } 868 }
864 869
865 // The user has submitted credentials, which indicates they don't want to 870 // The user has submitted credentials, which indicates they don't want to
866 // suppress start up anymore. We do this before starting the signin process, 871 // suppress start up anymore. We do this before starting the signin process,
867 // so the ProfileSyncService knows to listen to the cached password. 872 // so the ProfileSyncService knows to listen to the cached password.
868 ProfileSyncService* service = GetSyncService(); 873 ProfileSyncService* service = GetSyncService();
869 if (service) 874 if (service)
870 service->UnsuppressAndStart(); 875 service->UnsuppressAndStart();
871 876
872 // Kick off a sign-in through the signin manager. 877 // Kick off a sign-in through the signin manager.
873 signin->StartSignIn(username, password, current_error.captcha().token, 878 signin->StartSignIn(username, password, current_error.captcha().token,
874 solution); 879 solution);
875 } 880 }
881 #endif // !defined (OS_CHROMEOS)
876 882
877 void SyncSetupHandler::GaiaCredentialsValid() { 883 void SyncSetupHandler::GaiaCredentialsValid() {
878 DCHECK(IsActiveLogin()); 884 DCHECK(IsActiveLogin());
879 885
880 // Gaia credentials are valid - update the UI. 886 // Gaia credentials are valid - update the UI.
881 DisplayGaiaSuccessAndSettingUp(); 887 DisplayGaiaSuccessAndSettingUp();
882 } 888 }
883 889
884 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { 890 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) {
885 // Stop a timer to handle timeout in waiting for checking network connection. 891 // Stop a timer to handle timeout in waiting for checking network connection.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1077
1072 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) { 1078 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) {
1073 DLOG(INFO) << "Signing out the user to fix a sync error."; 1079 DLOG(INFO) << "Signing out the user to fix a sync error.";
1074 chrome::AttemptUserExit(); 1080 chrome::AttemptUserExit();
1075 } 1081 }
1076 1082
1077 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { 1083 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) {
1078 if (GetSyncService()) 1084 if (GetSyncService())
1079 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 1085 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
1080 1086
1081 GetSignin()->SignOut(); 1087 SigninManagerFactory::GetForProfile(GetProfile())->SignOut();
1082 } 1088 }
1083 1089
1084 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) { 1090 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) {
1085 CloseSyncSetup(); 1091 CloseSyncSetup();
1086 } 1092 }
1087 1093
1088 void SyncSetupHandler::CloseSyncSetup() { 1094 void SyncSetupHandler::CloseSyncSetup() {
1089 // TODO(atwilson): Move UMA tracking of signin events out of sync module. 1095 // TODO(atwilson): Move UMA tracking of signin events out of sync module.
1090 ProfileSyncService* sync_service = GetSyncService(); 1096 ProfileSyncService* sync_service = GetSyncService();
1091 if (IsActiveLogin()) { 1097 if (IsActiveLogin()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 // scenario: 1130 // scenario:
1125 // * User signs in while sync is disabled by policy. 1131 // * User signs in while sync is disabled by policy.
1126 // * Sync is re-enabled by policy. 1132 // * Sync is re-enabled by policy.
1127 // * User brings up sync setup dialog to do initial sync config. 1133 // * User brings up sync setup dialog to do initial sync config.
1128 // * User cancels out of the dialog. 1134 // * User cancels out of the dialog.
1129 // 1135 //
1130 // This case is indistinguishable from the "one click signin" case where 1136 // This case is indistinguishable from the "one click signin" case where
1131 // the user checks the "advanced setup" checkbox, then cancels out of 1137 // the user checks the "advanced setup" checkbox, then cancels out of
1132 // the setup box, which is a much more common scenario, so we do the 1138 // the setup box, which is a much more common scenario, so we do the
1133 // right thing for the one-click case. 1139 // right thing for the one-click case.
1134 GetSignin()->SignOut(); 1140 SigninManagerFactory::GetForProfile(GetProfile())->SignOut();
1135 } 1141 }
1136 sync_service->DisableForUser(); 1142 sync_service->DisableForUser();
1137 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); 1143 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
1138 sync_prefs.SetStartSuppressed(true); 1144 sync_prefs.SetStartSuppressed(true);
1139 } 1145 }
1140 sync_service->SetSetupInProgress(false); 1146 sync_service->SetSetupInProgress(false);
1141 } 1147 }
1142 1148
1143 // Reset the attempted email address and error, otherwise the sync setup 1149 // Reset the attempted email address and error, otherwise the sync setup
1144 // overlay in the settings page will stay in whatever error state it was last 1150 // overlay in the settings page will stay in whatever error state it was last
(...skipping 19 matching lines...) Expand all
1164 // 3) Previously working credentials have expired. 1170 // 3) Previously working credentials have expired.
1165 // 4) User is already signed in, but App Notifications needs to force another 1171 // 4) User is already signed in, but App Notifications needs to force another
1166 // login so it can fetch an oauth token (passes force_login=true) 1172 // login so it can fetch an oauth token (passes force_login=true)
1167 // 5) User is signed in, but has stopped sync via the google dashboard, and 1173 // 5) User is signed in, but has stopped sync via the google dashboard, and
1168 // signout is prohibited by policy so we need to force a re-auth. 1174 // signout is prohibited by policy so we need to force a re-auth.
1169 // 6) User clicks [Advanced Settings] button on options page while already 1175 // 6) User clicks [Advanced Settings] button on options page while already
1170 // logged in. 1176 // logged in.
1171 // 7) One-click signin (credentials are already available, so should display 1177 // 7) One-click signin (credentials are already available, so should display
1172 // sync configure UI, not login UI). 1178 // sync configure UI, not login UI).
1173 // 8) ChromeOS re-enable after disabling sync. 1179 // 8) ChromeOS re-enable after disabling sync.
1174 SigninManager* signin = GetSignin(); 1180 SigninManagerBase* signin =
1181 SigninManagerFactory::GetForProfile(GetProfile());
1175 if (force_login || 1182 if (force_login ||
1176 signin->GetAuthenticatedUsername().empty() || 1183 signin->GetAuthenticatedUsername().empty() ||
1177 #if !defined(OS_CHROMEOS) 1184 #if !defined(OS_CHROMEOS)
1178 (GetSyncService() && GetSyncService()->IsStartSuppressed()) || 1185 (GetSyncService() && GetSyncService()->IsStartSuppressed()) ||
1179 #endif 1186 #endif
1180 signin->signin_global_error()->HasMenuItem()) { 1187 signin->signin_global_error()->HasMenuItem()) {
1181 // User is not logged in, or login has been specially requested - need to 1188 // User is not logged in, or login has been specially requested - need to
1182 // display login UI (cases 1-4). 1189 // display login UI (cases 1-4).
1183 DisplayGaiaLogin(false); 1190 DisplayGaiaLogin(false);
1184 } else { 1191 } else {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 1308
1302 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, 1309 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username,
1303 string16* error_message) { 1310 string16* error_message) {
1304 if (username.empty()) 1311 if (username.empty())
1305 return true; 1312 return true;
1306 1313
1307 // Can be null during some unit tests. 1314 // Can be null during some unit tests.
1308 if (!web_ui()) 1315 if (!web_ui())
1309 return true; 1316 return true;
1310 1317
1311 if (!GetSignin()->IsAllowedUsername(username)) { 1318 if (!SigninManagerFactory::GetForProfile(
1319 GetProfile())->IsAllowedUsername(username)) {
1312 *error_message = l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_NAME_PROHIBITED); 1320 *error_message = l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_NAME_PROHIBITED);
1313 return false; 1321 return false;
1314 } 1322 }
1315 1323
1316 // If running in a unit test, skip profile check. 1324 // If running in a unit test, skip profile check.
1317 if (!profile_manager_) 1325 if (!profile_manager_)
1318 return true; 1326 return true;
1319 1327
1320 // Check if the username is already in use by another profile. 1328 // Check if the username is already in use by another profile.
1321 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 1329 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
1322 size_t current_profile_index = 1330 size_t current_profile_index =
1323 cache.GetIndexOfProfileWithPath(GetProfile()->GetPath()); 1331 cache.GetIndexOfProfileWithPath(GetProfile()->GetPath());
1324 string16 username_utf16 = UTF8ToUTF16(username); 1332 string16 username_utf16 = UTF8ToUTF16(username);
1325 1333
1326 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 1334 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
1327 if (i != current_profile_index && AreUserNamesEqual( 1335 if (i != current_profile_index && AreUserNamesEqual(
1328 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1336 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1329 *error_message = l10n_util::GetStringUTF16( 1337 *error_message = l10n_util::GetStringUTF16(
1330 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1338 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1331 return false; 1339 return false;
1332 } 1340 }
1333 } 1341 }
1334 1342
1335 return true; 1343 return true;
1336 } 1344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698