Chromium Code Reviews| 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..ba605ed1aaa1ac94c894ffc1c01a68e0198e4242 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,37 @@ 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; |
| + |
| + // Compare the profile paths. Since the paths are "[userdir]\Profile #", so |
| + // comparisons take care of the numbers represented by # only. |
| + base::FilePath::StringType a_path = a->GetPath().value(); |
| + base::FilePath::StringType b_path = b->GetPath().value(); |
| + if (a_path.length() != b_path.length()) |
|
anthonyvd
2016/02/08 21:58:42
I think this check isn't needed. base::FilePath::S
tapted
2016/02/08 22:33:36
I read this as solving the issue that for profiles
lwchkg
2016/02/10 19:44:20
You're right. If the profile names are the same, t
|
| + return a_path.length() < b_path.length(); |
| + return a_path < b_path; |
| +} |
| + |
| } // namespace |
| ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
| @@ -1361,6 +1395,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) |