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

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: alexei comments and revert them scoped_ptrs 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 const SkBitmap* image_bitmap = image.ToSkBitmap();
596 SkBitmap bitmap_copy;
597 image_bitmap->deepCopyTo(&bitmap_copy);
598 return bitmap_copy;
599 }
600
592 // Returns a copied SkBitmap for the given resource id that can be safely passed 601 // Returns a copied SkBitmap for the given resource id that can be safely passed
593 // to another thread. 602 // to another thread.
594 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) { 603 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) {
595 const gfx::Image image = 604 const gfx::Image image =
596 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); 605 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
597 DCHECK(!image.IsEmpty()); 606 DCHECK(!image.IsEmpty());
Alexei Svitkine (slow) 2014/08/12 14:54:07 Nit: Move this check to GetSkBitmapCopy() since th
noms (inactive) 2014/08/12 18:52:53 Done.
598 607 return GetSkBitmapCopy(image);
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 if (cache->IsUsingGAIAPictureOfProfileAtIndex(profile_index)) {
814 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); 819 const gfx::Image* image =
815 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; 820 cache->GetGAIAPictureOfProfileAtIndex(profile_index);
Alexei Svitkine (slow) 2014/08/12 14:54:07 According to the docs for that method: // Retur
noms (inactive) 2014/08/12 18:52:53 Done.
816 // Make a copy of the SkBitmaps to ensure that we can safely use the image 821 params.avatar_image_1x = GetSkBitmapCopy(*image);
817 // data on the FILE thread. 822 params.avatar_image_2x = params.avatar_image_1x;
gab 2014/08/11 20:49:34 Maybe add a comment about explaining why it's okay
noms (inactive) 2014/08/12 18:52:53 Done.
818 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x); 823 } else {
819 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x); 824 const size_t icon_index =
825 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index);
826 const int resource_id_1x =
827 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index);
828 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index];
829 // Make a copy of the SkBitmaps to ensure that we can safely use the image
830 // data on the FILE thread.
831 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x);
832 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x);
833 }
820 } 834 }
821 BrowserThread::PostTask( 835 BrowserThread::PostTask(
822 BrowserThread::FILE, FROM_HERE, 836 BrowserThread::FILE, FROM_HERE,
823 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params)); 837 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params));
824 838
825 cache->SetShortcutNameOfProfileAtIndex(profile_index, 839 cache->SetShortcutNameOfProfileAtIndex(profile_index,
826 params.profile_name); 840 params.profile_name);
827 } 841 }
828 842
829 void ProfileShortcutManagerWin::Observe( 843 void ProfileShortcutManagerWin::Observe(
(...skipping 10 matching lines...) Expand all
840 // Ensure the profile's icon file has been created. 854 // Ensure the profile's icon file has been created.
841 CreateOrUpdateProfileIcon(profile->GetPath()); 855 CreateOrUpdateProfileIcon(profile->GetPath());
842 } 856 }
843 break; 857 break;
844 } 858 }
845 default: 859 default:
846 NOTREACHED(); 860 NOTREACHED();
847 break; 861 break;
848 } 862 }
849 } 863 }
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