Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/profiles/profile_attributes_entry.cc

Issue 1631373003: Refactor ProfileInfoCache in c/b/ui/app_list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments, add sorting of ProfileAttributesEntry Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 scoped_ptr<icu::Collator>
11 ProfileAttributesEntry::SortComparator::GetCollator() {
12 UErrorCode error_code = U_ZERO_ERROR;
13 // Use the default collator. The default locale should have been properly
14 // set by the time this constructor is called.
15 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code));
16 DCHECK(U_SUCCESS(error_code));
17 return collator;
18 }
19
20 bool ProfileAttributesEntry::SortComparator::operator()(
21 const ProfileAttributesEntry* const a,
22 const ProfileAttributesEntry* const b) const {
23 if (!collator_)
24 return false; // If collator is absent sorting fails with undefined result.
tapted 2016/01/31 23:04:37 can this actually happen? I think this should DCHE
lwchkg 2016/02/01 06:31:20 The constructor has already DCHECKed. This is only
tapted 2016/02/02 00:20:55 That's not normally what we use DCHECK for. DCHECK
25
26 UCollationResult result = base::i18n::CompareString16WithCollator(
27 *collator_, a->GetName(), b->GetName());
28 if (result != UCOL_EQUAL)
29 return result == UCOL_LESS;
30
31 // Compare the profile paths. Since the paths are "[userdir]\Profile #", so
32 // comparisons take care of the numbers represented by # only.
33 base::FilePath::StringType a_path = a->GetPath().value();
34 base::FilePath::StringType b_path = b->GetPath().value();
35 if (a_path.length() != b_path.length())
36 return a_path.length() < b_path.length();
37 return a_path < b_path;
38 }
39
8 ProfileAttributesEntry::ProfileAttributesEntry() 40 ProfileAttributesEntry::ProfileAttributesEntry()
9 : profile_info_cache_(nullptr), 41 : profile_info_cache_(nullptr),
10 profile_path_(base::FilePath()) {} 42 profile_path_(base::FilePath()) {}
11 43
12 void ProfileAttributesEntry::Initialize( 44 void ProfileAttributesEntry::Initialize(
13 ProfileInfoCache* cache, const base::FilePath& path) { 45 ProfileInfoCache* cache, const base::FilePath& path) {
14 DCHECK(!profile_info_cache_); 46 DCHECK(!profile_info_cache_);
15 DCHECK(cache); 47 DCHECK(cache);
16 profile_info_cache_ = cache; 48 profile_info_cache_ = cache;
17 DCHECK(profile_path_.empty()); 49 DCHECK(profile_path_.empty());
(...skipping 14 matching lines...) Expand all
32 } 64 }
33 65
34 base::Time ProfileAttributesEntry::GetActiveTime() const { 66 base::Time ProfileAttributesEntry::GetActiveTime() const {
35 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index()); 67 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index());
36 } 68 }
37 69
38 base::string16 ProfileAttributesEntry::GetUserName() const { 70 base::string16 ProfileAttributesEntry::GetUserName() const {
39 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index()); 71 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index());
40 } 72 }
41 73
42 const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() { 74 const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() const {
43 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index()); 75 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index());
44 } 76 }
45 77
46 std::string ProfileAttributesEntry::GetLocalAuthCredentials() const { 78 std::string ProfileAttributesEntry::GetLocalAuthCredentials() const {
47 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex( 79 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex(
48 profile_index()); 80 profile_index());
49 } 81 }
50 82
51 std::string ProfileAttributesEntry::GetPasswordChangeDetectionToken() const { 83 std::string ProfileAttributesEntry::GetPasswordChangeDetectionToken() const {
52 return profile_info_cache_->GetPasswordChangeDetectionTokenAtIndex( 84 return profile_info_cache_->GetPasswordChangeDetectionTokenAtIndex(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 const std::string& gaia_id, const base::string16& user_name) { 299 const std::string& gaia_id, const base::string16& user_name) {
268 profile_info_cache_->SetAuthInfoOfProfileAtIndex( 300 profile_info_cache_->SetAuthInfoOfProfileAtIndex(
269 profile_index(), gaia_id, user_name); 301 profile_index(), gaia_id, user_name);
270 } 302 }
271 303
272 size_t ProfileAttributesEntry::profile_index() const { 304 size_t ProfileAttributesEntry::profile_index() const {
273 size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_); 305 size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_);
274 DCHECK(index < profile_info_cache_->GetNumberOfProfiles()); 306 DCHECK(index < profile_info_cache_->GetNumberOfProfiles());
275 return index; 307 return index;
276 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698