Chromium Code Reviews| Index: chrome/browser/profiles/profile_manager.cc |
| diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc |
| index 6cf3a09e95103a161d07fcd0d9412409ed14a0e4..50ffcd57eca189748bc6e6c7f080975e43575a04 100644 |
| --- a/chrome/browser/profiles/profile_manager.cc |
| +++ b/chrome/browser/profiles/profile_manager.cc |
| @@ -32,6 +32,7 @@ |
| #include "net/url_request/url_request_context.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #include "net/url_request/url_request_job.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/cros/cros_library.h" |
| @@ -251,6 +252,8 @@ void ProfileManager::CreateProfileAsync(const FilePath& user_data_dir, |
| if (info->created) { |
| // Profile has already been created. Call observer immediately. |
| observer->OnProfileCreated(info->profile.get()); |
| + if (observer->DeleteAfterCreation()) |
| + delete observer; |
|
sail
2011/06/13 19:00:02
I think this was a leak in the old code. Let me kn
Miranda Callahan
2011/06/13 22:08:11
Ah, good catch -- yes, this was skipped before.
|
| } else { |
| // Profile is being created. Add observer to list. |
| info->observers.push_back(observer); |
| @@ -302,6 +305,7 @@ ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile, |
| ProfileInfo* info = new ProfileInfo(profile, created); |
| ProfilesInfoMap::iterator new_elem = |
| (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first; |
| + |
| return info; |
| } |
| @@ -429,3 +433,65 @@ void ProfileManager::RegisterPrefs(PrefService* prefs) { |
| prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); |
| prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
| } |
| + |
| + |
| +size_t ProfileManager::GetNumberOfProfiles() { |
| + const DictionaryValue* path_map = |
| + g_browser_process->local_state()->GetDictionary( |
| + prefs::kProfileDirectoryMap); |
| + return path_map ? path_map->size() : 0; |
| +} |
| + |
| +string16 ProfileManager::GetNameOfProfileAtIndex(size_t index) { |
| + return GetSortedProfilesFromDirectoryMap()[index].second; |
| +} |
| + |
| +FilePath ProfileManager::GetFilePathOfProfileAtIndex( |
| + size_t index, const FilePath& user_data_dir) { |
| + FilePath base_name = GetSortedProfilesFromDirectoryMap()[index].first; |
| + return user_data_dir.Append(base_name); |
| +} |
| + |
| +bool ProfileManager::CompareProfilePathAndName( |
| + const ProfileManager::ProfilePathAndName& pair1, |
| + const ProfileManager::ProfilePathAndName& pair2) { |
| + int name_compare = pair1.second.compare(pair2.second); |
| + if (name_compare < 0) { |
| + return true; |
| + } else if (name_compare > 0) { |
| + return false; |
| + } else { |
| + return pair1.first < pair2.first; |
| + } |
| +} |
| + |
| +ProfileManager::ProfilePathAndNames |
| +ProfileManager::GetSortedProfilesFromDirectoryMap() { |
|
Miranda Callahan
2011/06/13 22:08:11
Is there any reason to not keep these in sorted or
sail
2011/06/13 23:08:46
Do you mean keeping a cache of the profiles as a m
|
| + ProfilePathAndNames profiles; |
| + |
| + const DictionaryValue* path_map = |
| + g_browser_process->local_state()->GetDictionary( |
| + prefs::kProfileDirectoryMap); |
| + if (!path_map) |
| + return profiles; |
| + |
| + for (DictionaryValue::key_iterator it = path_map->begin_keys(); |
| + it != path_map->end_keys(); ++it) { |
| + std::string name_ascii; |
| + path_map->GetString(*it, &name_ascii); |
| + string16 name = ASCIIToUTF16(name_ascii); |
| + if (name.empty()) |
| + name = l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME); |
| +#if defined(OS_POSIX) |
| + FilePath file_path(*it); |
| +#elif defined(OS_WIN) |
| + FilePath file_path(ASCIIToWide(*it)); |
| +#endif |
| + |
| + // Pending, need to insert it alphabetically. |
| + profiles.push_back(std::pair<FilePath, string16>(file_path, name)); |
| + } |
| + |
| + std::sort(profiles.begin(), profiles.end(), CompareProfilePathAndName); |
| + return profiles; |
| +} |