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

Side by Side Diff: chrome/browser/profiles/profile_shortcut_manager_win.cc

Issue 14137032: Create profile .ico file on profile creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use important_file_handler for icon file creation Created 7 years, 7 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
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 const SkBitmap& badged_bitmap = 132 const SkBitmap& badged_bitmap =
133 offscreen_canvas->getDevice()->accessBitmap(false); 133 offscreen_canvas->getDevice()->accessBitmap(false);
134 SkBitmap badged_bitmap_copy; 134 SkBitmap badged_bitmap_copy;
135 badged_bitmap.deepCopyTo(&badged_bitmap_copy, badged_bitmap.getConfig()); 135 badged_bitmap.deepCopyTo(&badged_bitmap_copy, badged_bitmap.getConfig());
136 return badged_bitmap_copy; 136 return badged_bitmap_copy;
137 } 137 }
138 138
139 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile, 139 // Creates a desktop shortcut icon file (.ico) on the disk for a given profile,
140 // badging the browser distribution icon with the profile avatar. 140 // badging the browser distribution icon with the profile avatar.
141 // Returns a path to the shortcut icon file on disk, which is empty if this 141 // Returns a path to the shortcut icon file on disk, which is empty if this
142 // fails. Use index 0 when assigning the resulting file as the icon. 142 // fails. Use index 0 when assigning the resulting file as the icon. If both
143 base::FilePath CreateChromeDesktopShortcutIconForProfile( 143 // given bitmaps are empty, an unbadged icon is created.
144 // TODO(calamity): Ideally we'd just copy the app icon verbatim from the exe's
145 // resources in the case of an unbadged icon.
146 base::FilePath CreateOrUpdateShortcutIconForProfile(
144 const base::FilePath& profile_path, 147 const base::FilePath& profile_path,
145 const SkBitmap& avatar_bitmap_1x, 148 const SkBitmap& avatar_bitmap_1x,
146 const SkBitmap& avatar_bitmap_2x) { 149 const SkBitmap& avatar_bitmap_2x) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
148 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize)); 151 scoped_ptr<SkBitmap> app_icon_bitmap(GetAppIconForSize(kShortcutIconSize));
149 if (!app_icon_bitmap.get()) 152 if (!app_icon_bitmap.get())
150 return base::FilePath(); 153 return base::FilePath();
151 154
152 gfx::ImageFamily badged_bitmaps; 155 gfx::ImageFamily badged_bitmaps;
153 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( 156 if (!avatar_bitmap_1x.empty()) {
154 BadgeIcon(*app_icon_bitmap, avatar_bitmap_1x, 1)));
155
156 app_icon_bitmap = GetAppIconForSize(IconUtil::kLargeIconSize);
157 if (app_icon_bitmap.get()) {
158 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap( 157 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(
159 BadgeIcon(*app_icon_bitmap, avatar_bitmap_2x, 2))); 158 BadgeIcon(*app_icon_bitmap, avatar_bitmap_1x, 1)));
160 } 159 }
161 160
161 scoped_ptr<SkBitmap> large_app_icon_bitmap(
162 GetAppIconForSize(IconUtil::kLargeIconSize));
163 if (large_app_icon_bitmap.get() && !avatar_bitmap_2x.empty()) {
164 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(
165 BadgeIcon(*large_app_icon_bitmap, avatar_bitmap_2x, 2)));
166 }
167
168 // If we have no badged bitmaps, we should just use the default chrome icon.
169 if (badged_bitmaps.empty()) {
170 badged_bitmaps.Add(gfx::Image::CreateFrom1xBitmap(*app_icon_bitmap));
171 if (large_app_icon_bitmap.get()) {
172 badged_bitmaps.Add(
173 gfx::Image::CreateFrom1xBitmap(*large_app_icon_bitmap));
174 }
175 }
162 // Finally, write the .ico file containing this new bitmap. 176 // Finally, write the .ico file containing this new bitmap.
163 const base::FilePath icon_path = 177 const base::FilePath icon_path =
164 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); 178 profiles::internal::GetProfileIconPath(profile_path);
165 if (!IconUtil::CreateIconFileFromImageFamily(badged_bitmaps, icon_path))
166 return base::FilePath();
167 179
180 if (IconUtil::ShouldUpdateIcon(icon_path, badged_bitmaps)) {
181 if (IconUtil::SaveIconWithCheckSum(icon_path, badged_bitmaps)) {
182 // This invalidates the Windows icon cache and causes the icon changes to
183 // register with the taskbar an desktop.
184 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT,
gab 2013/05/08 13:01:08 Awesome, that's much better :) -- I didn't know we
185 NULL, NULL);
186 }
187 }
168 return icon_path; 188 return icon_path;
169 } 189 }
170 190
171 // Gets the user and system directories for desktop shortcuts. Parameters may 191 // Gets the user and system directories for desktop shortcuts. Parameters may
172 // be NULL if a directory type is not needed. Returns true on success. 192 // be NULL if a directory type is not needed. Returns true on success.
173 bool GetDesktopShortcutsDirectories( 193 bool GetDesktopShortcutsDirectories(
174 base::FilePath* user_shortcuts_directory, 194 base::FilePath* user_shortcuts_directory,
175 base::FilePath* system_shortcuts_directory) { 195 base::FilePath* system_shortcuts_directory) {
176 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 196 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
177 if (user_shortcuts_directory && 197 if (user_shortcuts_directory &&
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (file_util::PathExists(possible_new_system_shortcut)) 312 if (file_util::PathExists(possible_new_system_shortcut))
293 file_util::Delete(old_shortcut_path, false); 313 file_util::Delete(old_shortcut_path, false);
294 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) 314 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path))
295 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; 315 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut.";
296 } else { 316 } else {
297 // If the shortcut does not exist, it may have been renamed by the user. In 317 // If the shortcut does not exist, it may have been renamed by the user. In
298 // that case, its name should not be changed. 318 // that case, its name should not be changed.
299 // It's also possible that a system-level shortcut exists instead - this 319 // It's also possible that a system-level shortcut exists instead - this
300 // should only be the case for the original Chrome shortcut from an 320 // should only be the case for the original Chrome shortcut from an
301 // installation. If that's the case, copy that one over - it will get its 321 // installation. If that's the case, copy that one over - it will get its
302 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. 322 // properties updated by
323 // |CreateOrUpdateDesktopShortcutsAndIconForProfile()|.
303 const base::FilePath possible_old_system_shortcut = 324 const base::FilePath possible_old_system_shortcut =
304 system_shortcuts_directory.Append(old_shortcut_filename); 325 system_shortcuts_directory.Append(old_shortcut_filename);
305 if (file_util::PathExists(possible_old_system_shortcut)) 326 if (file_util::PathExists(possible_old_system_shortcut))
306 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); 327 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path);
307 } 328 }
308 } 329 }
309 330
310 // Updates all desktop shortcuts for the given profile to have the specified 331 // Updates all desktop shortcuts for the given profile to have the specified
311 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is 332 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is
312 // created if no existing ones were found. Whether non-profile shortcuts should 333 // created if no existing ones were found. Whether non-profile shortcuts should
313 // be updated is specified by |action|. Must be called on the FILE thread. 334 // be updated is specified by |action|. Must be called on the FILE thread.
314 void CreateOrUpdateDesktopShortcutsForProfile( 335 void CreateOrUpdateDesktopShortcutsAndIconForProfile(
315 const base::FilePath& profile_path, 336 const base::FilePath& profile_path,
316 const string16& old_profile_name, 337 const string16& old_profile_name,
317 const string16& profile_name, 338 const string16& profile_name,
318 const SkBitmap& avatar_image_1x, 339 const SkBitmap& avatar_image_1x,
319 const SkBitmap& avatar_image_2x, 340 const SkBitmap& avatar_image_2x,
320 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, 341 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode,
321 ProfileShortcutManagerWin::NonProfileShortcutAction action) { 342 ProfileShortcutManagerWin::NonProfileShortcutAction action) {
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
323 344
345 base::FilePath shortcut_icon =
346 CreateOrUpdateShortcutIconForProfile(profile_path,
347 avatar_image_1x,
348 avatar_image_2x);
349 if (shortcut_icon.empty()) {
350 NOTREACHED();
351 return;
352 }
353 if (create_mode == ProfileShortcutManagerWin::CREATE_ICON_ONLY)
354 return;
355
324 base::FilePath chrome_exe; 356 base::FilePath chrome_exe;
325 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 357 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
326 NOTREACHED(); 358 NOTREACHED();
327 return; 359 return;
328 } 360 }
329 361
330 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 362 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
331 // Ensure that the distribution supports creating shortcuts. If it doesn't, 363 // Ensure that the distribution supports creating shortcuts. If it doesn't,
332 // the following code may result in NOTREACHED() being hit. 364 // the following code may result in NOTREACHED() being hit.
333 DCHECK(distribution->CanCreateDesktopShortcuts()); 365 DCHECK(distribution->CanCreateDesktopShortcuts());
(...skipping 13 matching lines...) Expand all
347 installer::Product product(distribution); 379 installer::Product product(distribution);
348 product.AddDefaultShortcutProperties(chrome_exe, &properties); 380 product.AddDefaultShortcutProperties(chrome_exe, &properties);
349 381
350 const string16 command_line = 382 const string16 command_line =
351 profiles::internal::CreateProfileShortcutFlags(profile_path); 383 profiles::internal::CreateProfileShortcutFlags(profile_path);
352 384
353 // Only set the profile-specific properties when |profile_name| is non empty. 385 // Only set the profile-specific properties when |profile_name| is non empty.
354 // If it is empty, it means the shortcut being created should be a regular, 386 // If it is empty, it means the shortcut being created should be a regular,
355 // non-profile Chrome shortcut. 387 // non-profile Chrome shortcut.
356 if (!profile_name.empty()) { 388 if (!profile_name.empty()) {
357 const base::FilePath shortcut_icon =
358 CreateChromeDesktopShortcutIconForProfile(profile_path,
359 avatar_image_1x,
360 avatar_image_2x);
361 if (!shortcut_icon.empty()) 389 if (!shortcut_icon.empty())
362 properties.set_icon(shortcut_icon, 0); 390 properties.set_icon(shortcut_icon, 0);
363 properties.set_arguments(command_line); 391 properties.set_arguments(command_line);
364 } else { 392 } else {
365 // Set the arguments explicitly to the empty string to ensure that 393 // Set the arguments explicitly to the empty string to ensure that
366 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut. 394 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut.
367 properties.set_arguments(string16()); 395 properties.set_arguments(string16());
368 } 396 }
369 397
370 ShellUtil::ShortcutOperation operation = 398 ShellUtil::ShortcutOperation operation =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 file_util::FileEnumerator::FILES); 431 file_util::FileEnumerator::FILES);
404 for (base::FilePath path = enumerator.Next(); !path.empty(); 432 for (base::FilePath path = enumerator.Next(); !path.empty();
405 path = enumerator.Next()) { 433 path = enumerator.Next()) {
406 if (IsChromeShortcut(path, chrome_exe, NULL)) 434 if (IsChromeShortcut(path, chrome_exe, NULL))
407 return true; 435 return true;
408 } 436 }
409 437
410 return false; 438 return false;
411 } 439 }
412 440
413 // Deletes all desktop shortcuts for the specified profile and also removes the 441 // Deletes all desktop shortcuts for the specified profile. If
414 // corresponding icon file. If |ensure_shortcuts_remain| is true, then a regular 442 // |ensure_shortcuts_remain| is true, then a regular non-profile shortcut will
415 // non-profile shortcut will be created if this function would otherwise delete 443 // be created if this function would otherwise delete the last Chrome desktop
416 // the last Chrome desktop shortcut(s). Must be called on the FILE thread. 444 // shortcut(s). Must be called on the FILE thread.
417 void DeleteDesktopShortcutsAndIconFile(const base::FilePath& profile_path, 445 void DeleteDesktopShortcuts(const base::FilePath& profile_path,
418 bool ensure_shortcuts_remain) { 446 bool ensure_shortcuts_remain) {
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
420 448
421 base::FilePath chrome_exe; 449 base::FilePath chrome_exe;
422 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 450 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
423 NOTREACHED(); 451 NOTREACHED();
424 return; 452 return;
425 } 453 }
426 454
427 const string16 command_line = 455 const string16 command_line =
428 profiles::internal::CreateProfileShortcutFlags(profile_path); 456 profiles::internal::CreateProfileShortcutFlags(profile_path);
429 std::vector<base::FilePath> shortcuts; 457 std::vector<base::FilePath> shortcuts;
430 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, 458 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false,
431 &shortcuts); 459 &shortcuts);
432 460
433 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 461 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
434 for (size_t i = 0; i < shortcuts.size(); ++i) { 462 for (size_t i = 0; i < shortcuts.size(); ++i) {
435 // Use file_util::Delete() instead of ShellUtil::RemoveShortcut(), as the 463 // Use file_util::Delete() instead of ShellUtil::RemoveShortcut(), as the
436 // latter causes non-profile taskbar shortcuts to be unpinned. 464 // latter causes non-profile taskbar shortcuts to be unpinned.
437 file_util::Delete(shortcuts[i], false); 465 file_util::Delete(shortcuts[i], false);
438 // Notify the shell that the shortcut was deleted to ensure desktop refresh. 466 // Notify the shell that the shortcut was deleted to ensure desktop refresh.
439 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), 467 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(),
440 NULL); 468 NULL);
441 } 469 }
442 470
443 const base::FilePath icon_path =
444 profile_path.AppendASCII(profiles::internal::kProfileIconFileName);
445 file_util::Delete(icon_path, false);
446
447 // If |ensure_shortcuts_remain| is true and deleting this profile caused the 471 // If |ensure_shortcuts_remain| is true and deleting this profile caused the
448 // last shortcuts to be removed, re-create a regular non-profile shortcut. 472 // last shortcuts to be removed, re-create a regular non-profile shortcut.
449 const bool had_shortcuts = !shortcuts.empty(); 473 const bool had_shortcuts = !shortcuts.empty();
450 if (ensure_shortcuts_remain && had_shortcuts && 474 if (ensure_shortcuts_remain && had_shortcuts &&
451 !ChromeDesktopShortcutsExist(chrome_exe)) { 475 !ChromeDesktopShortcutsExist(chrome_exe)) {
452 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 476 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
453 // Ensure that the distribution supports creating shortcuts. If it doesn't, 477 // Ensure that the distribution supports creating shortcuts. If it doesn't,
454 // the following code may result in NOTREACHED() being hit. 478 // the following code may result in NOTREACHED() being hit.
455 DCHECK(distribution->CanCreateDesktopShortcuts()); 479 DCHECK(distribution->CanCreateDesktopShortcuts());
456 installer::Product product(distribution); 480 installer::Product product(distribution);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return bitmap_copy; 544 return bitmap_copy;
521 } 545 }
522 546
523 } // namespace 547 } // namespace
524 548
525 namespace profiles { 549 namespace profiles {
526 namespace internal { 550 namespace internal {
527 551
528 const char kProfileIconFileName[] = "Google Profile.ico"; 552 const char kProfileIconFileName[] = "Google Profile.ico";
529 553
554 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) {
555 return profile_path.AppendASCII(kProfileIconFileName);
556 }
557
530 string16 GetShortcutFilenameForProfile(const string16& profile_name, 558 string16 GetShortcutFilenameForProfile(const string16& profile_name,
531 BrowserDistribution* distribution) { 559 BrowserDistribution* distribution) {
532 string16 shortcut_name; 560 string16 shortcut_name;
533 if (!profile_name.empty()) { 561 if (!profile_name.empty()) {
534 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name)); 562 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name));
535 shortcut_name.append(L" - "); 563 shortcut_name.append(L" - ");
536 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 564 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
537 } else { 565 } else {
538 shortcut_name.append(distribution->GetAppShortCutName()); 566 shortcut_name.append(distribution->GetAppShortCutName());
539 } 567 }
(...skipping 28 matching lines...) Expand all
568 arraysize(kProfileAvatarIconResources2x), 596 arraysize(kProfileAvatarIconResources2x),
569 profile_manager_->GetProfileInfoCache().GetDefaultAvatarIconCount()); 597 profile_manager_->GetProfileInfoCache().GetDefaultAvatarIconCount());
570 598
571 profile_manager_->GetProfileInfoCache().AddObserver(this); 599 profile_manager_->GetProfileInfoCache().AddObserver(this);
572 } 600 }
573 601
574 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { 602 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() {
575 profile_manager_->GetProfileInfoCache().RemoveObserver(this); 603 profile_manager_->GetProfileInfoCache().RemoveObserver(this);
576 } 604 }
577 605
606 void ProfileShortcutManagerWin::CreateProfileIcon(
607 const base::FilePath& profile_path) {
608 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY,
609 IGNORE_NON_PROFILE_SHORTCUTS);
610 }
611
578 void ProfileShortcutManagerWin::CreateProfileShortcut( 612 void ProfileShortcutManagerWin::CreateProfileShortcut(
579 const base::FilePath& profile_path) { 613 const base::FilePath& profile_path) {
580 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, 614 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND,
581 IGNORE_NON_PROFILE_SHORTCUTS); 615 IGNORE_NON_PROFILE_SHORTCUTS);
582 } 616 }
583 617
584 void ProfileShortcutManagerWin::RemoveProfileShortcuts( 618 void ProfileShortcutManagerWin::RemoveProfileShortcuts(
585 const base::FilePath& profile_path) { 619 const base::FilePath& profile_path) {
586 BrowserThread::PostTask( 620 BrowserThread::PostTask(
587 BrowserThread::FILE, FROM_HERE, 621 BrowserThread::FILE, FROM_HERE,
588 base::Bind(&DeleteDesktopShortcutsAndIconFile, profile_path, false)); 622 base::Bind(&DeleteDesktopShortcuts, profile_path, false));
589 } 623 }
590 624
591 void ProfileShortcutManagerWin::HasProfileShortcuts( 625 void ProfileShortcutManagerWin::HasProfileShortcuts(
592 const base::FilePath& profile_path, 626 const base::FilePath& profile_path,
593 const base::Callback<void(bool)>& callback) { 627 const base::Callback<void(bool)>& callback) {
594 BrowserThread::PostTaskAndReplyWithResult( 628 BrowserThread::PostTaskAndReplyWithResult(
595 BrowserThread::FILE, FROM_HERE, 629 BrowserThread::FILE, FROM_HERE,
596 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); 630 base::Bind(&HasAnyProfileShortcuts, profile_path), callback);
597 } 631 }
598 632
599 void ProfileShortcutManagerWin::OnProfileAdded( 633 void ProfileShortcutManagerWin::OnProfileAdded(
600 const base::FilePath& profile_path) { 634 const base::FilePath& profile_path) {
601 const size_t profile_count = 635 const size_t profile_count =
602 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); 636 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles();
603 if (profile_count == 1) { 637 if (profile_count == 1) {
604 CreateOrUpdateShortcutsForProfileAtPath(profile_path, 638 CreateOrUpdateShortcutsForProfileAtPath(profile_path,
605 CREATE_WHEN_NONE_FOUND, 639 CREATE_WHEN_NONE_FOUND,
606 UPDATE_NON_PROFILE_SHORTCUTS); 640 UPDATE_NON_PROFILE_SHORTCUTS);
607 } else if (profile_count == 2) { 641 } else {
608 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), 642 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY,
609 UPDATE_EXISTING_ONLY, 643 IGNORE_NON_PROFILE_SHORTCUTS);
610 UPDATE_NON_PROFILE_SHORTCUTS); 644 if (profile_count == 2) {
645 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path),
646 UPDATE_EXISTING_ONLY,
647 UPDATE_NON_PROFILE_SHORTCUTS);
648 }
611 } 649 }
612 } 650 }
613 651
614 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( 652 void ProfileShortcutManagerWin::OnProfileWillBeRemoved(
615 const base::FilePath& profile_path) { 653 const base::FilePath& profile_path) {
616 } 654 }
617 655
618 void ProfileShortcutManagerWin::OnProfileWasRemoved( 656 void ProfileShortcutManagerWin::OnProfileWasRemoved(
619 const base::FilePath& profile_path, 657 const base::FilePath& profile_path,
620 const string16& profile_name) { 658 const string16& profile_name) {
621 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 659 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
622 // If there is only one profile remaining, remove the badging information 660 // If there is only one profile remaining, remove the badging information
623 // from an existing shortcut. 661 // from an existing shortcut.
624 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1); 662 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1);
625 if (deleting_down_to_last_profile) { 663 if (deleting_down_to_last_profile) {
664 // This is needed to unbadge the icon.
626 CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), 665 CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0),
627 UPDATE_EXISTING_ONLY, 666 UPDATE_EXISTING_ONLY,
628 IGNORE_NON_PROFILE_SHORTCUTS); 667 IGNORE_NON_PROFILE_SHORTCUTS);
629 } 668 }
630 669
631 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 670 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
632 base::Bind(&DeleteDesktopShortcutsAndIconFile, 671 base::Bind(&DeleteDesktopShortcuts,
633 profile_path, 672 profile_path,
634 deleting_down_to_last_profile)); 673 deleting_down_to_last_profile));
635 } 674 }
636 675
637 void ProfileShortcutManagerWin::OnProfileNameChanged( 676 void ProfileShortcutManagerWin::OnProfileNameChanged(
638 const base::FilePath& profile_path, 677 const base::FilePath& profile_path,
639 const string16& old_profile_name) { 678 const string16& old_profile_name) {
640 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, 679 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY,
641 IGNORE_NON_PROFILE_SHORTCUTS); 680 IGNORE_NON_PROFILE_SHORTCUTS);
642 } 681 }
643 682
644 void ProfileShortcutManagerWin::OnProfileAvatarChanged( 683 void ProfileShortcutManagerWin::OnProfileAvatarChanged(
645 const base::FilePath& profile_path) { 684 const base::FilePath& profile_path) {
646 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, 685 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY,
647 IGNORE_NON_PROFILE_SHORTCUTS); 686 IGNORE_NON_PROFILE_SHORTCUTS);
648 } 687 }
649 688
650 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath( 689 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath(
651 const base::FilePath& profile_path) { 690 const base::FilePath& profile_path) {
652 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 691 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
653 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); 692 DCHECK_EQ(2U, cache.GetNumberOfProfiles());
654 // Get the index of the current profile, in order to find the index of the 693 // Get the index of the current profile, in order to find the index of the
655 // other profile. 694 // other profile.
656 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); 695 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 const int resource_id_1x = 731 const int resource_id_1x =
693 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index); 732 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index);
694 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; 733 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index];
695 // Make a copy of the SkBitmaps to ensure that we can safely use the image 734 // Make a copy of the SkBitmaps to ensure that we can safely use the image
696 // data on the FILE thread. 735 // data on the FILE thread.
697 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x); 736 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x);
698 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x); 737 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x);
699 } 738 }
700 BrowserThread::PostTask( 739 BrowserThread::PostTask(
701 BrowserThread::FILE, FROM_HERE, 740 BrowserThread::FILE, FROM_HERE,
702 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, 741 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, profile_path,
703 old_shortcut_appended_name, new_shortcut_appended_name, 742 old_shortcut_appended_name, new_shortcut_appended_name,
704 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, 743 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode,
705 action)); 744 action));
706 745
707 cache->SetShortcutNameOfProfileAtIndex(profile_index, 746 cache->SetShortcutNameOfProfileAtIndex(profile_index,
708 new_shortcut_appended_name); 747 new_shortcut_appended_name);
709 } 748 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698