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

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: fix override 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 LoginUIService* service = GetLoginUIService(); 555 LoginUIService* service = GetLoginUIService();
551 return service && (service->current_login_ui() == this); 556 return service && (service->current_login_ui() == this);
552 } 557 }
553 558
554 void SyncSetupHandler::RegisterMessages() { 559 void SyncSetupHandler::RegisterMessages() {
555 web_ui()->RegisterMessageCallback( 560 web_ui()->RegisterMessageCallback(
556 "SyncSetupDidClosePage", 561 "SyncSetupDidClosePage",
557 base::Bind(&SyncSetupHandler::OnDidClosePage, 562 base::Bind(&SyncSetupHandler::OnDidClosePage,
558 base::Unretained(this))); 563 base::Unretained(this)));
559 web_ui()->RegisterMessageCallback( 564 web_ui()->RegisterMessageCallback(
560 "SyncSetupSubmitAuth",
561 base::Bind(&SyncSetupHandler::HandleSubmitAuth,
562 base::Unretained(this)));
563 web_ui()->RegisterMessageCallback(
564 "SyncSetupConfigure", 565 "SyncSetupConfigure",
565 base::Bind(&SyncSetupHandler::HandleConfigure, 566 base::Bind(&SyncSetupHandler::HandleConfigure,
566 base::Unretained(this))); 567 base::Unretained(this)));
567 web_ui()->RegisterMessageCallback( 568 web_ui()->RegisterMessageCallback(
568 "SyncSetupAttachHandler", 569 "SyncSetupAttachHandler",
569 base::Bind(&SyncSetupHandler::HandleAttachHandler, 570 base::Bind(&SyncSetupHandler::HandleAttachHandler,
570 base::Unretained(this))); 571 base::Unretained(this)));
571 web_ui()->RegisterMessageCallback( 572 web_ui()->RegisterMessageCallback(
572 "SyncSetupShowErrorUI", 573 "SyncSetupShowErrorUI",
573 base::Bind(&SyncSetupHandler::HandleShowErrorUI, 574 base::Bind(&SyncSetupHandler::HandleShowErrorUI,
574 base::Unretained(this))); 575 base::Unretained(this)));
575 web_ui()->RegisterMessageCallback( 576 web_ui()->RegisterMessageCallback(
576 "SyncSetupShowSetupUI", 577 "SyncSetupShowSetupUI",
577 base::Bind(&SyncSetupHandler::HandleShowSetupUI, 578 base::Bind(&SyncSetupHandler::HandleShowSetupUI,
578 base::Unretained(this))); 579 base::Unretained(this)));
579 web_ui()->RegisterMessageCallback( 580 web_ui()->RegisterMessageCallback(
580 "SyncSetupShowSetupUIWithoutLogin", 581 "SyncSetupShowSetupUIWithoutLogin",
581 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin, 582 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin,
582 base::Unretained(this))); 583 base::Unretained(this)));
583 web_ui()->RegisterMessageCallback( 584 web_ui()->RegisterMessageCallback(
584 "SyncSetupDoSignOutOnAuthError", 585 "SyncSetupDoSignOutOnAuthError",
585 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError, 586 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError,
586 base::Unretained(this))); 587 base::Unretained(this)));
587 web_ui()->RegisterMessageCallback("CloseTimeout", 588 web_ui()->RegisterMessageCallback("CloseTimeout",
588 base::Bind(&SyncSetupHandler::HandleCloseTimeout, 589 base::Bind(&SyncSetupHandler::HandleCloseTimeout,
589 base::Unretained(this))); 590 base::Unretained(this)));
590 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", 591 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing",
591 base::Bind(&SyncSetupHandler::HandleStopSyncing, 592 base::Bind(&SyncSetupHandler::HandleStopSyncing,
592 base::Unretained(this))); 593 base::Unretained(this)));
593 } 594 #if !defined(OS_CHROMEOS)
594 595 web_ui()->RegisterMessageCallback(
595 SigninManager* SyncSetupHandler::GetSignin() const { 596 "SyncSetupSubmitAuth",
596 return SigninManagerFactory::GetForProfile(GetProfile()); 597 base::Bind(&SyncSetupHandler::HandleSubmitAuth,
598 base::Unretained(this)));
599 #endif
597 } 600 }
598 601
599 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { 602 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) {
600 if (SyncPromoUI::UseWebBasedSigninFlow()) { 603 if (SyncPromoUI::UseWebBasedSigninFlow()) {
601 // Advanced options are no longer being configured if the login screen is 604 // Advanced options are no longer being configured if the login screen is
602 // visible. If the user exits the signin wizard after this without 605 // visible. If the user exits the signin wizard after this without
603 // configuring sync, CloseSyncSetup() will ensure they are logged out. 606 // configuring sync, CloseSyncSetup() will ensure they are logged out.
604 configuring_sync_ = false; 607 configuring_sync_ = false;
605 608
606 DisplayGaiaLoginInNewTabOrWindow(); 609 DisplayGaiaLoginInNewTabOrWindow();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 user = last_attempted_user_email_; 674 user = last_attempted_user_email_;
672 error = last_signin_error_.state(); 675 error = last_signin_error_.state();
673 captcha = last_signin_error_.captcha().image_url.spec(); 676 captcha = last_signin_error_.captcha().image_url.spec();
674 editable_user = true; 677 editable_user = true;
675 678
676 if (local_error_message.empty()) 679 if (local_error_message.empty())
677 local_error_message = UTF8ToUTF16(last_signin_error_.error_message()); 680 local_error_message = UTF8ToUTF16(last_signin_error_.error_message());
678 } else { 681 } else {
679 // Fresh login attempt - lock in the authenticated username if there is 682 // Fresh login attempt - lock in the authenticated username if there is
680 // one (don't let the user change it). 683 // one (don't let the user change it).
681 user = GetSignin()->GetAuthenticatedUsername(); 684 user = SigninManagerFactory::GetForProfile(GetProfile())->
685 GetAuthenticatedUsername();
682 error = 0; 686 error = 0;
683 editable_user = user.empty(); 687 editable_user = user.empty();
684 } 688 }
685 DictionaryValue args; 689 DictionaryValue args;
686 args.SetString("user", user); 690 args.SetString("user", user);
687 args.SetInteger("error", error); 691 args.SetInteger("error", error);
688 692
689 // If the error is two-factor, then ask for an OTP if the ClientOAuth flow 693 // If the error is two-factor, then ask for an OTP if the ClientOAuth flow
690 // is enasbled. Otherwise ask for an ASP. If the error is catptcha required, 694 // is enasbled. Otherwise ask for an ASP. If the error is catptcha required,
691 // then we don't want to show username and password fields if ClientOAuth is 695 // 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
776 if (SyncPromoUI::UseWebBasedSigninFlow()) 780 if (SyncPromoUI::UseWebBasedSigninFlow())
777 CloseGaiaSigninPage(); 781 CloseGaiaSigninPage();
778 782
779 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); 783 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp");
780 } 784 }
781 785
782 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { 786 void SyncSetupHandler::OnDidClosePage(const ListValue* args) {
783 CloseSyncSetup(); 787 CloseSyncSetup();
784 } 788 }
785 789
790 #if !defined (OS_CHROMEOS)
786 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { 791 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) {
787 std::string json; 792 std::string json;
788 if (!args->GetString(0, &json)) { 793 if (!args->GetString(0, &json)) {
789 NOTREACHED() << "Could not read JSON argument"; 794 NOTREACHED() << "Could not read JSON argument";
790 return; 795 return;
791 } 796 }
792 797
793 if (json.empty()) 798 if (json.empty())
794 return; 799 return;
795 800
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 // Make sure we are listening for signin traffic. 838 // Make sure we are listening for signin traffic.
834 if (!signin_tracker_.get()) 839 if (!signin_tracker_.get())
835 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); 840 signin_tracker_.reset(new SigninTracker(GetProfile(), this));
836 841
837 last_attempted_user_email_ = username; 842 last_attempted_user_email_ = username;
838 843
839 // User is trying to log in again so reset the cached error. 844 // User is trying to log in again so reset the cached error.
840 GoogleServiceAuthError current_error = last_signin_error_; 845 GoogleServiceAuthError current_error = last_signin_error_;
841 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone(); 846 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone();
842 847
843 SigninManager* signin = GetSignin(); 848 SigninManager* signin = SigninManagerFactory::GetForProfile(GetProfile());
844 849
845 // If we're just being called to provide an ASP, then pass it to the 850 // If we're just being called to provide an ASP, then pass it to the
846 // SigninManager and wait for the next step. 851 // SigninManager and wait for the next step.
847 if (!access_code.empty()) { 852 if (!access_code.empty()) {
848 signin->ProvideSecondFactorAccessCode(access_code); 853 signin->ProvideSecondFactorAccessCode(access_code);
849 return; 854 return;
850 } 855 }
851 856
852 // The user has submitted credentials, which indicates they don't want to 857 // The user has submitted credentials, which indicates they don't want to
853 // suppress start up anymore. We do this before starting the signin process, 858 // suppress start up anymore. We do this before starting the signin process,
854 // so the ProfileSyncService knows to listen to the cached password. 859 // so the ProfileSyncService knows to listen to the cached password.
855 ProfileSyncService* service = GetSyncService(); 860 ProfileSyncService* service = GetSyncService();
856 if (service) 861 if (service)
857 service->UnsuppressAndStart(); 862 service->UnsuppressAndStart();
858 863
859 // Kick off a sign-in through the signin manager. 864 // Kick off a sign-in through the signin manager.
860 signin->StartSignIn(username, password, current_error.captcha().token, 865 signin->StartSignIn(username, password, current_error.captcha().token,
861 solution); 866 solution);
862 } 867 }
868 #endif // !defined (OS_CHROMEOS)
863 869
864 void SyncSetupHandler::GaiaCredentialsValid() { 870 void SyncSetupHandler::GaiaCredentialsValid() {
865 DCHECK(IsActiveLogin()); 871 DCHECK(IsActiveLogin());
866 872
867 // Gaia credentials are valid - update the UI. 873 // Gaia credentials are valid - update the UI.
868 DisplayGaiaSuccessAndSettingUp(); 874 DisplayGaiaSuccessAndSettingUp();
869 } 875 }
870 876
871 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { 877 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) {
872 // Stop a timer to handle timeout in waiting for checking network connection. 878 // Stop a timer to handle timeout in waiting for checking network connection.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1064
1059 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) { 1065 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) {
1060 DLOG(INFO) << "Signing out the user to fix a sync error."; 1066 DLOG(INFO) << "Signing out the user to fix a sync error.";
1061 chrome::AttemptUserExit(); 1067 chrome::AttemptUserExit();
1062 } 1068 }
1063 1069
1064 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { 1070 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) {
1065 if (GetSyncService()) 1071 if (GetSyncService())
1066 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 1072 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
1067 1073
1068 GetSignin()->SignOut(); 1074 SigninManagerFactory::GetForProfile(GetProfile())->SignOut();
1069 } 1075 }
1070 1076
1071 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) { 1077 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) {
1072 CloseSyncSetup(); 1078 CloseSyncSetup();
1073 } 1079 }
1074 1080
1075 void SyncSetupHandler::CloseSyncSetup() { 1081 void SyncSetupHandler::CloseSyncSetup() {
1076 // TODO(atwilson): Move UMA tracking of signin events out of sync module. 1082 // TODO(atwilson): Move UMA tracking of signin events out of sync module.
1077 ProfileSyncService* sync_service = GetSyncService(); 1083 ProfileSyncService* sync_service = GetSyncService();
1078 if (IsActiveLogin()) { 1084 if (IsActiveLogin()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 // scenario: 1117 // scenario:
1112 // * User signs in while sync is disabled by policy. 1118 // * User signs in while sync is disabled by policy.
1113 // * Sync is re-enabled by policy. 1119 // * Sync is re-enabled by policy.
1114 // * User brings up sync setup dialog to do initial sync config. 1120 // * User brings up sync setup dialog to do initial sync config.
1115 // * User cancels out of the dialog. 1121 // * User cancels out of the dialog.
1116 // 1122 //
1117 // This case is indistinguishable from the "one click signin" case where 1123 // This case is indistinguishable from the "one click signin" case where
1118 // the user checks the "advanced setup" checkbox, then cancels out of 1124 // the user checks the "advanced setup" checkbox, then cancels out of
1119 // the setup box, which is a much more common scenario, so we do the 1125 // the setup box, which is a much more common scenario, so we do the
1120 // right thing for the one-click case. 1126 // right thing for the one-click case.
1121 GetSignin()->SignOut(); 1127 SigninManagerFactory::GetForProfile(GetProfile())->SignOut();
1122 } 1128 }
1123 sync_service->DisableForUser(); 1129 sync_service->DisableForUser();
1124 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); 1130 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
1125 sync_prefs.SetStartSuppressed(true); 1131 sync_prefs.SetStartSuppressed(true);
1126 } 1132 }
1127 sync_service->SetSetupInProgress(false); 1133 sync_service->SetSetupInProgress(false);
1128 } 1134 }
1129 1135
1130 // Reset the attempted email address and error, otherwise the sync setup 1136 // Reset the attempted email address and error, otherwise the sync setup
1131 // overlay in the settings page will stay in whatever error state it was last 1137 // overlay in the settings page will stay in whatever error state it was last
(...skipping 19 matching lines...) Expand all
1151 // 3) Previously working credentials have expired. 1157 // 3) Previously working credentials have expired.
1152 // 4) User is already signed in, but App Notifications needs to force another 1158 // 4) User is already signed in, but App Notifications needs to force another
1153 // login so it can fetch an oauth token (passes force_login=true) 1159 // login so it can fetch an oauth token (passes force_login=true)
1154 // 5) User is signed in, but has stopped sync via the google dashboard, and 1160 // 5) User is signed in, but has stopped sync via the google dashboard, and
1155 // signout is prohibited by policy so we need to force a re-auth. 1161 // signout is prohibited by policy so we need to force a re-auth.
1156 // 6) User clicks [Advanced Settings] button on options page while already 1162 // 6) User clicks [Advanced Settings] button on options page while already
1157 // logged in. 1163 // logged in.
1158 // 7) One-click signin (credentials are already available, so should display 1164 // 7) One-click signin (credentials are already available, so should display
1159 // sync configure UI, not login UI). 1165 // sync configure UI, not login UI).
1160 // 8) ChromeOS re-enable after disabling sync. 1166 // 8) ChromeOS re-enable after disabling sync.
1161 SigninManager* signin = GetSignin(); 1167 SigninManagerBase* signin =
1168 SigninManagerFactory::GetForProfile(GetProfile());
1162 if (force_login || 1169 if (force_login ||
1163 signin->GetAuthenticatedUsername().empty() || 1170 signin->GetAuthenticatedUsername().empty() ||
1164 #if !defined(OS_CHROMEOS) 1171 #if !defined(OS_CHROMEOS)
1165 (GetSyncService() && GetSyncService()->IsStartSuppressed()) || 1172 (GetSyncService() && GetSyncService()->IsStartSuppressed()) ||
1166 #endif 1173 #endif
1167 signin->signin_global_error()->HasMenuItem()) { 1174 signin->signin_global_error()->HasMenuItem()) {
1168 // User is not logged in, or login has been specially requested - need to 1175 // User is not logged in, or login has been specially requested - need to
1169 // display login UI (cases 1-4). 1176 // display login UI (cases 1-4).
1170 DisplayGaiaLogin(false); 1177 DisplayGaiaLogin(false);
1171 } else { 1178 } else {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1301
1295 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, 1302 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username,
1296 string16* error_message) { 1303 string16* error_message) {
1297 if (username.empty()) 1304 if (username.empty())
1298 return true; 1305 return true;
1299 1306
1300 // Can be null during some unit tests. 1307 // Can be null during some unit tests.
1301 if (!web_ui()) 1308 if (!web_ui())
1302 return true; 1309 return true;
1303 1310
1304 if (!GetSignin()->IsAllowedUsername(username)) { 1311 if (!SigninManagerFactory::GetForProfile(
1312 GetProfile())->IsAllowedUsername(username)) {
1305 *error_message = l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_NAME_PROHIBITED); 1313 *error_message = l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_NAME_PROHIBITED);
1306 return false; 1314 return false;
1307 } 1315 }
1308 1316
1309 // If running in a unit test, skip profile check. 1317 // If running in a unit test, skip profile check.
1310 if (!profile_manager_) 1318 if (!profile_manager_)
1311 return true; 1319 return true;
1312 1320
1313 // Check if the username is already in use by another profile. 1321 // Check if the username is already in use by another profile.
1314 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 1322 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
1315 size_t current_profile_index = 1323 size_t current_profile_index =
1316 cache.GetIndexOfProfileWithPath(GetProfile()->GetPath()); 1324 cache.GetIndexOfProfileWithPath(GetProfile()->GetPath());
1317 string16 username_utf16 = UTF8ToUTF16(username); 1325 string16 username_utf16 = UTF8ToUTF16(username);
1318 1326
1319 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 1327 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
1320 if (i != current_profile_index && AreUserNamesEqual( 1328 if (i != current_profile_index && AreUserNamesEqual(
1321 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1329 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1322 *error_message = l10n_util::GetStringUTF16( 1330 *error_message = l10n_util::GetStringUTF16(
1323 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1331 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1324 return false; 1332 return false;
1325 } 1333 }
1326 } 1334 }
1327 1335
1328 return true; 1336 return true;
1329 } 1337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698