Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/profiles/profile_attributes_entry.h" | 5 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 6 | |
| 7 #include "base/i18n/string_compare.h" | |
| 6 #include "chrome/browser/profiles/profile_info_cache.h" | 8 #include "chrome/browser/profiles/profile_info_cache.h" |
| 7 | 9 |
| 10 ProfileAttributesEntry::SortComparator::SortComparator() { | |
| 11 UErrorCode error_code = U_ZERO_ERROR; | |
| 12 // Use the default collator. The default locale should have been properly | |
| 13 // set by the time this constructor is called. | |
| 14 collator_.reset(icu::Collator::createInstance(error_code)); | |
| 15 DCHECK(U_SUCCESS(error_code)); | |
|
tapted
2016/02/04 23:10:35
After looking at SortVectorWithStringKey from ui/b
| |
| 16 } | |
| 17 | |
| 18 bool ProfileAttributesEntry::SortComparator::operator()( | |
| 19 const ProfileAttributesEntry* const a, | |
| 20 const ProfileAttributesEntry* const b) const { | |
| 21 UCollationResult result = base::i18n::CompareString16WithCollator( | |
| 22 *collator_, a->GetName(), b->GetName()); | |
| 23 if (result != UCOL_EQUAL) | |
| 24 return result == UCOL_LESS; | |
| 25 | |
| 26 // Compare the profile paths. Since the paths are "[userdir]\Profile #", so | |
| 27 // comparisons take care of the numbers represented by # only. | |
| 28 base::FilePath::StringType a_path = a->GetPath().value(); | |
| 29 base::FilePath::StringType b_path = b->GetPath().value(); | |
| 30 if (a_path.length() != b_path.length()) | |
| 31 return a_path.length() < b_path.length(); | |
| 32 return a_path < b_path; | |
| 33 } | |
| 34 | |
| 8 ProfileAttributesEntry::ProfileAttributesEntry() | 35 ProfileAttributesEntry::ProfileAttributesEntry() |
| 9 : profile_info_cache_(nullptr), | 36 : profile_info_cache_(nullptr), |
| 10 profile_path_(base::FilePath()) {} | 37 profile_path_(base::FilePath()) {} |
| 11 | 38 |
| 12 void ProfileAttributesEntry::Initialize( | 39 void ProfileAttributesEntry::Initialize( |
| 13 ProfileInfoCache* cache, const base::FilePath& path) { | 40 ProfileInfoCache* cache, const base::FilePath& path) { |
| 14 DCHECK(!profile_info_cache_); | 41 DCHECK(!profile_info_cache_); |
| 15 DCHECK(cache); | 42 DCHECK(cache); |
| 16 profile_info_cache_ = cache; | 43 profile_info_cache_ = cache; |
| 17 DCHECK(profile_path_.empty()); | 44 DCHECK(profile_path_.empty()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 32 } | 59 } |
| 33 | 60 |
| 34 base::Time ProfileAttributesEntry::GetActiveTime() const { | 61 base::Time ProfileAttributesEntry::GetActiveTime() const { |
| 35 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index()); | 62 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index()); |
| 36 } | 63 } |
| 37 | 64 |
| 38 base::string16 ProfileAttributesEntry::GetUserName() const { | 65 base::string16 ProfileAttributesEntry::GetUserName() const { |
| 39 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index()); | 66 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index()); |
| 40 } | 67 } |
| 41 | 68 |
| 42 const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() { | 69 const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() const { |
| 43 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index()); | 70 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index()); |
| 44 } | 71 } |
| 45 | 72 |
| 46 std::string ProfileAttributesEntry::GetLocalAuthCredentials() const { | 73 std::string ProfileAttributesEntry::GetLocalAuthCredentials() const { |
| 47 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex( | 74 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex( |
| 48 profile_index()); | 75 profile_index()); |
| 49 } | 76 } |
| 50 | 77 |
| 51 std::string ProfileAttributesEntry::GetPasswordChangeDetectionToken() const { | 78 std::string ProfileAttributesEntry::GetPasswordChangeDetectionToken() const { |
| 52 return profile_info_cache_->GetPasswordChangeDetectionTokenAtIndex( | 79 return profile_info_cache_->GetPasswordChangeDetectionTokenAtIndex( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 const std::string& gaia_id, const base::string16& user_name) { | 294 const std::string& gaia_id, const base::string16& user_name) { |
| 268 profile_info_cache_->SetAuthInfoOfProfileAtIndex( | 295 profile_info_cache_->SetAuthInfoOfProfileAtIndex( |
| 269 profile_index(), gaia_id, user_name); | 296 profile_index(), gaia_id, user_name); |
| 270 } | 297 } |
| 271 | 298 |
| 272 size_t ProfileAttributesEntry::profile_index() const { | 299 size_t ProfileAttributesEntry::profile_index() const { |
| 273 size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_); | 300 size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_); |
| 274 DCHECK(index < profile_info_cache_->GetNumberOfProfiles()); | 301 DCHECK(index < profile_info_cache_->GetNumberOfProfiles()); |
| 275 return index; | 302 return index; |
| 276 } | 303 } |
| OLD | NEW |