| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const SkBitmap& avatar_bitmap_1x, | 164 const SkBitmap& avatar_bitmap_1x, |
| 165 const SkBitmap& avatar_bitmap_2x) { | 165 const SkBitmap& avatar_bitmap_2x) { |
| 166 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 166 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 167 | 167 |
| 168 if (!base::PathExists(profile_path)) { | 168 if (!base::PathExists(profile_path)) { |
| 169 LOG(ERROR) << "Profile directory " << profile_path.value() | 169 LOG(ERROR) << "Profile directory " << profile_path.value() |
| 170 << " did not exist when trying to create profile icon"; | 170 << " did not exist when trying to create profile icon"; |
| 171 return base::FilePath(); | 171 return base::FilePath(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize)); | 174 scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily(); |
| 175 if (!app_icon_bitmap) | 175 if (!family) |
| 176 return base::FilePath(); |
| 177 |
| 178 // TODO(mgiuca): A better approach would be to badge each image in the |
| 179 // ImageFamily (scaling the badge to the correct size), and then re-export the |
| 180 // family (as opposed to making a family with just 48 and 256, then scaling |
| 181 // those images to about a dozen different sizes). |
| 182 SkBitmap app_icon_bitmap = |
| 183 family->CreateExact(kShortcutIconSize, kShortcutIconSize).AsBitmap(); |
| 184 if (app_icon_bitmap.isNull()) |
| 176 return base::FilePath(); | 185 return base::FilePath(); |
| 177 | 186 |
| 178 gfx::ImageFamily badged_bitmaps; | 187 gfx::ImageFamily badged_bitmaps; |
| 179 if (!avatar_bitmap_1x.empty()) { | 188 if (!avatar_bitmap_1x.empty()) { |
| 180 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( | 189 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( |
| 181 BadgeIcon(*app_icon_bitmap, avatar_bitmap_1x, 1))); | 190 BadgeIcon(app_icon_bitmap, avatar_bitmap_1x, 1))); |
| 182 } | 191 } |
| 183 | 192 |
| 184 scoped_ptr<SkBitmap> large_app_icon_bitmap( | 193 SkBitmap large_app_icon_bitmap = |
| 185 GetAppIconForSize(IconUtil::kLargeIconSize)); | 194 family->CreateExact(IconUtil::kLargeIconSize, IconUtil::kLargeIconSize) |
| 186 if (large_app_icon_bitmap && !avatar_bitmap_2x.empty()) { | 195 .AsBitmap(); |
| 196 if (!large_app_icon_bitmap.isNull() && !avatar_bitmap_2x.empty()) { |
| 187 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( | 197 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( |
| 188 BadgeIcon(*large_app_icon_bitmap, avatar_bitmap_2x, 2))); | 198 BadgeIcon(large_app_icon_bitmap, avatar_bitmap_2x, 2))); |
| 189 } | 199 } |
| 190 | 200 |
| 191 // If we have no badged bitmaps, we should just use the default chrome icon. | 201 // If we have no badged bitmaps, we should just use the default chrome icon. |
| 192 if (badged_bitmaps.empty()) { | 202 if (badged_bitmaps.empty()) { |
| 193 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(*app_icon_bitmap)); | 203 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(app_icon_bitmap)); |
| 194 if (large_app_icon_bitmap) { | 204 if (!large_app_icon_bitmap.isNull()) { |
| 195 badged_bitmaps.Add( | 205 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(large_app_icon_bitmap)); |
| 196 gfx::Image::CreateFrom1xBitmap(*large_app_icon_bitmap)); | |
| 197 } | 206 } |
| 198 } | 207 } |
| 199 // Finally, write the .ico file containing this new bitmap. | 208 // Finally, write the .ico file containing this new bitmap. |
| 200 const base::FilePath icon_path = | 209 const base::FilePath icon_path = |
| 201 profiles::internal::GetProfileIconPath(profile_path); | 210 profiles::internal::GetProfileIconPath(profile_path); |
| 202 const bool had_icon = base::PathExists(icon_path); | 211 const bool had_icon = base::PathExists(icon_path); |
| 203 | 212 |
| 204 if (!IconUtil::CreateIconFileFromImageFamily(badged_bitmaps, icon_path)) { | 213 if (!IconUtil::CreateIconFileFromImageFamily(badged_bitmaps, icon_path)) { |
| 205 // This can happen in theory if the profile directory is deleted between the | 214 // This can happen in theory if the profile directory is deleted between the |
| 206 // beginning of this function and here; however this is extremely unlikely | 215 // beginning of this function and here; however this is extremely unlikely |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 // Ensure the profile's icon file has been created. | 874 // Ensure the profile's icon file has been created. |
| 866 CreateOrUpdateProfileIcon(profile->GetPath()); | 875 CreateOrUpdateProfileIcon(profile->GetPath()); |
| 867 } | 876 } |
| 868 break; | 877 break; |
| 869 } | 878 } |
| 870 default: | 879 default: |
| 871 NOTREACHED(); | 880 NOTREACHED(); |
| 872 break; | 881 break; |
| 873 } | 882 } |
| 874 } | 883 } |
| OLD | NEW |