OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_list_desktop.h" | 5 #include "chrome/browser/profiles/profile_list_desktop.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/profiles/profile_info_cache.h" | 9 #include "chrome/browser/profiles/profile_info_cache.h" |
10 #include "chrome/browser/profiles/profile_info_util.h" | 10 #include "chrome/browser/profiles/profile_info_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 size_t ProfileListDesktop::GetNumberOfItems() const { | 28 size_t ProfileListDesktop::GetNumberOfItems() const { |
29 return items_.size(); | 29 return items_.size(); |
30 } | 30 } |
31 | 31 |
32 const AvatarMenu::Item& ProfileListDesktop::GetItemAt(size_t index) const { | 32 const AvatarMenu::Item& ProfileListDesktop::GetItemAt(size_t index) const { |
33 DCHECK_LT(index, items_.size()); | 33 DCHECK_LT(index, items_.size()); |
34 return *items_[index]; | 34 return *items_[index]; |
35 } | 35 } |
36 | 36 |
| 37 const AvatarMenu::Item& ProfileListDesktop::GetActiveItem() const { |
| 38 for (size_t i = 0; i < items_.size(); ++i) { |
| 39 if (items_[i]->active) |
| 40 return *items_[i]; |
| 41 } |
| 42 |
| 43 // During singleton profile deletion, this function can be called with no |
| 44 // profiles in the model - crbug.com/102278 . |
| 45 return *items_[0]; |
| 46 } |
| 47 |
37 void ProfileListDesktop::RebuildMenu() { | 48 void ProfileListDesktop::RebuildMenu() { |
38 ClearMenu(); | 49 ClearMenu(); |
39 | 50 |
40 const size_t count = profile_info_->GetNumberOfProfiles(); | 51 const std::vector<ProfileInfoEntry> entries( |
41 for (size_t i = 0; i < count; ++i) { | 52 profile_info_->GetProfilesSortedByName()); |
| 53 for (size_t i = 0; i < entries.size(); ++i) { |
| 54 const ProfileInfoEntry& entry = entries[i]; |
42 bool is_gaia_picture = | 55 bool is_gaia_picture = |
43 profile_info_->IsUsingGAIAPictureOfProfileAtIndex(i) && | 56 entry.is_using_GAIA_picture() && |
44 profile_info_->GetGAIAPictureOfProfileAtIndex(i); | 57 profile_info_->GetGAIAPictureOfProfile(entry.path()); |
45 | 58 |
46 gfx::Image icon = profile_info_->GetAvatarIconOfProfileAtIndex(i); | 59 gfx::Image icon = profile_info_->GetAvatarIconOfProfile(entry.path()); |
47 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 60 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
48 switches::kNewProfileManagement)) { | 61 switches::kNewProfileManagement)) { |
49 // old avatar menu uses resized-small images | 62 // old avatar menu uses resized-small images |
50 icon = profiles::GetAvatarIconForMenu(icon, is_gaia_picture); | 63 icon = profiles::GetAvatarIconForMenu(icon, is_gaia_picture); |
51 } | 64 } |
52 | 65 |
53 AvatarMenu::Item* item = new AvatarMenu::Item(i, i, icon); | 66 AvatarMenu::Item* item = new AvatarMenu::Item(i, i, icon); |
54 item->name = profile_info_->GetNameOfProfileAtIndex(i); | 67 item->name = entry.GetDisplayName(); |
55 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); | 68 item->sync_state = entry.user_name(); |
56 item->managed = profile_info_->ProfileIsManagedAtIndex(i); | 69 item->managed = entry.IsManaged(); |
57 item->signed_in = !item->sync_state.empty(); | 70 item->signed_in = !item->sync_state.empty(); |
58 if (!item->signed_in) { | 71 if (!item->signed_in) { |
59 item->sync_state = l10n_util::GetStringUTF16( | 72 item->sync_state = l10n_util::GetStringUTF16( |
60 item->managed ? IDS_MANAGED_USER_AVATAR_LABEL : | 73 item->managed ? IDS_MANAGED_USER_AVATAR_LABEL : |
61 IDS_PROFILES_LOCAL_PROFILE_STATE); | 74 IDS_PROFILES_LOCAL_PROFILE_STATE); |
62 } | 75 } |
63 item->active = profile_info_->GetPathOfProfileAtIndex(i) == | 76 item->active = entry.path() == active_profile_path_; |
64 active_profile_path_; | 77 item->signin_required = entry.is_signin_required(); |
65 item->signin_required = profile_info_->ProfileIsSigninRequiredAtIndex(i); | |
66 items_.push_back(item); | 78 items_.push_back(item); |
67 } | 79 } |
68 } | 80 } |
69 | 81 |
70 size_t ProfileListDesktop::MenuIndexFromProfileIndex(size_t index) { | 82 size_t ProfileListDesktop::MenuIndexFromProfileIndex(size_t index) { |
71 // Menu indices correspond to indices in profile cache. | 83 // Menu indices correspond to indices in profile cache. |
72 return index; | 84 return index; |
73 } | 85 } |
74 | 86 |
75 void ProfileListDesktop::ActiveProfilePathChanged(base::FilePath& path) { | 87 void ProfileListDesktop::ActiveProfilePathChanged(base::FilePath& path) { |
76 active_profile_path_ = path; | 88 active_profile_path_ = path; |
77 } | 89 } |
78 | 90 |
79 void ProfileListDesktop::ClearMenu() { | 91 void ProfileListDesktop::ClearMenu() { |
80 STLDeleteElements(&items_); | 92 STLDeleteElements(&items_); |
81 } | 93 } |
OLD | NEW |