blob: edaeef06b906d70d1203722f002503e84ec3efaa [file] [log] [blame]
noms42ff91f2014-12-01 18:26:131// 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
avib896c712015-12-26 02:10:437#include <stddef.h>
8
noms42ff91f2014-12-01 18:26:139#include "chrome/browser/browser_process.h"
10#include "chrome/browser/profiles/profile.h"
lwchkg0558a132016-03-11 14:33:2511#include "chrome/browser/profiles/profile_attributes_entry.h"
12#include "chrome/browser/profiles/profile_attributes_storage.h"
noms42ff91f2014-12-01 18:26:1313#include "chrome/browser/profiles/profile_avatar_icon_util.h"
noms42ff91f2014-12-01 18:26:1314#include "chrome/browser/profiles/profile_manager.h"
15#include "ui/base/resource/resource_bundle.h"
16
17// static
Xi Cheng1b761382017-08-15 20:37:3418AvatarMenu::ImageLoadStatus AvatarMenu::GetImageForMenuButton(
19 const base::FilePath& profile_path,
20 gfx::Image* image) {
lwchkg0558a132016-03-11 14:33:2521 ProfileAttributesEntry* entry;
22 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage().
23 GetProfileAttributesWithPath(profile_path, &entry)) {
estadefe4b88a2016-05-23 20:03:4224 // This can happen if the user deletes the current profile.
Xi Cheng1b761382017-08-15 20:37:3425 return ImageLoadStatus::PROFILE_DELETED;
noms42ff91f2014-12-01 18:26:1326 }
27
Xi Cheng1b761382017-08-15 20:37:3428 ImageLoadStatus status = ImageLoadStatus::LOADED;
29
noms42ff91f2014-12-01 18:26:1330 // If there is a Gaia image available, try to use that.
lwchkg0558a132016-03-11 14:33:2531 if (entry->IsUsingGAIAPicture()) {
Xi Cheng18a6d85f2018-11-22 18:55:3932 // The GetGAIAPicture API call will trigger an async image load from disk if
33 // it has not been loaded into memory.
lwchkg0558a132016-03-11 14:33:2534 const gfx::Image* gaia_image = entry->GetGAIAPicture();
Xi Cheng1b761382017-08-15 20:37:3435
noms42ff91f2014-12-01 18:26:1336 if (gaia_image) {
37 *image = *gaia_image;
Xi Cheng1b761382017-08-15 20:37:3438 return ImageLoadStatus::LOADED;
noms42ff91f2014-12-01 18:26:1339 }
Xi Cheng18a6d85f2018-11-22 18:55:3940
Xi Cheng1b761382017-08-15 20:37:3441 if (entry->IsGAIAPictureLoaded())
42 status = ImageLoadStatus::MISSING;
43 else
44 status = ImageLoadStatus::LOADING;
noms42ff91f2014-12-01 18:26:1345 }
46
Thomas Lukaszewiczd9f8de4a2019-11-14 17:54:1847 // 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 Cheng1b761382017-08-15 20:37:3453
54 return status;
noms42ff91f2014-12-01 18:26:1355}