Home | History | Annotate | Download | only in profiles
      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 
      7 #include "chrome/browser/browser_process.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
     10 #include "chrome/browser/profiles/profile_info_cache.h"
     11 #include "chrome/browser/profiles/profile_manager.h"
     12 #include "ui/base/resource/resource_bundle.h"
     13 
     14 // static
     15 void AvatarMenu::GetImageForMenuButton(Profile* profile,
     16                                        gfx::Image* image,
     17                                        bool* is_rectangle) {
     18   ProfileInfoCache& cache =
     19       g_browser_process->profile_manager()->GetProfileInfoCache();
     20   size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
     21   if (index == std::string::npos) {
     22     NOTREACHED();
     23     return;
     24   }
     25 
     26   // Ensure we are using the default resource, not the downloaded high-res one.
     27   const size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
     28   const int resource_id =
     29       profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index);
     30   *image = ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
     31   *is_rectangle =
     32       cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
     33       cache.GetGAIAPictureOfProfileAtIndex(index);
     34 }
     35