Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 = 2; |
|
gab
2014/08/11 15:27:59
If the icon is changed after the profile shortcut
noms (inactive)
2014/08/11 19:14:22
Done.
| |
| 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 Loading... | |
| 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; | |
|
gab
2014/08/11 15:27:59
This will create a copy of the SkBitmap (from the
noms (inactive)
2014/08/11 15:44:39
I just moved the code from one function to another
gab
2014/08/11 16:13:09
Ah indeed GetImageResourceSkBitmapCopy() already r
noms (inactive)
2014/08/11 19:57:07
Done.
Alexei Svitkine (slow)
2014/08/11 20:02:31
I don't think we need extra scoped_ptr's here. SkB
gab
2014/08/11 20:29:44
Ah ok, I'd noticed they were sharing pixels, but i
noms (inactive)
2014/08/11 20:37:53
Reverted! :(
On 2014/08/11 20:29:44, gab wrote:
| |
| 599 } | |
| 592 // Returns a copied SkBitmap for the given resource id that can be safely passed | 600 // Returns a copied SkBitmap for the given resource id that can be safely passed |
|
gab
2014/08/11 15:27:59
nit: empty line above
noms (inactive)
2014/08/11 19:14:22
Done.
| |
| 593 // to another thread. | 601 // to another thread. |
| 594 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) { | 602 SkBitmap GetImageResourceSkBitmapCopy(int resource_id) { |
| 595 const gfx::Image image = | 603 const gfx::Image image = |
| 596 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); | 604 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); |
| 597 DCHECK(!image.IsEmpty()); | 605 DCHECK(!image.IsEmpty()); |
| 598 | 606 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 } | 607 } |
| 604 | 608 |
| 605 } // namespace | 609 } // namespace |
| 606 | 610 |
| 607 namespace profiles { | 611 namespace profiles { |
| 608 namespace internal { | 612 namespace internal { |
| 609 | 613 |
| 610 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { | 614 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { |
| 611 return profile_path.AppendASCII(kProfileIconFileName); | 615 return profile_path.AppendASCII(kProfileIconFileName); |
| 612 } | 616 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 // set in the profile info cache. | 805 // set in the profile info cache. |
| 802 if (params.old_profile_name.empty() && | 806 if (params.old_profile_name.empty() && |
| 803 create_mode == UPDATE_EXISTING_ONLY && | 807 create_mode == UPDATE_EXISTING_ONLY && |
| 804 action == IGNORE_NON_PROFILE_SHORTCUTS) { | 808 action == IGNORE_NON_PROFILE_SHORTCUTS) { |
| 805 return; | 809 return; |
| 806 } | 810 } |
| 807 | 811 |
| 808 if (!remove_badging) { | 812 if (!remove_badging) { |
| 809 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index); | 813 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index); |
| 810 | 814 |
| 811 const size_t icon_index = | 815 // The profile might be using the Gaia avatar, which is not in the |
| 812 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); | 816 // resources array. |
| 813 const int resource_id_1x = | 817 if (cache->IsUsingGAIAPictureOfProfileAtIndex(profile_index)) { |
| 814 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); | 818 const gfx::Image* image = |
| 815 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; | 819 cache->GetGAIAPictureOfProfileAtIndex(profile_index); |
| 816 // Make a copy of the SkBitmaps to ensure that we can safely use the image | 820 params.avatar_image_1x = GetSkBitmapCopy(*image); |
|
Alexei Svitkine (slow)
2014/08/11 19:27:39
To avoid copying the image twice, is it possible t
| |
| 817 // data on the FILE thread. | 821 params.avatar_image_2x = GetSkBitmapCopy(*image); |
|
gab
2014/08/11 15:27:59
You use the same image for the 2x image?
noms (inactive)
2014/08/11 15:44:39
Yup, we only download one image from the userInfo
gab
2014/08/11 16:13:09
Okay but shouldn't one of them be scaled up/down?
noms (inactive)
2014/08/11 19:14:22
The Gaia image is way bigger than the 1x or 2x ava
Alexei Svitkine (slow)
2014/08/11 19:27:39
Can you post pictures on the bug of how this looks
noms (inactive)
2014/08/11 19:57:07
Also added to the description: https://drive.googl
| |
| 818 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x); | 822 } else { |
| 819 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x); | 823 const size_t icon_index = |
| 824 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); | |
| 825 const int resource_id_1x = | |
| 826 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index); | |
| 827 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; | |
| 828 // Make a copy of the SkBitmaps to ensure that we can safely use the image | |
| 829 // data on the FILE thread. | |
| 830 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x); | |
| 831 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x); | |
| 832 } | |
| 820 } | 833 } |
| 821 BrowserThread::PostTask( | 834 BrowserThread::PostTask( |
| 822 BrowserThread::FILE, FROM_HERE, | 835 BrowserThread::FILE, FROM_HERE, |
| 823 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params)); | 836 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params)); |
| 824 | 837 |
| 825 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 838 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
| 826 params.profile_name); | 839 params.profile_name); |
| 827 } | 840 } |
| 828 | 841 |
| 829 void ProfileShortcutManagerWin::Observe( | 842 void ProfileShortcutManagerWin::Observe( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 840 // Ensure the profile's icon file has been created. | 853 // Ensure the profile's icon file has been created. |
| 841 CreateOrUpdateProfileIcon(profile->GetPath()); | 854 CreateOrUpdateProfileIcon(profile->GetPath()); |
| 842 } | 855 } |
| 843 break; | 856 break; |
| 844 } | 857 } |
| 845 default: | 858 default: |
| 846 NOTREACHED(); | 859 NOTREACHED(); |
| 847 break; | 860 break; |
| 848 } | 861 } |
| 849 } | 862 } |
| OLD | NEW |