| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, | 719 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, |
| 720 string16* error_message) { | 720 string16* error_message) { |
| 721 // Happens during unit tests. | 721 // Happens during unit tests. |
| 722 if (!web_ui_ || !profile_manager_) | 722 if (!web_ui_ || !profile_manager_) |
| 723 return true; | 723 return true; |
| 724 | 724 |
| 725 if (username.empty()) | 725 if (username.empty()) |
| 726 return true; | 726 return true; |
| 727 | 727 |
| 728 // Check if the username is already in use by another profile. | 728 // Check if the username is already in use by another profile. |
| 729 FilePath cur_path = Profile::FromWebUI(web_ui_)->GetPath(); |
| 730 string16 cur_username = UTF8ToUTF16(username); |
| 731 |
| 729 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 732 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 730 size_t current_profile_index = cache.GetIndexOfProfileWithPath( | 733 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName()); |
| 731 Profile::FromWebUI(web_ui_)->GetPath()); | 734 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 732 string16 username_utf16 = UTF8ToUTF16(username); | 735 it != entries.end(); ++it) { |
| 733 | 736 if (it->path() != cur_path && |
| 734 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 737 AreUserNamesEqual(it->user_name(), cur_username)) { |
| 735 if (i != current_profile_index && AreUserNamesEqual( | |
| 736 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | |
| 737 *error_message = l10n_util::GetStringUTF16( | 738 *error_message = l10n_util::GetStringUTF16( |
| 738 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 739 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 739 return false; | 740 return false; |
| 740 } | 741 } |
| 741 } | 742 } |
| 742 | 743 |
| 743 return true; | 744 return true; |
| 744 } | 745 } |
| 745 | 746 |
| 746 void SyncSetupHandler::ShowLoginErrorMessage(const string16& error_message) { | 747 void SyncSetupHandler::ShowLoginErrorMessage(const string16& error_message) { |
| 747 DictionaryValue args; | 748 DictionaryValue args; |
| 748 Profile* profile = Profile::FromWebUI(web_ui_); | 749 Profile* profile = Profile::FromWebUI(web_ui_); |
| 749 ProfileSyncService* service = profile->GetProfileSyncService(); | 750 ProfileSyncService* service = profile->GetProfileSyncService(); |
| 750 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 751 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
| 751 args.SetString("error_message", error_message); | 752 args.SetString("error_message", error_message); |
| 752 ShowGaiaLogin(args); | 753 ShowGaiaLogin(args); |
| 753 } | 754 } |
| OLD | NEW |