OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_shortcut_manager_win.h" | 5 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
6 | 6 |
7 #include <shlobj.h> // For SHChangeNotify(). | 7 #include <shlobj.h> // For SHChangeNotify(). |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 // The avatar badge size needs to be half of the shortcut icon size because | 67 // The avatar badge size needs to be half of the shortcut icon size because |
68 // the Windows taskbar icon is 32x32 and the avatar icon overlay is 16x16. So to | 68 // the Windows taskbar icon is 32x32 and the avatar icon overlay is 16x16. So to |
69 // get the shortcut avatar badge and the avatar icon overlay to match up, we | 69 // get the shortcut avatar badge and the avatar icon overlay to match up, we |
70 // need to preserve those ratios when creating the shortcut icon. | 70 // need to preserve those ratios when creating the shortcut icon. |
71 const int kShortcutIconSize = 48; | 71 const int kShortcutIconSize = 48; |
72 const int kProfileAvatarBadgeSize = kShortcutIconSize / 2; | 72 const int kProfileAvatarBadgeSize = kShortcutIconSize / 2; |
73 | 73 |
74 const int kCurrentProfileIconVersion = 3; | 74 const int kCurrentProfileIconVersion = 3; |
75 | 75 |
76 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in | 76 // 2x sized profile avatar icons. Mirrors |GetDefaultAvatarIconResourceInfo()| |
77 // profile_info_cache.cc. | 77 // in profile_avatar_icon_util.cc |
noms (inactive)
2014/10/30 17:39:08
nit: needs to end in a .
Roger Tawa OOO till Jul 10th
2014/10/31 19:44:39
Removed this code from CL.
| |
78 const int kProfileAvatarIconResources2x[] = { | 78 const int kProfileAvatarIconResources2x[] = { |
79 IDR_PROFILE_AVATAR_2X_0, | 79 IDR_PROFILE_AVATAR_2X_0, |
80 IDR_PROFILE_AVATAR_2X_1, | 80 IDR_PROFILE_AVATAR_2X_1, |
81 IDR_PROFILE_AVATAR_2X_2, | 81 IDR_PROFILE_AVATAR_2X_2, |
82 IDR_PROFILE_AVATAR_2X_3, | 82 IDR_PROFILE_AVATAR_2X_3, |
83 IDR_PROFILE_AVATAR_2X_4, | 83 IDR_PROFILE_AVATAR_2X_4, |
84 IDR_PROFILE_AVATAR_2X_5, | 84 IDR_PROFILE_AVATAR_2X_5, |
85 IDR_PROFILE_AVATAR_2X_6, | 85 IDR_PROFILE_AVATAR_2X_6, |
86 IDR_PROFILE_AVATAR_2X_7, | 86 IDR_PROFILE_AVATAR_2X_7, |
87 IDR_PROFILE_AVATAR_2X_8, | 87 IDR_PROFILE_AVATAR_2X_8, |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 // Returns a copied SkBitmap for the given image that can be safely passed to | 592 // Returns a copied SkBitmap for the given image that can be safely passed to |
593 // another thread. | 593 // another thread. |
594 SkBitmap GetSkBitmapCopy(const gfx::Image& image) { | 594 SkBitmap GetSkBitmapCopy(const gfx::Image& image) { |
595 DCHECK(!image.IsEmpty()); | 595 DCHECK(!image.IsEmpty()); |
596 const SkBitmap* image_bitmap = image.ToSkBitmap(); | 596 const SkBitmap* image_bitmap = image.ToSkBitmap(); |
597 SkBitmap bitmap_copy; | 597 SkBitmap bitmap_copy; |
598 image_bitmap->deepCopyTo(&bitmap_copy); | 598 image_bitmap->deepCopyTo(&bitmap_copy); |
599 return bitmap_copy; | 599 return bitmap_copy; |
600 } | 600 } |
601 | 601 |
602 // Returns a copied SkBitmap for the given resource id that can be safely passed | |
603 // to another thread. | |
604 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) { | |
605 const gfx::Image image = | |
606 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); | |
607 return GetSkBitmapCopy(image); | |
608 } | |
609 | |
610 } // namespace | 602 } // namespace |
611 | 603 |
612 namespace profiles { | 604 namespace profiles { |
613 namespace internal { | 605 namespace internal { |
614 | 606 |
615 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { | 607 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { |
616 return profile_path.AppendASCII(kProfileIconFileName); | 608 return profile_path.AppendASCII(kProfileIconFileName); |
617 } | 609 } |
618 | 610 |
619 base::string16 GetShortcutFilenameForProfile( | 611 base::string16 GetShortcutFilenameForProfile( |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 // set in the profile info cache. | 798 // set in the profile info cache. |
807 if (params.old_profile_name.empty() && | 799 if (params.old_profile_name.empty() && |
808 create_mode == UPDATE_EXISTING_ONLY && | 800 create_mode == UPDATE_EXISTING_ONLY && |
809 action == IGNORE_NON_PROFILE_SHORTCUTS) { | 801 action == IGNORE_NON_PROFILE_SHORTCUTS) { |
810 return; | 802 return; |
811 } | 803 } |
812 | 804 |
813 if (!remove_badging) { | 805 if (!remove_badging) { |
814 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index); | 806 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index); |
815 | 807 |
816 // The profile might be using the Gaia avatar, which is not in the | 808 gfx::Image image_1x; |
817 // resources array. | 809 gfx::Image image_2x; |
818 bool has_gaia_image = false; | 810 GetBadgingAvatarImages(profile_manager_, profile_path, &image_1x, |
819 if (cache->IsUsingGAIAPictureOfProfileAtIndex(profile_index)) { | 811 &image_2x); |
820 const gfx::Image* image = | 812 params.avatar_image_1x = GetSkBitmapCopy(image_1x); |
821 cache->GetGAIAPictureOfProfileAtIndex(profile_index); | 813 params.avatar_image_2x = GetSkBitmapCopy(image_2x); |
822 if (image) { | |
823 params.avatar_image_1x = GetSkBitmapCopy(*image); | |
824 // Gaia images are 256px, which makes them big enough to use in the | |
825 // large icon case as well. | |
826 DCHECK_GE(image->Width(), IconUtil::kLargeIconSize); | |
827 params.avatar_image_2x = params.avatar_image_1x; | |
828 has_gaia_image = true; | |
829 } | |
830 } | |
831 | |
832 // If the profile isn't using a Gaia image, or if the Gaia image did not | |
833 // exist, revert to the previously used avatar icon. | |
834 if (!has_gaia_image) { | |
835 const size_t icon_index = | |
836 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); | |
837 const int resource_id_1x = | |
838 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); | |
839 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; | |
840 // Make a copy of the SkBitmaps to ensure that we can safely use the image | |
841 // data on the FILE thread. | |
842 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x); | |
843 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x); | |
844 } | |
845 } | 814 } |
846 BrowserThread::PostTask( | 815 BrowserThread::PostTask( |
847 BrowserThread::FILE, FROM_HERE, | 816 BrowserThread::FILE, FROM_HERE, |
848 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params)); | 817 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params)); |
849 | 818 |
850 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 819 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
851 params.profile_name); | 820 params.profile_name); |
852 } | 821 } |
853 | 822 |
854 void ProfileShortcutManagerWin::Observe( | 823 void ProfileShortcutManagerWin::Observe( |
(...skipping 10 matching lines...) Expand all Loading... | |
865 // Ensure the profile's icon file has been created. | 834 // Ensure the profile's icon file has been created. |
866 CreateOrUpdateProfileIcon(profile->GetPath()); | 835 CreateOrUpdateProfileIcon(profile->GetPath()); |
867 } | 836 } |
868 break; | 837 break; |
869 } | 838 } |
870 default: | 839 default: |
871 NOTREACHED(); | 840 NOTREACHED(); |
872 break; | 841 break; |
873 } | 842 } |
874 } | 843 } |
844 | |
845 // static | |
846 void ProfileShortcutManagerWin::GetBadgingAvatarImages( | |
847 ProfileManager* profile_manager, | |
848 const base::FilePath& profile_path, | |
849 gfx::Image* image_1x, | |
850 gfx::Image* image_2x) { | |
851 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
852 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path); | |
853 | |
854 // The profile might be using the Gaia avatar, which is not in the | |
855 // resources array. | |
856 bool has_gaia_image = false; | |
857 if (cache.IsUsingGAIAPictureOfProfileAtIndex(profile_index)) { | |
858 const gfx::Image* image = | |
859 cache.GetGAIAPictureOfProfileAtIndex(profile_index); | |
860 if (image) { | |
861 if (image_1x) | |
862 *image_1x = *image; | |
863 // Gaia images are 256px, which makes them big enough to use in the | |
864 // large icon case as well. | |
865 DCHECK_GE(image->Width(), IconUtil::kLargeIconSize); | |
866 if (image_2x) | |
867 *image_2x = *image; | |
868 has_gaia_image = true; | |
869 } | |
870 } | |
871 | |
872 // If the profile isn't using a Gaia image, or if the Gaia image did not | |
873 // exist, revert to the previously used avatar icon. | |
874 if (!has_gaia_image) { | |
875 const size_t icon_index = | |
876 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index); | |
877 const int resource_id_1x = | |
878 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); | |
879 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; | |
880 if (image_1x) { | |
881 *image_1x = | |
882 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
noms (inactive)
2014/10/30 17:39:08
Maybe you get pull the ResourceBundle instance out
Roger Tawa OOO till Jul 10th
2014/10/31 19:44:39
Removed this code from CL.
| |
883 resource_id_1x); | |
884 } | |
885 if (image_2x) { | |
886 *image_2x = | |
887 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
888 resource_id_2x); | |
889 } | |
890 } | |
891 } | |
892 | |
OLD | NEW |