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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 const SkBitmap& badged_bitmap = | 131 const SkBitmap& badged_bitmap = |
| 132 offscreen_canvas->getDevice()->accessBitmap(false); | 132 offscreen_canvas->getDevice()->accessBitmap(false); |
| 133 SkBitmap badged_bitmap_copy; | 133 SkBitmap badged_bitmap_copy; |
| 134 badged_bitmap.deepCopyTo(&badged_bitmap_copy, badged_bitmap.getConfig()); | 134 badged_bitmap.deepCopyTo(&badged_bitmap_copy, badged_bitmap.getConfig()); |
| 135 return badged_bitmap_copy; | 135 return badged_bitmap_copy; |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, | 138 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, |
| 139 // badging the browser distribution icon with the profile avatar. | 139 // badging the browser distribution icon with the profile avatar. |
| 140 // Returns a path to the shortcut icon file on disk, which is empty if this | 140 // Returns a path to the shortcut icon file on disk, which is empty if this |
| 141 // fails. Use index 0 when assigning the resulting file as the icon. | 141 // fails. Use index 0 when assigning the resulting file as the icon. If both |
| 142 base::FilePath CreateChromeDesktopShortcutIconForProfile( | 142 // given bitmaps are empty, an unbadged icon is created. |
|
Alexei Svitkine (slow)
2013/05/01 15:27:30
Please add a TODO that ideally we'd just want to c
calamity
2013/05/03 04:40:28
Done.
| |
| 143 base::FilePath CreateOrUpdateShortcutIconForProfile( | |
| 143 const base::FilePath& profile_path, | 144 const base::FilePath& profile_path, |
| 144 const SkBitmap& avatar_bitmap_1x, | 145 const SkBitmap& avatar_bitmap_1x, |
| 145 const SkBitmap& avatar_bitmap_2x) { | 146 const SkBitmap& avatar_bitmap_2x) { |
| 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
|
Alexei Svitkine (slow)
2013/05/01 15:27:30
Add: DCHECK_EQ(avatar_bitmap_1x.empty(), avatar_bi
calamity
2013/05/03 04:40:28
I'm assuming this is to facilitate the change belo
| |
| 147 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize)); | 148 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize)); |
| 148 if (!app_icon_bitmap.get()) | 149 if (!app_icon_bitmap.get()) |
| 149 return base::FilePath(); | 150 return base::FilePath(); |
| 150 | 151 |
| 151 const SkBitmap badged_bitmap = BadgeIcon(*app_icon_bitmap, | 152 SkBitmap badged_bitmap; |
|
Alexei Svitkine (slow)
2013/05/01 15:27:30
How about:
SkBitmap badged_bitmap = avatar_bitmap
calamity
2013/05/03 04:40:28
I think that making these changes decreases the ro
| |
| 152 avatar_bitmap_1x, 1); | 153 if (!avatar_bitmap_1x.empty()) |
| 154 badged_bitmap = BadgeIcon(*app_icon_bitmap, avatar_bitmap_1x, 1); | |
| 153 | 155 |
| 154 SkBitmap large_badged_bitmap; | 156 SkBitmap large_badged_bitmap; |
| 155 app_icon_bitmap = GetAppIconForSize(IconUtil::kLargeIconSize); | 157 scoped_ptr<SkBitmap> large_app_icon_bitmap( |
| 156 if (app_icon_bitmap.get()) | 158 GetAppIconForSize(IconUtil::kLargeIconSize)); |
| 157 large_badged_bitmap = BadgeIcon(*app_icon_bitmap, avatar_bitmap_2x, 2); | 159 if (large_app_icon_bitmap.get() && !avatar_bitmap_2x.empty()) { |
| 160 large_badged_bitmap = | |
| 161 BadgeIcon(*large_app_icon_bitmap, avatar_bitmap_2x, 2); | |
| 162 } | |
| 158 | 163 |
| 159 // Finally, write the .ico file containing this new bitmap. | 164 // Finally, write the .ico file containing this new bitmap. |
| 160 const base::FilePath icon_path = | 165 const base::FilePath icon_path = |
| 161 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 166 profiles::internal::GetProfileIconPath(profile_path); |
| 167 if (avatar_bitmap_1x.empty() && avatar_bitmap_2x.empty()) { | |
| 168 badged_bitmap = *app_icon_bitmap; | |
| 169 if (large_app_icon_bitmap.get()) | |
| 170 large_badged_bitmap = *large_app_icon_bitmap; | |
| 171 } | |
| 162 if (!IconUtil::CreateIconFileFromSkBitmap(badged_bitmap, large_badged_bitmap, | 172 if (!IconUtil::CreateIconFileFromSkBitmap(badged_bitmap, large_badged_bitmap, |
| 163 icon_path)) | 173 icon_path)) { |
| 164 return base::FilePath(); | 174 NOTREACHED(); |
|
Alexei Svitkine (slow)
2013/05/01 15:27:30
Re-add the return base::FilePath() to propagate th
calamity
2013/05/03 04:40:28
Done.
| |
| 165 | 175 } |
| 176 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, | |
| 177 NULL, NULL); | |
| 166 return icon_path; | 178 return icon_path; |
| 167 } | 179 } |
| 168 | 180 |
| 169 // Gets the user and system directories for desktop shortcuts. Parameters may | 181 // Gets the user and system directories for desktop shortcuts. Parameters may |
| 170 // be NULL if a directory type is not needed. Returns true on success. | 182 // be NULL if a directory type is not needed. Returns true on success. |
| 171 bool GetDesktopShortcutsDirectories( | 183 bool GetDesktopShortcutsDirectories( |
| 172 base::FilePath* user_shortcuts_directory, | 184 base::FilePath* user_shortcuts_directory, |
| 173 base::FilePath* system_shortcuts_directory) { | 185 base::FilePath* system_shortcuts_directory) { |
| 174 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 186 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 175 if (user_shortcuts_directory && | 187 if (user_shortcuts_directory && |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 if (file_util::PathExists(possible_new_system_shortcut)) | 302 if (file_util::PathExists(possible_new_system_shortcut)) |
| 291 file_util::Delete(old_shortcut_path, false); | 303 file_util::Delete(old_shortcut_path, false); |
| 292 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) | 304 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) |
| 293 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 305 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
| 294 } else { | 306 } else { |
| 295 // If the shortcut does not exist, it may have been renamed by the user. In | 307 // If the shortcut does not exist, it may have been renamed by the user. In |
| 296 // that case, its name should not be changed. | 308 // that case, its name should not be changed. |
| 297 // It's also possible that a system-level shortcut exists instead - this | 309 // It's also possible that a system-level shortcut exists instead - this |
| 298 // should only be the case for the original Chrome shortcut from an | 310 // should only be the case for the original Chrome shortcut from an |
| 299 // installation. If that's the case, copy that one over - it will get its | 311 // installation. If that's the case, copy that one over - it will get its |
| 300 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. | 312 // properties updated by |
| 313 // |CreateOrUpdateDesktopShortcutsAndIconForProfile()|. | |
| 301 const base::FilePath possible_old_system_shortcut = | 314 const base::FilePath possible_old_system_shortcut = |
| 302 system_shortcuts_directory.Append(old_shortcut_filename); | 315 system_shortcuts_directory.Append(old_shortcut_filename); |
| 303 if (file_util::PathExists(possible_old_system_shortcut)) | 316 if (file_util::PathExists(possible_old_system_shortcut)) |
| 304 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); | 317 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); |
| 305 } | 318 } |
| 306 } | 319 } |
| 307 | 320 |
| 308 // Updates all desktop shortcuts for the given profile to have the specified | 321 // Updates all desktop shortcuts for the given profile to have the specified |
| 309 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is | 322 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is |
| 310 // created if no existing ones were found. Whether non-profile shortcuts should | 323 // created if no existing ones were found. Whether non-profile shortcuts should |
| 311 // be updated is specified by |action|. Must be called on the FILE thread. | 324 // be updated is specified by |action|. Must be called on the FILE thread. |
| 312 void CreateOrUpdateDesktopShortcutsForProfile( | 325 void CreateOrUpdateDesktopShortcutsAndIconForProfile( |
| 313 const base::FilePath& profile_path, | 326 const base::FilePath& profile_path, |
| 314 const string16& old_profile_name, | 327 const string16& old_profile_name, |
| 315 const string16& profile_name, | 328 const string16& profile_name, |
| 316 const SkBitmap& avatar_image_1x, | 329 const SkBitmap& avatar_image_1x, |
| 317 const SkBitmap& avatar_image_2x, | 330 const SkBitmap& avatar_image_2x, |
| 318 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, | 331 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, |
| 319 ProfileShortcutManagerWin::NonProfileShortcutAction action) { | 332 ProfileShortcutManagerWin::NonProfileShortcutAction action) { |
| 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 321 | 334 |
| 335 base::FilePath shortcut_icon = | |
| 336 CreateOrUpdateShortcutIconForProfile(profile_path, | |
| 337 avatar_image_1x, | |
| 338 avatar_image_2x); | |
| 339 if (shortcut_icon.empty()) { | |
| 340 NOTREACHED(); | |
|
Alexei Svitkine (slow)
2013/05/01 15:27:30
Add a return.
calamity
2013/05/03 04:40:28
Done.
| |
| 341 } | |
| 342 if (create_mode == ProfileShortcutManagerWin::CREATE_ICON_ONLY) { | |
|
Alexei Svitkine (slow)
2013/05/01 15:27:30
No need for {}'s.
calamity
2013/05/03 04:40:28
Done.
| |
| 343 return; | |
| 344 } | |
| 345 | |
| 322 base::FilePath chrome_exe; | 346 base::FilePath chrome_exe; |
| 323 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 347 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 324 NOTREACHED(); | 348 NOTREACHED(); |
| 325 return; | 349 return; |
| 326 } | 350 } |
| 327 | 351 |
| 328 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 352 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 329 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 353 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
| 330 // the following code may result in NOTREACHED() being hit. | 354 // the following code may result in NOTREACHED() being hit. |
| 331 DCHECK(distribution->CanCreateDesktopShortcuts()); | 355 DCHECK(distribution->CanCreateDesktopShortcuts()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 345 installer::Product product(distribution); | 369 installer::Product product(distribution); |
| 346 product.AddDefaultShortcutProperties(chrome_exe, &properties); | 370 product.AddDefaultShortcutProperties(chrome_exe, &properties); |
| 347 | 371 |
| 348 const string16 command_line = | 372 const string16 command_line = |
| 349 profiles::internal::CreateProfileShortcutFlags(profile_path); | 373 profiles::internal::CreateProfileShortcutFlags(profile_path); |
| 350 | 374 |
| 351 // Only set the profile-specific properties when |profile_name| is non empty. | 375 // Only set the profile-specific properties when |profile_name| is non empty. |
| 352 // If it is empty, it means the shortcut being created should be a regular, | 376 // If it is empty, it means the shortcut being created should be a regular, |
| 353 // non-profile Chrome shortcut. | 377 // non-profile Chrome shortcut. |
| 354 if (!profile_name.empty()) { | 378 if (!profile_name.empty()) { |
| 355 const base::FilePath shortcut_icon = | |
| 356 CreateChromeDesktopShortcutIconForProfile(profile_path, | |
| 357 avatar_image_1x, | |
| 358 avatar_image_2x); | |
| 359 if (!shortcut_icon.empty()) | 379 if (!shortcut_icon.empty()) |
| 360 properties.set_icon(shortcut_icon, 0); | 380 properties.set_icon(shortcut_icon, 0); |
| 361 properties.set_arguments(command_line); | 381 properties.set_arguments(command_line); |
| 362 } else { | 382 } else { |
| 363 // Set the arguments explicitly to the empty string to ensure that | 383 // Set the arguments explicitly to the empty string to ensure that |
| 364 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut. | 384 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut. |
| 365 properties.set_arguments(string16()); | 385 properties.set_arguments(string16()); |
| 366 } | 386 } |
| 367 | 387 |
| 368 ShellUtil::ShortcutOperation operation = | 388 ShellUtil::ShortcutOperation operation = |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 return true; | 425 return true; |
| 406 } | 426 } |
| 407 | 427 |
| 408 return false; | 428 return false; |
| 409 } | 429 } |
| 410 | 430 |
| 411 // Deletes all desktop shortcuts for the specified profile and also removes the | 431 // Deletes all desktop shortcuts for the specified profile and also removes the |
| 412 // corresponding icon file. If |ensure_shortcuts_remain| is true, then a regular | 432 // corresponding icon file. If |ensure_shortcuts_remain| is true, then a regular |
| 413 // non-profile shortcut will be created if this function would otherwise delete | 433 // non-profile shortcut will be created if this function would otherwise delete |
| 414 // the last Chrome desktop shortcut(s). Must be called on the FILE thread. | 434 // the last Chrome desktop shortcut(s). Must be called on the FILE thread. |
| 415 void DeleteDesktopShortcutsAndIconFile(const base::FilePath& profile_path, | 435 void DeleteDesktopShortcuts(const base::FilePath& profile_path, |
| 416 bool ensure_shortcuts_remain) { | 436 bool ensure_shortcuts_remain) { |
| 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 418 | 438 |
| 419 base::FilePath chrome_exe; | 439 base::FilePath chrome_exe; |
| 420 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 440 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 421 NOTREACHED(); | 441 NOTREACHED(); |
| 422 return; | 442 return; |
| 423 } | 443 } |
| 424 | 444 |
| 425 const string16 command_line = | 445 const string16 command_line = |
| 426 profiles::internal::CreateProfileShortcutFlags(profile_path); | 446 profiles::internal::CreateProfileShortcutFlags(profile_path); |
| 427 std::vector<base::FilePath> shortcuts; | 447 std::vector<base::FilePath> shortcuts; |
| 428 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, | 448 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, |
| 429 &shortcuts); | 449 &shortcuts); |
| 430 | 450 |
| 431 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 451 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 432 for (size_t i = 0; i < shortcuts.size(); ++i) { | 452 for (size_t i = 0; i < shortcuts.size(); ++i) { |
| 433 // Use file_util::Delete() instead of ShellUtil::RemoveShortcut(), as the | 453 // Use file_util::Delete() instead of ShellUtil::RemoveShortcut(), as the |
| 434 // latter causes non-profile taskbar shortcuts to be unpinned. | 454 // latter causes non-profile taskbar shortcuts to be unpinned. |
| 435 file_util::Delete(shortcuts[i], false); | 455 file_util::Delete(shortcuts[i], false); |
| 436 // Notify the shell that the shortcut was deleted to ensure desktop refresh. | 456 // Notify the shell that the shortcut was deleted to ensure desktop refresh. |
| 437 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), | 457 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), |
| 438 NULL); | 458 NULL); |
| 439 } | 459 } |
| 440 | 460 |
| 441 const base::FilePath icon_path = | |
| 442 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | |
| 443 file_util::Delete(icon_path, false); | |
| 444 | |
| 445 // If |ensure_shortcuts_remain| is true and deleting this profile caused the | 461 // If |ensure_shortcuts_remain| is true and deleting this profile caused the |
| 446 // last shortcuts to be removed, re-create a regular non-profile shortcut. | 462 // last shortcuts to be removed, re-create a regular non-profile shortcut. |
| 447 const bool had_shortcuts = !shortcuts.empty(); | 463 const bool had_shortcuts = !shortcuts.empty(); |
| 448 if (ensure_shortcuts_remain && had_shortcuts && | 464 if (ensure_shortcuts_remain && had_shortcuts && |
| 449 !ChromeDesktopShortcutsExist(chrome_exe)) { | 465 !ChromeDesktopShortcutsExist(chrome_exe)) { |
| 450 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 466 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 451 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 467 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
| 452 // the following code may result in NOTREACHED() being hit. | 468 // the following code may result in NOTREACHED() being hit. |
| 453 DCHECK(distribution->CanCreateDesktopShortcuts()); | 469 DCHECK(distribution->CanCreateDesktopShortcuts()); |
| 454 installer::Product product(distribution); | 470 installer::Product product(distribution); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 SkBitmap bitmap_copy; | 532 SkBitmap bitmap_copy; |
| 517 image_bitmap->deepCopyTo(&bitmap_copy, image_bitmap->getConfig()); | 533 image_bitmap->deepCopyTo(&bitmap_copy, image_bitmap->getConfig()); |
| 518 return bitmap_copy; | 534 return bitmap_copy; |
| 519 } | 535 } |
| 520 | 536 |
| 521 } // namespace | 537 } // namespace |
| 522 | 538 |
| 523 namespace profiles { | 539 namespace profiles { |
| 524 namespace internal { | 540 namespace internal { |
| 525 | 541 |
| 542 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { | |
| 543 return profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | |
| 544 } | |
| 545 | |
| 526 const char kProfileIconFileName[] = "Google Profile.ico"; | 546 const char kProfileIconFileName[] = "Google Profile.ico"; |
| 527 | 547 |
| 528 string16 GetShortcutFilenameForProfile(const string16& profile_name, | 548 string16 GetShortcutFilenameForProfile(const string16& profile_name, |
| 529 BrowserDistribution* distribution) { | 549 BrowserDistribution* distribution) { |
| 530 string16 shortcut_name; | 550 string16 shortcut_name; |
| 531 if (!profile_name.empty()) { | 551 if (!profile_name.empty()) { |
| 532 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name)); | 552 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name)); |
| 533 shortcut_name.append(L" - "); | 553 shortcut_name.append(L" - "); |
| 534 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 554 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
| 535 } else { | 555 } else { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 void ProfileShortcutManagerWin::CreateProfileShortcut( | 596 void ProfileShortcutManagerWin::CreateProfileShortcut( |
| 577 const base::FilePath& profile_path) { | 597 const base::FilePath& profile_path) { |
| 578 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, | 598 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, |
| 579 IGNORE_NON_PROFILE_SHORTCUTS); | 599 IGNORE_NON_PROFILE_SHORTCUTS); |
| 580 } | 600 } |
| 581 | 601 |
| 582 void ProfileShortcutManagerWin::RemoveProfileShortcuts( | 602 void ProfileShortcutManagerWin::RemoveProfileShortcuts( |
| 583 const base::FilePath& profile_path) { | 603 const base::FilePath& profile_path) { |
| 584 BrowserThread::PostTask( | 604 BrowserThread::PostTask( |
| 585 BrowserThread::FILE, FROM_HERE, | 605 BrowserThread::FILE, FROM_HERE, |
| 586 base::Bind(&DeleteDesktopShortcutsAndIconFile, profile_path, false)); | 606 base::Bind(&DeleteDesktopShortcuts, profile_path, false)); |
| 587 } | 607 } |
| 588 | 608 |
| 589 void ProfileShortcutManagerWin::HasProfileShortcuts( | 609 void ProfileShortcutManagerWin::HasProfileShortcuts( |
| 590 const base::FilePath& profile_path, | 610 const base::FilePath& profile_path, |
| 591 const base::Callback<void(bool)>& callback) { | 611 const base::Callback<void(bool)>& callback) { |
| 592 BrowserThread::PostTaskAndReplyWithResult( | 612 BrowserThread::PostTaskAndReplyWithResult( |
| 593 BrowserThread::FILE, FROM_HERE, | 613 BrowserThread::FILE, FROM_HERE, |
| 594 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); | 614 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); |
| 595 } | 615 } |
| 596 | 616 |
| 597 void ProfileShortcutManagerWin::OnProfileAdded( | 617 void ProfileShortcutManagerWin::OnProfileAdded( |
| 598 const base::FilePath& profile_path) { | 618 const base::FilePath& profile_path) { |
| 599 const size_t profile_count = | 619 const size_t profile_count = |
| 600 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); | 620 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); |
| 601 if (profile_count == 1) { | 621 if (profile_count == 1) { |
| 602 CreateOrUpdateShortcutsForProfileAtPath(profile_path, | 622 CreateOrUpdateShortcutsForProfileAtPath(profile_path, |
| 603 CREATE_WHEN_NONE_FOUND, | 623 CREATE_WHEN_NONE_FOUND, |
| 604 UPDATE_NON_PROFILE_SHORTCUTS); | 624 UPDATE_NON_PROFILE_SHORTCUTS); |
| 605 } else if (profile_count == 2) { | 625 } else { |
| 606 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), | 626 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY, |
| 607 UPDATE_EXISTING_ONLY, | 627 IGNORE_NON_PROFILE_SHORTCUTS); |
| 608 UPDATE_NON_PROFILE_SHORTCUTS); | 628 if (profile_count == 2) { |
| 629 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), | |
| 630 UPDATE_EXISTING_ONLY, | |
| 631 UPDATE_NON_PROFILE_SHORTCUTS); | |
| 632 } | |
| 609 } | 633 } |
| 610 } | 634 } |
| 611 | 635 |
| 612 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( | 636 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( |
| 613 const base::FilePath& profile_path) { | 637 const base::FilePath& profile_path) { |
| 614 } | 638 } |
| 615 | 639 |
| 616 void ProfileShortcutManagerWin::OnProfileWasRemoved( | 640 void ProfileShortcutManagerWin::OnProfileWasRemoved( |
| 617 const base::FilePath& profile_path, | 641 const base::FilePath& profile_path, |
| 618 const string16& profile_name) { | 642 const string16& profile_name) { |
| 619 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 643 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 620 // If there is only one profile remaining, remove the badging information | 644 // If there is only one profile remaining, remove the badging information |
| 621 // from an existing shortcut. | 645 // from an existing shortcut. |
| 622 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1); | 646 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1); |
| 623 if (deleting_down_to_last_profile) { | 647 if (deleting_down_to_last_profile) { |
| 624 CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), | 648 // This is needed to unbadge the icon. |
| 649 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(0); | |
| 650 CreateOrUpdateShortcutsForProfileAtPath(profile_path, | |
| 625 UPDATE_EXISTING_ONLY, | 651 UPDATE_EXISTING_ONLY, |
| 626 IGNORE_NON_PROFILE_SHORTCUTS); | 652 IGNORE_NON_PROFILE_SHORTCUTS); |
| 627 } | 653 } |
| 628 | 654 |
| 629 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 655 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 630 base::Bind(&DeleteDesktopShortcutsAndIconFile, | 656 base::Bind(&DeleteDesktopShortcuts, |
| 631 profile_path, | 657 profile_path, |
| 632 deleting_down_to_last_profile)); | 658 deleting_down_to_last_profile)); |
| 633 } | 659 } |
| 634 | 660 |
| 635 void ProfileShortcutManagerWin::OnProfileNameChanged( | 661 void ProfileShortcutManagerWin::OnProfileNameChanged( |
| 636 const base::FilePath& profile_path, | 662 const base::FilePath& profile_path, |
| 637 const string16& old_profile_name) { | 663 const string16& old_profile_name) { |
| 638 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, | 664 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, |
| 639 IGNORE_NON_PROFILE_SHORTCUTS); | 665 IGNORE_NON_PROFILE_SHORTCUTS); |
| 640 } | 666 } |
| 641 | 667 |
| 642 void ProfileShortcutManagerWin::OnProfileAvatarChanged( | 668 void ProfileShortcutManagerWin::OnProfileAvatarChanged( |
| 643 const base::FilePath& profile_path) { | 669 const base::FilePath& profile_path) { |
| 644 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, | 670 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY, |
| 645 IGNORE_NON_PROFILE_SHORTCUTS); | 671 IGNORE_NON_PROFILE_SHORTCUTS); |
| 646 } | 672 } |
| 647 | 673 |
| 648 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath( | 674 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath( |
| 649 const base::FilePath& profile_path) { | 675 const base::FilePath& profile_path) { |
| 650 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 676 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 651 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); | 677 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); |
| 652 // Get the index of the current profile, in order to find the index of the | 678 // Get the index of the current profile, in order to find the index of the |
| 653 // other profile. | 679 // other profile. |
| 654 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); | 680 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 const int resource_id_1x = | 716 const int resource_id_1x = |
| 691 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index); | 717 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index); |
| 692 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; | 718 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; |
| 693 // Make a copy of the SkBitmaps to ensure that we can safely use the image | 719 // Make a copy of the SkBitmaps to ensure that we can safely use the image |
| 694 // data on the FILE thread. | 720 // data on the FILE thread. |
| 695 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x); | 721 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x); |
| 696 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x); | 722 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x); |
| 697 } | 723 } |
| 698 BrowserThread::PostTask( | 724 BrowserThread::PostTask( |
| 699 BrowserThread::FILE, FROM_HERE, | 725 BrowserThread::FILE, FROM_HERE, |
| 700 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, | 726 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, profile_path, |
| 701 old_shortcut_appended_name, new_shortcut_appended_name, | 727 old_shortcut_appended_name, new_shortcut_appended_name, |
| 702 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, | 728 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, |
| 703 action)); | 729 action)); |
| 704 | 730 |
| 705 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 731 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
| 706 new_shortcut_appended_name); | 732 new_shortcut_appended_name); |
| 707 } | 733 } |
| OLD | NEW |