Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/profiles/profile_shortcut_manager_win.cc

Issue 462713002: [Win] Profile desktop shortcuts should use the Gaia avatar if it's in use. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/_eq/_ge Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/profiles/profile_info_cache_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // differently than it was when a shortcut was originally created. 64 // differently than it was when a shortcut was originally created.
65 const int kMaxProfileShortcutFileNameLength = 64; 65 const int kMaxProfileShortcutFileNameLength = 64;
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 = 2; 74 const int kCurrentProfileIconVersion = 3;
75 75
76 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in 76 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in
77 // profile_info_cache.cc. 77 // profile_info_cache.cc.
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,
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 582 }
583 583
584 base::TrimWhitespace(sanitized, base::TRIM_LEADING, &sanitized); 584 base::TrimWhitespace(sanitized, base::TRIM_LEADING, &sanitized);
585 if (sanitized.size() > kMaxProfileShortcutFileNameLength) 585 if (sanitized.size() > kMaxProfileShortcutFileNameLength)
586 sanitized.erase(kMaxProfileShortcutFileNameLength); 586 sanitized.erase(kMaxProfileShortcutFileNameLength);
587 base::TrimWhitespace(sanitized, base::TRIM_TRAILING, &sanitized); 587 base::TrimWhitespace(sanitized, base::TRIM_TRAILING, &sanitized);
588 588
589 return sanitized; 589 return sanitized;
590 } 590 }
591 591
592 // Returns a copied SkBitmap for the given image that can be safely passed to
593 // another thread.
594 SkBitmap GetSkBitmapCopy(const gfx::Image& image) {
595 DCHECK(!image.IsEmpty());
596 const SkBitmap* image_bitmap = image.ToSkBitmap();
597 SkBitmap bitmap_copy;
598 image_bitmap->deepCopyTo(&bitmap_copy);
599 return bitmap_copy;
600 }
601
592 // Returns a copied SkBitmap for the given resource id that can be safely passed 602 // Returns a copied SkBitmap for the given resource id that can be safely passed
593 // to another thread. 603 // to another thread.
594 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) { 604 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) {
595 const gfx::Image image = 605 const gfx::Image image =
596 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); 606 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
597 DCHECK(!image.IsEmpty()); 607 return GetSkBitmapCopy(image);
598
599 const SkBitmap* image_bitmap = image.ToSkBitmap();
600 SkBitmap bitmap_copy;
601 image_bitmap->deepCopyTo(&bitmap_copy);
602 return bitmap_copy;
603 } 608 }
604 609
605 } // namespace 610 } // namespace
606 611
607 namespace profiles { 612 namespace profiles {
608 namespace internal { 613 namespace internal {
609 614
610 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { 615 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) {
611 return profile_path.AppendASCII(kProfileIconFileName); 616 return profile_path.AppendASCII(kProfileIconFileName);
612 } 617 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // set in the profile info cache. 806 // set in the profile info cache.
802 if (params.old_profile_name.empty() && 807 if (params.old_profile_name.empty() &&
803 create_mode == UPDATE_EXISTING_ONLY && 808 create_mode == UPDATE_EXISTING_ONLY &&
804 action == IGNORE_NON_PROFILE_SHORTCUTS) { 809 action == IGNORE_NON_PROFILE_SHORTCUTS) {
805 return; 810 return;
806 } 811 }
807 812
808 if (!remove_badging) { 813 if (!remove_badging) {
809 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index); 814 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index);
810 815
811 const size_t icon_index = 816 // The profile might be using the Gaia avatar, which is not in the
812 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); 817 // resources array.
813 const int resource_id_1x = 818 bool has_gaia_image = false;
814 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); 819 if (cache->IsUsingGAIAPictureOfProfileAtIndex(profile_index)) {
815 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; 820 const gfx::Image* image =
816 // Make a copy of the SkBitmaps to ensure that we can safely use the image 821 cache->GetGAIAPictureOfProfileAtIndex(profile_index);
817 // data on the FILE thread. 822 if (image) {
818 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x); 823 params.avatar_image_1x = GetSkBitmapCopy(*image);
819 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x); 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 }
820 } 845 }
821 BrowserThread::PostTask( 846 BrowserThread::PostTask(
822 BrowserThread::FILE, FROM_HERE, 847 BrowserThread::FILE, FROM_HERE,
823 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params)); 848 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params));
824 849
825 cache->SetShortcutNameOfProfileAtIndex(profile_index, 850 cache->SetShortcutNameOfProfileAtIndex(profile_index,
826 params.profile_name); 851 params.profile_name);
827 } 852 }
828 853
829 void ProfileShortcutManagerWin::Observe( 854 void ProfileShortcutManagerWin::Observe(
(...skipping 10 matching lines...) Expand all
840 // Ensure the profile's icon file has been created. 865 // Ensure the profile's icon file has been created.
841 CreateOrUpdateProfileIcon(profile->GetPath()); 866 CreateOrUpdateProfileIcon(profile->GetPath());
842 } 867 }
843 break; 868 break;
844 } 869 }
845 default: 870 default:
846 NOTREACHED(); 871 NOTREACHED();
847 break; 872 break;
848 } 873 }
849 } 874 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_info_cache_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698