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

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: Fix errors 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 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));
16 }
17
18 ProfileAttributesEntry::SortComparator::~SortComparator() {}
19
20 bool ProfileAttributesEntry::SortComparator::operator()(
21 const ProfileAttributesEntry* const a,
22 const ProfileAttributesEntry* const b) const {
23 UCollationResult result = base::i18n::CompareString16WithCollator(
24 *collator_, a->GetName(), b->GetName());
25 if (result != UCOL_EQUAL)
26 return result == UCOL_LESS;
27
28 // Compare the profile paths. Since the paths are "[userdir]\Profile #", so
29 // comparisons take care of the numbers represented by # only.
30 base::FilePath::StringType a_path = a->GetPath().value();
31 base::FilePath::StringType b_path = b->GetPath().value();
32 if (a_path.length() != b_path.length())
33 return a_path.length() < b_path.length();
34 return a_path < b_path;
35 }
36
8 ProfileAttributesEntry::ProfileAttributesEntry() 37 ProfileAttributesEntry::ProfileAttributesEntry()
9 : profile_info_cache_(nullptr), 38 : profile_info_cache_(nullptr),
10 profile_path_(base::FilePath()) {} 39 profile_path_(base::FilePath()) {}
11 40
12 void ProfileAttributesEntry::Initialize( 41 void ProfileAttributesEntry::Initialize(
13 ProfileInfoCache* cache, const base::FilePath& path) { 42 ProfileInfoCache* cache, const base::FilePath& path) {
14 DCHECK(!profile_info_cache_); 43 DCHECK(!profile_info_cache_);
15 DCHECK(cache); 44 DCHECK(cache);
16 profile_info_cache_ = cache; 45 profile_info_cache_ = cache;
17 DCHECK(profile_path_.empty()); 46 DCHECK(profile_path_.empty());
(...skipping 14 matching lines...) Expand all
32 } 61 }
33 62
34 base::Time ProfileAttributesEntry::GetActiveTime() const { 63 base::Time ProfileAttributesEntry::GetActiveTime() const {
35 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index()); 64 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index());
36 } 65 }
37 66
38 base::string16 ProfileAttributesEntry::GetUserName() const { 67 base::string16 ProfileAttributesEntry::GetUserName() const {
39 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index()); 68 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index());
40 } 69 }
41 70
42 const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() { 71 const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() const {
43 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index()); 72 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index());
44 } 73 }
45 74
46 std::string ProfileAttributesEntry::GetLocalAuthCredentials() const { 75 std::string ProfileAttributesEntry::GetLocalAuthCredentials() const {
47 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex( 76 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex(
48 profile_index()); 77 profile_index());
49 } 78 }
50 79
51 std::string ProfileAttributesEntry::GetPasswordChangeDetectionToken() const { 80 std::string ProfileAttributesEntry::GetPasswordChangeDetectionToken() const {
52 return profile_info_cache_->GetPasswordChangeDetectionTokenAtIndex( 81 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) { 296 const std::string& gaia_id, const base::string16& user_name) {
268 profile_info_cache_->SetAuthInfoOfProfileAtIndex( 297 profile_info_cache_->SetAuthInfoOfProfileAtIndex(
269 profile_index(), gaia_id, user_name); 298 profile_index(), gaia_id, user_name);
270 } 299 }
271 300
272 size_t ProfileAttributesEntry::profile_index() const { 301 size_t ProfileAttributesEntry::profile_index() const {
273 size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_); 302 size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_);
274 DCHECK(index < profile_info_cache_->GetNumberOfProfiles()); 303 DCHECK(index < profile_info_cache_->GetNumberOfProfiles());
275 return index; 304 return index;
276 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698