OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/views/profiles/avatar_menu_button.h" | 5 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/profiles/avatar_menu.h" | 13 #include "chrome/browser/profiles/avatar_menu.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 16 #include "chrome/browser/profiles/profile_attributes_storage.h" |
15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
16 #include "chrome/browser/profiles/profile_info_cache.h" | |
17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/profiles/profile_metrics.h" | 19 #include "chrome/browser/profiles/profile_metrics.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_commands.h" | 21 #include "chrome/browser/ui/browser_commands.h" |
21 #include "chrome/browser/ui/views/frame/browser_view.h" | 22 #include "chrome/browser/ui/views/frame/browser_view.h" |
22 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 23 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
23 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
24 #include "components/signin/core/common/profile_management_switches.h" | 25 #include "components/signin/core/common/profile_management_switches.h" |
25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
26 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | 111 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test |
111 // environment handles profile directories correctly. | 112 // environment handles profile directories correctly. |
112 #if !defined(OS_CHROMEOS) | 113 #if !defined(OS_CHROMEOS) |
113 bool is_badge_rectangle = false; | 114 bool is_badge_rectangle = false; |
114 // The taskbar badge should be the profile avatar, not the OTR avatar. | 115 // The taskbar badge should be the profile avatar, not the OTR avatar. |
115 AvatarMenu::GetImageForMenuButton(profile->GetPath(), | 116 AvatarMenu::GetImageForMenuButton(profile->GetPath(), |
116 taskbar_badge_avatar, | 117 taskbar_badge_avatar, |
117 &is_badge_rectangle); | 118 &is_badge_rectangle); |
118 #endif | 119 #endif |
119 } else if (should_show_avatar_menu) { | 120 } else if (should_show_avatar_menu) { |
120 ProfileInfoCache& cache = | 121 ProfileAttributesEntry* entry; |
121 g_browser_process->profile_manager()->GetProfileInfoCache(); | 122 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
122 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 123 GetProfileAttributesWithPath(profile->GetPath(), &entry)) |
123 if (index == std::string::npos) | |
124 return false; | 124 return false; |
125 | 125 |
126 #if defined(OS_CHROMEOS) | 126 #if defined(OS_CHROMEOS) |
127 AvatarMenu::GetImageForMenuButton(profile->GetPath(), avatar, is_rectangle); | 127 AvatarMenu::GetImageForMenuButton(profile->GetPath(), avatar, is_rectangle); |
128 #else | 128 #else |
129 *avatar = cache.GetAvatarIconOfProfileAtIndex(index); | 129 *avatar = entry->GetAvatarIcon(); |
130 // TODO(noms): Once the code for the old avatar menu button is removed, | 130 // TODO(noms): Once the code for the old avatar menu button is removed, |
131 // this function will only be called for badging the taskbar icon. The | 131 // this function will only be called for badging the taskbar icon. The |
132 // function can be renamed to something like GetAvatarImageForBadging() | 132 // function can be renamed to something like GetAvatarImageForBadging() |
133 // and only needs to return the avatar from | 133 // and only needs to return the avatar from |
134 // AvatarMenu::GetImageForMenuButton(). | 134 // AvatarMenu::GetImageForMenuButton(). |
135 bool is_badge_rectangle = false; | 135 bool is_badge_rectangle = false; |
136 AvatarMenu::GetImageForMenuButton(profile->GetPath(), | 136 AvatarMenu::GetImageForMenuButton(profile->GetPath(), |
137 taskbar_badge_avatar, | 137 taskbar_badge_avatar, |
138 &is_badge_rectangle); | 138 &is_badge_rectangle); |
139 #endif | 139 #endif |
140 } | 140 } |
141 return true; | 141 return true; |
142 } | 142 } |
143 | 143 |
144 // views::ViewTargeterDelegate: | 144 // views::ViewTargeterDelegate: |
145 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 145 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, |
146 const gfx::Rect& rect) const { | 146 const gfx::Rect& rect) const { |
147 CHECK_EQ(target, this); | 147 CHECK_EQ(target, this); |
148 return enabled_ && | 148 return enabled_ && |
149 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 149 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); |
150 } | 150 } |
151 | 151 |
152 // views::MenuButtonListener implementation | 152 // views::MenuButtonListener implementation |
153 void AvatarMenuButton::OnMenuButtonClicked(views::MenuButton* source, | 153 void AvatarMenuButton::OnMenuButtonClicked(views::MenuButton* source, |
154 const gfx::Point& point, | 154 const gfx::Point& point, |
155 const ui::Event* event) { | 155 const ui::Event* event) { |
156 if (enabled_) | 156 if (enabled_) |
157 chrome::ShowAvatarMenu(browser_view_->browser()); | 157 chrome::ShowAvatarMenu(browser_view_->browser()); |
158 } | 158 } |
OLD | NEW |