Index: chrome/browser/profiles/profile_attributes_entry.cc |
diff --git a/chrome/browser/profiles/profile_attributes_entry.cc b/chrome/browser/profiles/profile_attributes_entry.cc |
index 3adf2a0bffd53c2632b46826be473144bed427bc..d3574351981423a356212e7589db80446e169674 100644 |
--- a/chrome/browser/profiles/profile_attributes_entry.cc |
+++ b/chrome/browser/profiles/profile_attributes_entry.cc |
@@ -3,8 +3,35 @@ |
// found in the LICENSE file. |
#include "chrome/browser/profiles/profile_attributes_entry.h" |
+ |
+#include "base/i18n/string_compare.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
+ProfileAttributesEntry::SortComparator::SortComparator() { |
+ 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. |
+ collator_.reset(icu::Collator::createInstance(error_code)); |
+ DCHECK(U_SUCCESS(error_code)); |
tapted
2016/02/04 23:10:35
After looking at SortVectorWithStringKey from ui/b
|
+} |
+ |
+bool ProfileAttributesEntry::SortComparator::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()) |
+ return a_path.length() < b_path.length(); |
+ return a_path < b_path; |
+} |
+ |
ProfileAttributesEntry::ProfileAttributesEntry() |
: profile_info_cache_(nullptr), |
profile_path_(base::FilePath()) {} |
@@ -39,7 +66,7 @@ base::string16 ProfileAttributesEntry::GetUserName() const { |
return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index()); |
} |
-const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() { |
+const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() const { |
return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index()); |
} |