Index: chrome/browser/profiles/profile_info_cache.cc |
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc |
index 12ad997b4c6f1c11d5e17cc0780fed5e967cc5f7..34ad387f898577124745366faa348aad8d01e69b 100644 |
--- a/chrome/browser/profiles/profile_info_cache.cc |
+++ b/chrome/browser/profiles/profile_info_cache.cc |
@@ -4,11 +4,13 @@ |
#include "chrome/browser/profiles/profile_info_cache.h" |
+#include <algorithm> |
#include <utility> |
#include "base/bind.h" |
#include "base/files/file_util.h" |
#include "base/i18n/case_conversion.h" |
+#include "base/i18n/string_compare.h" |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/memory/scoped_ptr.h" |
@@ -31,6 +33,7 @@ |
#include "components/prefs/scoped_user_pref_update.h" |
#include "components/signin/core/common/profile_management_switches.h" |
#include "content/public/browser/browser_thread.h" |
+#include "third_party/icu/source/i18n/unicode/coll.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/image/image.h" |
@@ -157,6 +160,32 @@ void DeleteBitmap(const base::FilePath& image_path) { |
base::DeleteFile(image_path, false); |
} |
+// Compares two ProfileAttributesEntry using locale-sensitive comparison of |
+// their names. For ties, the profile path is compared next. |
+class ProfileAttributesSortComparator { |
+ public: |
+ explicit ProfileAttributesSortComparator(icu::Collator* collator); |
+ bool operator()(const ProfileAttributesEntry* const a, |
+ const ProfileAttributesEntry* const b) const; |
+ private: |
+ icu::Collator* collator_; |
+}; |
+ |
+ProfileAttributesSortComparator::ProfileAttributesSortComparator( |
+ icu::Collator* collator) : collator_(collator) {} |
+ |
+bool ProfileAttributesSortComparator::operator()( |
+ const ProfileAttributesEntry* const a, |
+ const ProfileAttributesEntry* const b) const { |
+ UCollationResult result = base::i18n::CompareString16WithCollator( |
+ *collator_, a->GetName(), b->GetName()); |
+ if (result != UCOL_EQUAL) |
+ return result == UCOL_LESS; |
+ |
+ // If the names are the same, then compare the paths, which must be unique. |
+ return a->GetPath().value() < b->GetPath().value(); |
+} |
+ |
} // namespace |
ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
@@ -1361,6 +1390,20 @@ ProfileInfoCache::GetAllProfilesAttributes() { |
return ret; |
} |
+std::vector<ProfileAttributesEntry*> |
+ProfileInfoCache::GetAllProfilesAttributesSortedByName() { |
+ UErrorCode error_code = U_ZERO_ERROR; |
+ // Use the default collator. The default locale should have been properly |
+ // set by the time this constructor is called. |
+ scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); |
+ DCHECK(U_SUCCESS(error_code)); |
+ |
+ std::vector<ProfileAttributesEntry*> ret = GetAllProfilesAttributes(); |
+ std::sort(ret.begin(), ret.end(), |
+ ProfileAttributesSortComparator(collator.get())); |
+ return ret; |
+} |
+ |
bool ProfileInfoCache::GetProfileAttributesWithPath( |
const base::FilePath& path, ProfileAttributesEntry** entry) { |
if (GetNumberOfProfiles() == 0) |