noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/profiles/avatar_menu.h" |
| 6 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
| 10 | #include "chrome/browser/profiles/profile.h" |
lwchkg | 0558a13 | 2016-03-11 14:33:25 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 12 | #include "chrome/browser/profiles/profile_attributes_storage.h" |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 13 | #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile_manager.h" |
| 15 | #include "ui/base/resource/resource_bundle.h" |
| 16 | |
| 17 | // static |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 18 | AvatarMenu::ImageLoadStatus AvatarMenu::GetImageForMenuButton( |
| 19 | const base::FilePath& profile_path, |
| 20 | gfx::Image* image) { |
lwchkg | 0558a13 | 2016-03-11 14:33:25 | [diff] [blame] | 21 | ProfileAttributesEntry* entry; |
| 22 | if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 23 | GetProfileAttributesWithPath(profile_path, &entry)) { |
estade | fe4b88a | 2016-05-23 20:03:42 | [diff] [blame] | 24 | // This can happen if the user deletes the current profile. |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 25 | return ImageLoadStatus::PROFILE_DELETED; |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 26 | } |
| 27 | |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 28 | ImageLoadStatus status = ImageLoadStatus::LOADED; |
| 29 | |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 30 | // If there is a Gaia image available, try to use that. |
lwchkg | 0558a13 | 2016-03-11 14:33:25 | [diff] [blame] | 31 | if (entry->IsUsingGAIAPicture()) { |
Xi Cheng | 18a6d85f | 2018-11-22 18:55:39 | [diff] [blame] | 32 | // The GetGAIAPicture API call will trigger an async image load from disk if |
| 33 | // it has not been loaded into memory. |
lwchkg | 0558a13 | 2016-03-11 14:33:25 | [diff] [blame] | 34 | const gfx::Image* gaia_image = entry->GetGAIAPicture(); |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 35 | |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 36 | if (gaia_image) { |
| 37 | *image = *gaia_image; |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 38 | return ImageLoadStatus::LOADED; |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 39 | } |
Xi Cheng | 18a6d85f | 2018-11-22 18:55:39 | [diff] [blame] | 40 | |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 41 | if (entry->IsGAIAPictureLoaded()) |
| 42 | status = ImageLoadStatus::MISSING; |
| 43 | else |
| 44 | status = ImageLoadStatus::LOADING; |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 45 | } |
| 46 | |
Thomas Lukaszewicz | d9f8de4a | 2019-11-14 17:54:18 | [diff] [blame] | 47 | // Otherwise, use the default resource, not the downloaded high-res one. |
| 48 | const size_t icon_index = entry->GetAvatarIconIndex(); |
| 49 | const int resource_id = |
| 50 | profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); |
| 51 | *image = |
| 52 | ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 53 | |
| 54 | return status; |
noms | 42ff91f | 2014-12-01 18:26:13 | [diff] [blame] | 55 | } |