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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/prefs/pref_service.h" | |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/win/shortcut.h" | 22 #include "base/win/shortcut.h" |
| 22 #include "chrome/browser/app_icon_win.h" | 23 #include "chrome/browser/app_icon_win.h" |
| 23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 25 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 25 #include "chrome/browser/profiles/profile_info_util.h" | 26 #include "chrome/browser/profiles/profile_info_util.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/shell_integration.h" | 28 #include "chrome/browser/shell_integration.h" |
| 29 #include "chrome/common/chrome_notification_types.h" | |
| 28 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | |
| 29 #include "chrome/installer/util/browser_distribution.h" | 32 #include "chrome/installer/util/browser_distribution.h" |
| 30 #include "chrome/installer/util/product.h" | 33 #include "chrome/installer/util/product.h" |
| 31 #include "chrome/installer/util/shell_util.h" | 34 #include "chrome/installer/util/shell_util.h" |
| 32 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/notification_service.h" | |
| 33 #include "grit/chrome_unscaled_resources.h" | 37 #include "grit/chrome_unscaled_resources.h" |
| 34 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
| 35 #include "skia/ext/image_operations.h" | 39 #include "skia/ext/image_operations.h" |
| 36 #include "skia/ext/platform_canvas.h" | 40 #include "skia/ext/platform_canvas.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/gfx/icon_util.h" | 43 #include "ui/gfx/icon_util.h" |
| 40 #include "ui/gfx/image/image.h" | 44 #include "ui/gfx/image/image.h" |
| 41 #include "ui/gfx/image/image_family.h" | 45 #include "ui/gfx/image/image_family.h" |
| 42 #include "ui/gfx/rect.h" | 46 #include "ui/gfx/rect.h" |
| 43 #include "ui/gfx/skia_util.h" | 47 #include "ui/gfx/skia_util.h" |
| 44 | 48 |
| 45 using content::BrowserThread; | 49 using content::BrowserThread; |
| 46 | 50 |
| 47 namespace { | 51 namespace { |
| 48 | 52 |
| 53 // Name of the badged icon file generated for a given profile. | |
| 54 const char kProfileIconFileName[] = "Google Profile.ico"; | |
| 55 | |
| 49 // Characters that are not allowed in Windows filenames. Taken from | 56 // Characters that are not allowed in Windows filenames. Taken from |
| 50 // http://msdn.microsoft.com/en-us/library/aa365247.aspx | 57 // http://msdn.microsoft.com/en-us/library/aa365247.aspx |
| 51 const char16 kReservedCharacters[] = L"<>:\"/\\|?*\x01\x02\x03\x04\x05\x06\x07" | 58 const char16 kReservedCharacters[] = L"<>:\"/\\|?*\x01\x02\x03\x04\x05\x06\x07" |
| 52 L"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19" | 59 L"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19" |
| 53 L"\x1A\x1B\x1C\x1D\x1E\x1F"; | 60 L"\x1A\x1B\x1C\x1D\x1E\x1F"; |
| 54 | 61 |
| 55 // The maximum number of characters allowed in profile shortcuts' file names. | 62 // The maximum number of characters allowed in profile shortcuts' file names. |
| 56 // Warning: migration code will be needed if this is changed later, since | 63 // Warning: migration code will be needed if this is changed later, since |
| 57 // existing shortcuts might no longer be found if the name is generated | 64 // existing shortcuts might no longer be found if the name is generated |
| 58 // differently than it was when a shortcut was originally created. | 65 // differently than it was when a shortcut was originally created. |
| 59 const int kMaxProfileShortcutFileNameLength = 64; | 66 const int kMaxProfileShortcutFileNameLength = 64; |
| 60 | 67 |
| 61 const int kProfileAvatarBadgeSize = 28; | 68 const int kProfileAvatarBadgeSize = 28; |
| 62 const int kShortcutIconSize = 48; | 69 const int kShortcutIconSize = 48; |
| 63 | 70 |
| 71 const int kCurrentProfileIconVersion = 1; | |
| 72 | |
| 64 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in | 73 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in |
| 65 // profile_info_cache.cc. | 74 // profile_info_cache.cc. |
| 66 const int kProfileAvatarIconResources2x[] = { | 75 const int kProfileAvatarIconResources2x[] = { |
| 67 IDR_PROFILE_AVATAR_2X_0, | 76 IDR_PROFILE_AVATAR_2X_0, |
| 68 IDR_PROFILE_AVATAR_2X_1, | 77 IDR_PROFILE_AVATAR_2X_1, |
| 69 IDR_PROFILE_AVATAR_2X_2, | 78 IDR_PROFILE_AVATAR_2X_2, |
| 70 IDR_PROFILE_AVATAR_2X_3, | 79 IDR_PROFILE_AVATAR_2X_3, |
| 71 IDR_PROFILE_AVATAR_2X_4, | 80 IDR_PROFILE_AVATAR_2X_4, |
| 72 IDR_PROFILE_AVATAR_2X_5, | 81 IDR_PROFILE_AVATAR_2X_5, |
| 73 IDR_PROFILE_AVATAR_2X_6, | 82 IDR_PROFILE_AVATAR_2X_6, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 const SkBitmap& badged_bitmap = | 143 const SkBitmap& badged_bitmap = |
| 135 offscreen_canvas->getDevice()->accessBitmap(false); | 144 offscreen_canvas->getDevice()->accessBitmap(false); |
| 136 SkBitmap badged_bitmap_copy; | 145 SkBitmap badged_bitmap_copy; |
| 137 badged_bitmap.deepCopyTo(&badged_bitmap_copy, badged_bitmap.getConfig()); | 146 badged_bitmap.deepCopyTo(&badged_bitmap_copy, badged_bitmap.getConfig()); |
| 138 return badged_bitmap_copy; | 147 return badged_bitmap_copy; |
| 139 } | 148 } |
| 140 | 149 |
| 141 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, | 150 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, |
| 142 // badging the browser distribution icon with the profile avatar. | 151 // badging the browser distribution icon with the profile avatar. |
| 143 // Returns a path to the shortcut icon file on disk, which is empty if this | 152 // Returns a path to the shortcut icon file on disk, which is empty if this |
| 144 // fails. Use index 0 when assigning the resulting file as the icon. | 153 // fails. Use index 0 when assigning the resulting file as the icon. If both |
| 145 base::FilePath CreateChromeDesktopShortcutIconForProfile( | 154 // given bitmaps are empty, an unbadged icon is created. |
| 155 // |callback| will be run on successful icon creation. | |
| 156 // Returns the path to the created icon on success and an empty base::FilePath | |
| 157 // on failure. | |
| 158 // TODO(calamity): Ideally we'd just copy the app icon verbatim from the exe's | |
| 159 // resources in the case of an unbadged icon. | |
| 160 base::FilePath CreateOrUpdateShortcutIconForProfile( | |
| 146 const base::FilePath& profile_path, | 161 const base::FilePath& profile_path, |
| 147 const SkBitmap& avatar_bitmap_1x, | 162 const SkBitmap& avatar_bitmap_1x, |
| 148 const SkBitmap& avatar_bitmap_2x) { | 163 const SkBitmap& avatar_bitmap_2x, |
| 164 const base::Closure& callback) { | |
| 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 150 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize)); | 166 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize)); |
| 151 if (!app_icon_bitmap) | 167 if (!app_icon_bitmap) |
| 152 return base::FilePath(); | 168 return base::FilePath(); |
| 153 | 169 |
| 154 gfx::ImageFamily badged_bitmaps; | 170 gfx::ImageFamily badged_bitmaps; |
| 155 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( | 171 if (!avatar_bitmap_1x.empty()) { |
| 156 BadgeIcon(*app_icon_bitmap, avatar_bitmap_1x, 1))); | |
| 157 | |
| 158 app_icon_bitmap = GetAppIconForSize(IconUtil::kLargeIconSize); | |
| 159 if (app_icon_bitmap) { | |
| 160 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( | 172 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( |
| 161 BadgeIcon(*app_icon_bitmap, avatar_bitmap_2x, 2))); | 173 BadgeIcon(*app_icon_bitmap, avatar_bitmap_1x, 1))); |
| 162 } | 174 } |
| 163 | 175 |
| 176 scoped_ptr<SkBitmap> large_app_icon_bitmap( | |
| 177 GetAppIconForSize(IconUtil::kLargeIconSize)); | |
| 178 if (large_app_icon_bitmap && !avatar_bitmap_2x.empty()) { | |
| 179 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( | |
| 180 BadgeIcon(*large_app_icon_bitmap, avatar_bitmap_2x, 2))); | |
| 181 } | |
| 182 | |
| 183 // If we have no badged bitmaps, we should just use the default chrome icon. | |
| 184 if (badged_bitmaps.empty()) { | |
| 185 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(*app_icon_bitmap)); | |
| 186 if (large_app_icon_bitmap) { | |
| 187 badged_bitmaps.Add( | |
| 188 gfx::Image::CreateFrom1xBitmap(*large_app_icon_bitmap)); | |
| 189 } | |
| 190 } | |
| 164 // Finally, write the .ico file containing this new bitmap. | 191 // Finally, write the .ico file containing this new bitmap. |
| 165 const base::FilePath icon_path = | 192 const base::FilePath icon_path = |
| 166 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 193 profiles::internal::GetProfileIconPath(profile_path); |
| 167 if (!IconUtil::CreateIconFileFromImageFamily(badged_bitmaps, icon_path)) | 194 const bool had_icon = file_util::PathExists(icon_path); |
| 195 | |
| 196 if (!IconUtil::CreateIconFileFromImageFamily(badged_bitmaps, icon_path)) { | |
| 197 NOTREACHED(); | |
| 168 return base::FilePath(); | 198 return base::FilePath(); |
| 199 } | |
| 169 | 200 |
| 201 if (had_icon) { | |
| 202 // This invalidates the Windows icon cache and causes the icon changes to | |
| 203 // register with the taskbar and desktop. SHCNE_ASSOCCHANGED will cause a | |
| 204 // desktop flash and we would like to avoid that if possible. | |
| 205 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | |
| 206 } else { | |
| 207 SHChangeNotify(SHCNE_CREATE, SHCNF_PATH, icon_path.value().c_str(), NULL); | |
| 208 } | |
| 209 if (!callback.is_null()) | |
| 210 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | |
| 170 return icon_path; | 211 return icon_path; |
| 171 } | 212 } |
| 172 | 213 |
| 214 // Updates the preferences with the current icon version on icon creation | |
| 215 // success. | |
| 216 void OnProfileIconCreateSuccess(Profile* profile) { | |
| 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 218 profile->GetPrefs()->SetInteger(prefs::kProfileIconVersion, | |
| 219 kCurrentProfileIconVersion); | |
| 220 } | |
| 221 | |
| 173 // Gets the user and system directories for desktop shortcuts. Parameters may | 222 // Gets the user and system directories for desktop shortcuts. Parameters may |
| 174 // be NULL if a directory type is not needed. Returns true on success. | 223 // be NULL if a directory type is not needed. Returns true on success. |
| 175 bool GetDesktopShortcutsDirectories( | 224 bool GetDesktopShortcutsDirectories( |
| 176 base::FilePath* user_shortcuts_directory, | 225 base::FilePath* user_shortcuts_directory, |
| 177 base::FilePath* system_shortcuts_directory) { | 226 base::FilePath* system_shortcuts_directory) { |
| 178 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 227 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 179 if (user_shortcuts_directory && | 228 if (user_shortcuts_directory && |
| 180 !ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 229 !ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 181 distribution, ShellUtil::CURRENT_USER, | 230 distribution, ShellUtil::CURRENT_USER, |
| 182 user_shortcuts_directory)) { | 231 user_shortcuts_directory)) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 if (file_util::PathExists(possible_new_system_shortcut)) | 343 if (file_util::PathExists(possible_new_system_shortcut)) |
| 295 base::Delete(old_shortcut_path, false); | 344 base::Delete(old_shortcut_path, false); |
| 296 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) | 345 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) |
| 297 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 346 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
| 298 } else { | 347 } else { |
| 299 // If the shortcut does not exist, it may have been renamed by the user. In | 348 // If the shortcut does not exist, it may have been renamed by the user. In |
| 300 // that case, its name should not be changed. | 349 // that case, its name should not be changed. |
| 301 // It's also possible that a system-level shortcut exists instead - this | 350 // It's also possible that a system-level shortcut exists instead - this |
| 302 // should only be the case for the original Chrome shortcut from an | 351 // should only be the case for the original Chrome shortcut from an |
| 303 // installation. If that's the case, copy that one over - it will get its | 352 // installation. If that's the case, copy that one over - it will get its |
| 304 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. | 353 // properties updated by |
| 354 // |CreateOrUpdateDesktopShortcutsAndIconForProfile()|. | |
| 305 const base::FilePath possible_old_system_shortcut = | 355 const base::FilePath possible_old_system_shortcut = |
| 306 system_shortcuts_directory.Append(old_shortcut_filename); | 356 system_shortcuts_directory.Append(old_shortcut_filename); |
| 307 if (file_util::PathExists(possible_old_system_shortcut)) | 357 if (file_util::PathExists(possible_old_system_shortcut)) |
| 308 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); | 358 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); |
| 309 } | 359 } |
| 310 } | 360 } |
| 311 | 361 |
| 362 struct CreateOrUpdateShortcutsParams { | |
| 363 CreateOrUpdateShortcutsParams( | |
| 364 base::FilePath profile_path, | |
| 365 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, | |
| 366 ProfileShortcutManagerWin::NonProfileShortcutAction action) | |
| 367 : profile_path(profile_path), create_mode(create_mode), action(action) {} | |
| 368 ~CreateOrUpdateShortcutsParams() {} | |
| 369 | |
| 370 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode; | |
| 371 ProfileShortcutManagerWin::NonProfileShortcutAction action; | |
| 372 | |
| 373 // The path for this profile. | |
| 374 base::FilePath profile_path; | |
| 375 // The profile name before this update. Empty on create. | |
| 376 string16 old_profile_name; | |
| 377 // The new profile name. | |
| 378 string16 profile_name; | |
| 379 // Avatar images for this profile. | |
| 380 SkBitmap avatar_image_1x; | |
| 381 SkBitmap avatar_image_2x; | |
| 382 }; | |
| 383 | |
| 312 // Updates all desktop shortcuts for the given profile to have the specified | 384 // Updates all desktop shortcuts for the given profile to have the specified |
| 313 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is | 385 // parameters. If |params.create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut |
| 314 // created if no existing ones were found. Whether non-profile shortcuts should | 386 // is created if no existing ones were found. Whether non-profile shortcuts |
| 315 // be updated is specified by |action|. Must be called on the FILE thread. | 387 // should be updated is specified by |params.action|. Must be called on the FILE |
| 316 void CreateOrUpdateDesktopShortcutsForProfile( | 388 // thread. |callback| is called on successful icon creation. |
| 317 const base::FilePath& profile_path, | 389 void CreateOrUpdateDesktopShortcutsAndIconForProfile( |
| 318 const string16& old_profile_name, | 390 const CreateOrUpdateShortcutsParams& params, |
| 319 const string16& profile_name, | 391 const base::Closure& callback) { |
| 320 const SkBitmap& avatar_image_1x, | |
| 321 const SkBitmap& avatar_image_2x, | |
| 322 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, | |
| 323 ProfileShortcutManagerWin::NonProfileShortcutAction action) { | |
| 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 325 | 393 |
|
gab
2013/07/16 14:10:38
nit: I think it was better with an empty line here
gab
2013/07/16 14:10:38
nit: I think it was better with an empty line here
| |
| 394 const base::FilePath shortcut_icon = | |
| 395 CreateOrUpdateShortcutIconForProfile(params.profile_path, | |
| 396 params.avatar_image_1x, | |
| 397 params.avatar_image_2x, | |
| 398 callback); | |
| 399 if (shortcut_icon.empty()) { | |
| 400 NOTREACHED(); | |
| 401 return; | |
| 402 } | |
| 403 if (params.create_mode == | |
| 404 ProfileShortcutManagerWin::CREATE_OR_UPDATE_ICON_ONLY) { | |
| 405 return; | |
| 406 } | |
| 407 | |
| 326 base::FilePath chrome_exe; | 408 base::FilePath chrome_exe; |
| 327 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 409 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 328 NOTREACHED(); | 410 NOTREACHED(); |
| 329 return; | 411 return; |
| 330 } | 412 } |
| 331 | 413 |
| 332 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 414 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 333 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 415 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
| 334 // the following code may result in NOTREACHED() being hit. | 416 // the following code may result in NOTREACHED() being hit. |
| 335 DCHECK(distribution->CanCreateDesktopShortcuts()); | 417 DCHECK(distribution->CanCreateDesktopShortcuts()); |
| 336 | 418 |
| 337 if (old_profile_name != profile_name) { | 419 if (params.old_profile_name != params.profile_name) { |
| 338 const string16 old_shortcut_filename = | 420 const string16 old_shortcut_filename = |
| 339 profiles::internal::GetShortcutFilenameForProfile(old_profile_name, | 421 profiles::internal::GetShortcutFilenameForProfile( |
| 340 distribution); | 422 params.old_profile_name, |
| 423 distribution); | |
| 341 const string16 new_shortcut_filename = | 424 const string16 new_shortcut_filename = |
| 342 profiles::internal::GetShortcutFilenameForProfile(profile_name, | 425 profiles::internal::GetShortcutFilenameForProfile(params.profile_name, |
| 343 distribution); | 426 distribution); |
| 344 RenameChromeDesktopShortcutForProfile(old_shortcut_filename, | 427 RenameChromeDesktopShortcutForProfile(old_shortcut_filename, |
| 345 new_shortcut_filename); | 428 new_shortcut_filename); |
| 346 } | 429 } |
| 347 | 430 |
| 348 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 431 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
| 349 installer::Product product(distribution); | 432 installer::Product product(distribution); |
| 350 product.AddDefaultShortcutProperties(chrome_exe, &properties); | 433 product.AddDefaultShortcutProperties(chrome_exe, &properties); |
| 351 | 434 |
| 352 const string16 command_line = | 435 const string16 command_line = |
| 353 profiles::internal::CreateProfileShortcutFlags(profile_path); | 436 profiles::internal::CreateProfileShortcutFlags(params.profile_path); |
| 354 | 437 |
| 355 // Only set the profile-specific properties when |profile_name| is non empty. | 438 // Only set the profile-specific properties when |profile_name| is non empty. |
| 356 // If it is empty, it means the shortcut being created should be a regular, | 439 // If it is empty, it means the shortcut being created should be a regular, |
| 357 // non-profile Chrome shortcut. | 440 // non-profile Chrome shortcut. |
| 358 if (!profile_name.empty()) { | 441 if (!params.profile_name.empty()) { |
| 359 const base::FilePath shortcut_icon = | |
| 360 CreateChromeDesktopShortcutIconForProfile(profile_path, | |
| 361 avatar_image_1x, | |
| 362 avatar_image_2x); | |
| 363 if (!shortcut_icon.empty()) | |
| 364 properties.set_icon(shortcut_icon, 0); | |
| 365 properties.set_arguments(command_line); | 442 properties.set_arguments(command_line); |
| 443 properties.set_icon(shortcut_icon, 0); | |
| 366 } else { | 444 } else { |
| 367 // Set the arguments explicitly to the empty string to ensure that | 445 // Set the arguments explicitly to the empty string to ensure that |
| 368 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut. | 446 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut. |
| 369 properties.set_arguments(string16()); | 447 properties.set_arguments(string16()); |
| 370 } | 448 } |
| 371 | 449 |
| 372 properties.set_app_id( | 450 properties.set_app_id( |
| 373 ShellIntegration::GetChromiumModelIdForProfile(profile_path)); | 451 ShellIntegration::GetChromiumModelIdForProfile(params.profile_path)); |
| 374 | 452 |
| 375 ShellUtil::ShortcutOperation operation = | 453 ShellUtil::ShortcutOperation operation = |
| 376 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING; | 454 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING; |
| 377 | 455 |
| 378 std::vector<base::FilePath> shortcuts; | 456 std::vector<base::FilePath> shortcuts; |
| 379 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, | 457 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, |
| 380 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, | 458 params.action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, |
| 381 &shortcuts); | 459 &shortcuts); |
| 382 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && | 460 if (params.create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && |
| 383 shortcuts.empty()) { | 461 shortcuts.empty()) { |
| 384 const string16 shortcut_name = | 462 const string16 shortcut_name = |
| 385 profiles::internal::GetShortcutFilenameForProfile(profile_name, | 463 profiles::internal::GetShortcutFilenameForProfile(params.profile_name, |
| 386 distribution); | 464 distribution); |
| 387 shortcuts.push_back(base::FilePath(shortcut_name)); | 465 shortcuts.push_back(base::FilePath(shortcut_name)); |
| 388 operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; | 466 operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; |
| 389 } | 467 } |
| 390 | 468 |
| 391 for (size_t i = 0; i < shortcuts.size(); ++i) { | 469 for (size_t i = 0; i < shortcuts.size(); ++i) { |
| 392 const base::FilePath shortcut_name = | 470 const base::FilePath shortcut_name = |
| 393 shortcuts[i].BaseName().RemoveExtension(); | 471 shortcuts[i].BaseName().RemoveExtension(); |
| 394 properties.set_shortcut_name(shortcut_name.value()); | 472 properties.set_shortcut_name(shortcut_name.value()); |
| 395 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 473 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 408 base::FileEnumerator::FILES); | 486 base::FileEnumerator::FILES); |
| 409 for (base::FilePath path = enumerator.Next(); !path.empty(); | 487 for (base::FilePath path = enumerator.Next(); !path.empty(); |
| 410 path = enumerator.Next()) { | 488 path = enumerator.Next()) { |
| 411 if (IsChromeShortcut(path, chrome_exe, NULL)) | 489 if (IsChromeShortcut(path, chrome_exe, NULL)) |
| 412 return true; | 490 return true; |
| 413 } | 491 } |
| 414 | 492 |
| 415 return false; | 493 return false; |
| 416 } | 494 } |
| 417 | 495 |
| 418 // Deletes all desktop shortcuts for the specified profile and also removes the | 496 // Deletes all desktop shortcuts for the specified profile. If |
| 419 // corresponding icon file. If |ensure_shortcuts_remain| is true, then a regular | 497 // |ensure_shortcuts_remain| is true, then a regular non-profile shortcut will |
| 420 // non-profile shortcut will be created if this function would otherwise delete | 498 // be created if this function would otherwise delete the last Chrome desktop |
| 421 // the last Chrome desktop shortcut(s). Must be called on the FILE thread. | 499 // shortcut(s). Must be called on the FILE thread. |
| 422 void DeleteDesktopShortcutsAndIconFile(const base::FilePath& profile_path, | 500 void DeleteDesktopShortcuts(const base::FilePath& profile_path, |
| 423 bool ensure_shortcuts_remain) { | 501 bool ensure_shortcuts_remain) { |
| 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 425 | 503 |
| 426 base::FilePath chrome_exe; | 504 base::FilePath chrome_exe; |
| 427 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 505 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 428 NOTREACHED(); | 506 NOTREACHED(); |
| 429 return; | 507 return; |
| 430 } | 508 } |
| 431 | 509 |
| 432 const string16 command_line = | 510 const string16 command_line = |
| 433 profiles::internal::CreateProfileShortcutFlags(profile_path); | 511 profiles::internal::CreateProfileShortcutFlags(profile_path); |
| 434 std::vector<base::FilePath> shortcuts; | 512 std::vector<base::FilePath> shortcuts; |
| 435 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, | 513 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, |
| 436 &shortcuts); | 514 &shortcuts); |
| 437 | 515 |
| 438 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 516 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 439 for (size_t i = 0; i < shortcuts.size(); ++i) { | 517 for (size_t i = 0; i < shortcuts.size(); ++i) { |
| 440 // Use base::Delete() instead of ShellUtil::RemoveShortcut(), as the | 518 // Use base::Delete() instead of ShellUtil::RemoveShortcut(), as the |
| 441 // latter causes non-profile taskbar shortcuts to be unpinned. | 519 // latter causes non-profile taskbar shortcuts to be unpinned. |
| 442 base::Delete(shortcuts[i], false); | 520 base::Delete(shortcuts[i], false); |
| 443 // Notify the shell that the shortcut was deleted to ensure desktop refresh. | 521 // Notify the shell that the shortcut was deleted to ensure desktop refresh. |
| 444 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), | 522 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), |
| 445 NULL); | 523 NULL); |
| 446 } | 524 } |
| 447 | 525 |
| 448 const base::FilePath icon_path = | |
| 449 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | |
| 450 base::Delete(icon_path, false); | |
| 451 | |
| 452 // If |ensure_shortcuts_remain| is true and deleting this profile caused the | 526 // If |ensure_shortcuts_remain| is true and deleting this profile caused the |
| 453 // last shortcuts to be removed, re-create a regular non-profile shortcut. | 527 // last shortcuts to be removed, re-create a regular non-profile shortcut. |
| 454 const bool had_shortcuts = !shortcuts.empty(); | 528 const bool had_shortcuts = !shortcuts.empty(); |
| 455 if (ensure_shortcuts_remain && had_shortcuts && | 529 if (ensure_shortcuts_remain && had_shortcuts && |
| 456 !ChromeDesktopShortcutsExist(chrome_exe)) { | 530 !ChromeDesktopShortcutsExist(chrome_exe)) { |
| 457 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 531 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 458 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 532 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
| 459 // the following code may result in NOTREACHED() being hit. | 533 // the following code may result in NOTREACHED() being hit. |
| 460 DCHECK(distribution->CanCreateDesktopShortcuts()); | 534 DCHECK(distribution->CanCreateDesktopShortcuts()); |
| 461 installer::Product product(distribution); | 535 installer::Product product(distribution); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 SkBitmap bitmap_copy; | 597 SkBitmap bitmap_copy; |
| 524 image_bitmap->deepCopyTo(&bitmap_copy, image_bitmap->getConfig()); | 598 image_bitmap->deepCopyTo(&bitmap_copy, image_bitmap->getConfig()); |
| 525 return bitmap_copy; | 599 return bitmap_copy; |
| 526 } | 600 } |
| 527 | 601 |
| 528 } // namespace | 602 } // namespace |
| 529 | 603 |
| 530 namespace profiles { | 604 namespace profiles { |
| 531 namespace internal { | 605 namespace internal { |
| 532 | 606 |
| 533 const char kProfileIconFileName[] = "Google Profile.ico"; | 607 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { |
| 608 return profile_path.AppendASCII(kProfileIconFileName); | |
| 609 } | |
| 534 | 610 |
| 535 string16 GetShortcutFilenameForProfile(const string16& profile_name, | 611 string16 GetShortcutFilenameForProfile(const string16& profile_name, |
| 536 BrowserDistribution* distribution) { | 612 BrowserDistribution* distribution) { |
| 537 string16 shortcut_name; | 613 string16 shortcut_name; |
| 538 if (!profile_name.empty()) { | 614 if (!profile_name.empty()) { |
| 539 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name)); | 615 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name)); |
| 540 shortcut_name.append(L" - "); | 616 shortcut_name.append(L" - "); |
| 541 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 617 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
| 542 } else { | 618 } else { |
| 543 shortcut_name.append(distribution->GetAppShortCutName()); | 619 shortcut_name.append(distribution->GetAppShortCutName()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 565 ProfileManager* manager) { | 641 ProfileManager* manager) { |
| 566 return new ProfileShortcutManagerWin(manager); | 642 return new ProfileShortcutManagerWin(manager); |
| 567 } | 643 } |
| 568 | 644 |
| 569 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) | 645 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) |
| 570 : profile_manager_(manager) { | 646 : profile_manager_(manager) { |
| 571 DCHECK_EQ( | 647 DCHECK_EQ( |
| 572 arraysize(kProfileAvatarIconResources2x), | 648 arraysize(kProfileAvatarIconResources2x), |
| 573 profile_manager_->GetProfileInfoCache().GetDefaultAvatarIconCount()); | 649 profile_manager_->GetProfileInfoCache().GetDefaultAvatarIconCount()); |
| 574 | 650 |
| 651 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | |
| 652 content::NotificationService::AllSources()); | |
| 653 | |
| 575 profile_manager_->GetProfileInfoCache().AddObserver(this); | 654 profile_manager_->GetProfileInfoCache().AddObserver(this); |
| 576 } | 655 } |
| 577 | 656 |
| 578 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { | 657 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { |
| 579 profile_manager_->GetProfileInfoCache().RemoveObserver(this); | 658 profile_manager_->GetProfileInfoCache().RemoveObserver(this); |
| 580 } | 659 } |
| 581 | 660 |
| 661 void ProfileShortcutManagerWin::CreateOrUpdateProfileIcon( | |
| 662 const base::FilePath& profile_path, | |
| 663 const base::Closure& callback) { | |
| 664 CreateOrUpdateShortcutsForProfileAtPath(profile_path, | |
| 665 CREATE_OR_UPDATE_ICON_ONLY, | |
| 666 IGNORE_NON_PROFILE_SHORTCUTS, | |
| 667 callback); | |
| 668 } | |
| 669 | |
| 582 void ProfileShortcutManagerWin::CreateProfileShortcut( | 670 void ProfileShortcutManagerWin::CreateProfileShortcut( |
| 583 const base::FilePath& profile_path) { | 671 const base::FilePath& profile_path) { |
| 584 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, | 672 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, |
| 585 IGNORE_NON_PROFILE_SHORTCUTS); | 673 IGNORE_NON_PROFILE_SHORTCUTS, |
| 674 base::Closure()); | |
| 586 } | 675 } |
| 587 | 676 |
| 588 void ProfileShortcutManagerWin::RemoveProfileShortcuts( | 677 void ProfileShortcutManagerWin::RemoveProfileShortcuts( |
| 589 const base::FilePath& profile_path) { | 678 const base::FilePath& profile_path) { |
| 590 BrowserThread::PostTask( | 679 BrowserThread::PostTask( |
| 591 BrowserThread::FILE, FROM_HERE, | 680 BrowserThread::FILE, FROM_HERE, |
| 592 base::Bind(&DeleteDesktopShortcutsAndIconFile, profile_path, false)); | 681 base::Bind(&DeleteDesktopShortcuts, profile_path, false)); |
| 593 } | 682 } |
| 594 | 683 |
| 595 void ProfileShortcutManagerWin::HasProfileShortcuts( | 684 void ProfileShortcutManagerWin::HasProfileShortcuts( |
| 596 const base::FilePath& profile_path, | 685 const base::FilePath& profile_path, |
| 597 const base::Callback<void(bool)>& callback) { | 686 const base::Callback<void(bool)>& callback) { |
| 598 BrowserThread::PostTaskAndReplyWithResult( | 687 BrowserThread::PostTaskAndReplyWithResult( |
| 599 BrowserThread::FILE, FROM_HERE, | 688 BrowserThread::FILE, FROM_HERE, |
| 600 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); | 689 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); |
| 601 } | 690 } |
| 602 | 691 |
| 603 void ProfileShortcutManagerWin::OnProfileAdded( | 692 void ProfileShortcutManagerWin::OnProfileAdded( |
| 604 const base::FilePath& profile_path) { | 693 const base::FilePath& profile_path) { |
| 694 CreateOrUpdateProfileIcon(profile_path, base::Closure()); | |
| 605 if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 2) { | 695 if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 2) { |
| 606 // When the second profile is added, make existing non-profile shortcuts | 696 // When the second profile is added, make existing non-profile shortcuts |
| 607 // point to the first profile and be badged/named appropriately. | 697 // point to the first profile and be badged/named appropriately. |
| 608 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), | 698 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), |
| 609 UPDATE_EXISTING_ONLY, | 699 UPDATE_EXISTING_ONLY, |
| 610 UPDATE_NON_PROFILE_SHORTCUTS); | 700 UPDATE_NON_PROFILE_SHORTCUTS, |
| 701 base::Closure()); | |
| 611 } | 702 } |
| 612 } | 703 } |
| 613 | 704 |
| 614 void ProfileShortcutManagerWin::OnProfileWasRemoved( | 705 void ProfileShortcutManagerWin::OnProfileWasRemoved( |
| 615 const base::FilePath& profile_path, | 706 const base::FilePath& profile_path, |
| 616 const string16& profile_name) { | 707 const string16& profile_name) { |
| 617 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 708 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 618 // If there is only one profile remaining, remove the badging information | 709 // If there is only one profile remaining, remove the badging information |
| 619 // from an existing shortcut. | 710 // from an existing shortcut. |
| 620 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1); | 711 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1); |
| 621 if (deleting_down_to_last_profile) { | 712 if (deleting_down_to_last_profile) { |
| 713 // This is needed to unbadge the icon. | |
| 622 CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), | 714 CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), |
| 623 UPDATE_EXISTING_ONLY, | 715 UPDATE_EXISTING_ONLY, |
| 624 IGNORE_NON_PROFILE_SHORTCUTS); | 716 IGNORE_NON_PROFILE_SHORTCUTS, |
| 717 base::Closure()); | |
| 625 } | 718 } |
| 626 | 719 |
| 627 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 720 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 628 base::Bind(&DeleteDesktopShortcutsAndIconFile, | 721 base::Bind(&DeleteDesktopShortcuts, |
| 629 profile_path, | 722 profile_path, |
| 630 deleting_down_to_last_profile)); | 723 deleting_down_to_last_profile)); |
| 631 } | 724 } |
| 632 | 725 |
| 633 void ProfileShortcutManagerWin::OnProfileNameChanged( | 726 void ProfileShortcutManagerWin::OnProfileNameChanged( |
| 634 const base::FilePath& profile_path, | 727 const base::FilePath& profile_path, |
| 635 const string16& old_profile_name) { | 728 const string16& old_profile_name) { |
| 636 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, | 729 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, |
| 637 IGNORE_NON_PROFILE_SHORTCUTS); | 730 IGNORE_NON_PROFILE_SHORTCUTS, |
| 731 base::Closure()); | |
| 638 } | 732 } |
| 639 | 733 |
| 640 void ProfileShortcutManagerWin::OnProfileAvatarChanged( | 734 void ProfileShortcutManagerWin::OnProfileAvatarChanged( |
| 641 const base::FilePath& profile_path) { | 735 const base::FilePath& profile_path) { |
| 642 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, | 736 CreateOrUpdateProfileIcon(profile_path, base::Closure()); |
| 643 IGNORE_NON_PROFILE_SHORTCUTS); | |
| 644 } | 737 } |
| 645 | 738 |
| 646 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath( | 739 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath( |
| 647 const base::FilePath& profile_path) { | 740 const base::FilePath& profile_path) { |
| 648 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 741 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 649 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); | 742 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); |
| 650 // Get the index of the current profile, in order to find the index of the | 743 // Get the index of the current profile, in order to find the index of the |
| 651 // other profile. | 744 // other profile. |
| 652 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); | 745 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); |
| 653 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; | 746 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; |
| 654 return cache.GetPathOfProfileAtIndex(other_profile_index); | 747 return cache.GetPathOfProfileAtIndex(other_profile_index); |
| 655 } | 748 } |
| 656 | 749 |
| 657 void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath( | 750 void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath( |
| 658 const base::FilePath& profile_path, | 751 const base::FilePath& profile_path, |
| 659 CreateOrUpdateMode create_mode, | 752 CreateOrUpdateMode create_mode, |
| 660 NonProfileShortcutAction action) { | 753 NonProfileShortcutAction action, |
| 754 const base::Closure& callback) { | |
| 755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 756 CreateOrUpdateShortcutsParams params(profile_path, create_mode, action); | |
| 757 | |
| 661 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); | 758 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); |
| 662 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path); | 759 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path); |
| 663 if (profile_index == std::string::npos) | 760 if (profile_index == std::string::npos) |
| 664 return; | 761 return; |
| 665 bool remove_badging = cache->GetNumberOfProfiles() == 1; | 762 bool remove_badging = cache->GetNumberOfProfiles() == 1; |
| 666 | 763 |
| 667 string16 old_shortcut_appended_name = | 764 params.old_profile_name = |
| 668 cache->GetShortcutNameOfProfileAtIndex(profile_index); | 765 cache->GetShortcutNameOfProfileAtIndex(profile_index); |
| 669 | 766 |
| 670 // Exit early if the mode is to update existing profile shortcuts only and | 767 // Exit early if the mode is to update existing profile shortcuts only and |
| 671 // none were ever created for this profile, per the shortcut name not being | 768 // none were ever created for this profile, per the shortcut name not being |
| 672 // set in the profile info cache. | 769 // set in the profile info cache. |
| 673 if (old_shortcut_appended_name.empty() && | 770 if (params.old_profile_name.empty() && |
| 674 create_mode == UPDATE_EXISTING_ONLY && | 771 create_mode == UPDATE_EXISTING_ONLY && |
| 675 action == IGNORE_NON_PROFILE_SHORTCUTS) { | 772 action == IGNORE_NON_PROFILE_SHORTCUTS) { |
| 676 return; | 773 return; |
| 677 } | 774 } |
| 678 | 775 |
| 679 string16 new_shortcut_appended_name; | 776 if (!remove_badging) { |
| 680 if (!remove_badging) | 777 params.profile_name = cache->GetNameOfProfileAtIndex(profile_index); |
| 681 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index); | |
| 682 | 778 |
| 683 SkBitmap avatar_bitmap_copy_1x; | |
| 684 SkBitmap avatar_bitmap_copy_2x; | |
| 685 if (!remove_badging) { | |
| 686 const size_t icon_index = | 779 const size_t icon_index = |
| 687 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); | 780 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); |
| 688 const int resource_id_1x = | 781 const int resource_id_1x = |
| 689 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index); | 782 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index); |
| 690 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; | 783 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; |
| 691 // Make a copy of the SkBitmaps to ensure that we can safely use the image | 784 // Make a copy of the SkBitmaps to ensure that we can safely use the image |
| 692 // data on the FILE thread. | 785 // data on the FILE thread. |
| 693 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x); | 786 params.avatar_image_1x = GetImageResourceSkBitmapCopy(resource_id_1x); |
| 694 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x); | 787 params.avatar_image_2x = GetImageResourceSkBitmapCopy(resource_id_2x); |
| 695 } | 788 } |
| 696 BrowserThread::PostTask( | 789 BrowserThread::PostTask( |
| 697 BrowserThread::FILE, FROM_HERE, | 790 BrowserThread::FILE, FROM_HERE, |
| 698 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, | 791 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params, |
| 699 old_shortcut_appended_name, new_shortcut_appended_name, | 792 callback)); |
| 700 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, | |
| 701 action)); | |
| 702 | 793 |
| 703 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 794 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
| 704 new_shortcut_appended_name); | 795 params.profile_name); |
| 705 } | 796 } |
| 797 | |
| 798 void ProfileShortcutManagerWin::Observe( | |
| 799 int type, | |
| 800 const content::NotificationSource& source, | |
| 801 const content::NotificationDetails& details) { | |
| 802 switch (type) { | |
| 803 // This notification is triggered when a profile is loaded. | |
| 804 case chrome::NOTIFICATION_PROFILE_CREATED: { | |
| 805 Profile* profile = | |
| 806 content::Source<Profile>(source).ptr()->GetOriginalProfile(); | |
| 807 if (profile->GetPrefs()->GetInteger(prefs::kProfileIconVersion) < | |
| 808 kCurrentProfileIconVersion) { | |
| 809 // Ensure the profile's icon file has been created. | |
| 810 CreateOrUpdateProfileIcon( | |
| 811 profile->GetPath(), | |
| 812 base::Bind(&OnProfileIconCreateSuccess, profile)); | |
| 813 } | |
| 814 break; | |
| 815 } | |
| 816 default: | |
| 817 NOTREACHED(); | |
| 818 break; | |
| 819 } | |
| 820 } | |
| OLD | NEW |