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

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: add profile icon creation on first run past this change 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 app_icon_bitmap.width() - sk_icon.width(), 130 app_icon_bitmap.width() - sk_icon.width(),
131 app_icon_bitmap.height() - sk_icon.height()); 131 app_icon_bitmap.height() - sk_icon.height());
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.
gab 2013/05/07 12:38:39 Why is "browser distribution" mentioned in this co
calamity 2013/05/08 08:15:42 I think it means the blue chromium icon vs the goo
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
Alexei Svitkine (slow) 2013/05/03 17:20:47 Nit: capitalize 'ideally'
calamity 2013/05/08 08:15:42 Done.
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)) 179 if (!IconUtil::CreateIconFileFromImageFamily(badged_bitmaps, icon_path)) {
180 NOTREACHED();
166 return base::FilePath(); 181 return base::FilePath();
182 }
167 183
184 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT,
Alexei Svitkine (slow) 2013/05/03 17:20:47 Add a comment mentioning why this is necessary. (T
gab 2013/05/07 12:38:39 FYI, I have had issues with SHCNF_FLUSHNOWAIT in t
calamity 2013/05/08 08:15:42 CreateIconFileFromImageFamily is synchronous. I do
gab 2013/05/08 13:01:08 SHChangeNotify(SHCNE_CREATE, SHCNF_PATH, icon_path
calamity 2013/05/09 06:12:16 SetAppIconForWindow would probably be called in th
gab 2013/05/09 13:43:56 Ah right, makes sense, the current code is synchro
185 NULL, NULL);
168 return icon_path; 186 return icon_path;
169 } 187 }
170 188
171 // Gets the user and system directories for desktop shortcuts. Parameters may 189 // 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. 190 // be NULL if a directory type is not needed. Returns true on success.
173 bool GetDesktopShortcutsDirectories( 191 bool GetDesktopShortcutsDirectories(
174 base::FilePath* user_shortcuts_directory, 192 base::FilePath* user_shortcuts_directory,
175 base::FilePath* system_shortcuts_directory) { 193 base::FilePath* system_shortcuts_directory) {
176 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 194 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
177 if (user_shortcuts_directory && 195 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)) 310 if (file_util::PathExists(possible_new_system_shortcut))
293 file_util::Delete(old_shortcut_path, false); 311 file_util::Delete(old_shortcut_path, false);
294 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) 312 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path))
295 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; 313 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut.";
296 } else { 314 } else {
297 // If the shortcut does not exist, it may have been renamed by the user. In 315 // If the shortcut does not exist, it may have been renamed by the user. In
298 // that case, its name should not be changed. 316 // that case, its name should not be changed.
299 // It's also possible that a system-level shortcut exists instead - this 317 // 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 318 // 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 319 // installation. If that's the case, copy that one over - it will get its
302 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. 320 // properties updated by
321 // |CreateOrUpdateDesktopShortcutsAndIconForProfile()|.
303 const base::FilePath possible_old_system_shortcut = 322 const base::FilePath possible_old_system_shortcut =
304 system_shortcuts_directory.Append(old_shortcut_filename); 323 system_shortcuts_directory.Append(old_shortcut_filename);
305 if (file_util::PathExists(possible_old_system_shortcut)) 324 if (file_util::PathExists(possible_old_system_shortcut))
306 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); 325 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path);
307 } 326 }
308 } 327 }
309 328
310 // Updates all desktop shortcuts for the given profile to have the specified 329 // 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 330 // 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 331 // 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. 332 // be updated is specified by |action|. Must be called on the FILE thread.
314 void CreateOrUpdateDesktopShortcutsForProfile( 333 void CreateOrUpdateDesktopShortcutsAndIconForProfile(
315 const base::FilePath& profile_path, 334 const base::FilePath& profile_path,
316 const string16& old_profile_name, 335 const string16& old_profile_name,
317 const string16& profile_name, 336 const string16& profile_name,
318 const SkBitmap& avatar_image_1x, 337 const SkBitmap& avatar_image_1x,
319 const SkBitmap& avatar_image_2x, 338 const SkBitmap& avatar_image_2x,
320 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, 339 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode,
321 ProfileShortcutManagerWin::NonProfileShortcutAction action) { 340 ProfileShortcutManagerWin::NonProfileShortcutAction action) {
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
323 342
343 base::FilePath shortcut_icon =
Alexei Svitkine (slow) 2013/05/03 17:20:47 Add a TODO that we should only update the icon if
calamity 2013/05/08 08:15:42 Code to do this existed in web_app_win. I moved it
344 CreateOrUpdateShortcutIconForProfile(profile_path,
345 avatar_image_1x,
346 avatar_image_2x);
347 if (shortcut_icon.empty()) {
348 NOTREACHED();
349 return;
350 }
351 if (create_mode == ProfileShortcutManagerWin::CREATE_ICON_ONLY)
352 return;
353
324 base::FilePath chrome_exe; 354 base::FilePath chrome_exe;
325 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 355 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
326 NOTREACHED(); 356 NOTREACHED();
327 return; 357 return;
328 } 358 }
329 359
330 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 360 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
331 // Ensure that the distribution supports creating shortcuts. If it doesn't, 361 // Ensure that the distribution supports creating shortcuts. If it doesn't,
332 // the following code may result in NOTREACHED() being hit. 362 // the following code may result in NOTREACHED() being hit.
333 DCHECK(distribution->CanCreateDesktopShortcuts()); 363 DCHECK(distribution->CanCreateDesktopShortcuts());
(...skipping 13 matching lines...) Expand all
347 installer::Product product(distribution); 377 installer::Product product(distribution);
348 product.AddDefaultShortcutProperties(chrome_exe, &properties); 378 product.AddDefaultShortcutProperties(chrome_exe, &properties);
349 379
350 const string16 command_line = 380 const string16 command_line =
351 profiles::internal::CreateProfileShortcutFlags(profile_path); 381 profiles::internal::CreateProfileShortcutFlags(profile_path);
352 382
353 // Only set the profile-specific properties when |profile_name| is non empty. 383 // 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, 384 // If it is empty, it means the shortcut being created should be a regular,
355 // non-profile Chrome shortcut. 385 // non-profile Chrome shortcut.
356 if (!profile_name.empty()) { 386 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()) 387 if (!shortcut_icon.empty())
362 properties.set_icon(shortcut_icon, 0); 388 properties.set_icon(shortcut_icon, 0);
363 properties.set_arguments(command_line); 389 properties.set_arguments(command_line);
364 } else { 390 } else {
365 // Set the arguments explicitly to the empty string to ensure that 391 // Set the arguments explicitly to the empty string to ensure that
366 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut. 392 // |ShellUtil::CreateOrUpdateShortcut| updates that part of the shortcut.
367 properties.set_arguments(string16()); 393 properties.set_arguments(string16());
368 } 394 }
369 395
370 ShellUtil::ShortcutOperation operation = 396 ShellUtil::ShortcutOperation operation =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 for (base::FilePath path = enumerator.Next(); !path.empty(); 430 for (base::FilePath path = enumerator.Next(); !path.empty();
405 path = enumerator.Next()) { 431 path = enumerator.Next()) {
406 if (IsChromeShortcut(path, chrome_exe, NULL)) 432 if (IsChromeShortcut(path, chrome_exe, NULL))
407 return true; 433 return true;
408 } 434 }
409 435
410 return false; 436 return false;
411 } 437 }
412 438
413 // Deletes all desktop shortcuts for the specified profile and also removes the 439 // Deletes all desktop shortcuts for the specified profile and also removes the
414 // corresponding icon file. If |ensure_shortcuts_remain| is true, then a regular 440 // corresponding icon file. If |ensure_shortcuts_remain| is true, then a regular
Alexei Svitkine (slow) 2013/05/03 17:20:47 Update this comment.
calamity 2013/05/08 08:15:42 Done.
415 // non-profile shortcut will be created if this function would otherwise delete 441 // non-profile shortcut will be created if this function would otherwise delete
416 // the last Chrome desktop shortcut(s). Must be called on the FILE thread. 442 // the last Chrome desktop shortcut(s). Must be called on the FILE thread.
417 void DeleteDesktopShortcutsAndIconFile(const base::FilePath& profile_path, 443 void DeleteDesktopShortcuts(const base::FilePath& profile_path,
418 bool ensure_shortcuts_remain) { 444 bool ensure_shortcuts_remain) {
gab 2013/05/07 12:38:39 nit: Indent.
calamity 2013/05/08 08:15:42 Done.
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
420 446
421 base::FilePath chrome_exe; 447 base::FilePath chrome_exe;
422 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 448 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
423 NOTREACHED(); 449 NOTREACHED();
424 return; 450 return;
425 } 451 }
426 452
427 const string16 command_line = 453 const string16 command_line =
428 profiles::internal::CreateProfileShortcutFlags(profile_path); 454 profiles::internal::CreateProfileShortcutFlags(profile_path);
429 std::vector<base::FilePath> shortcuts; 455 std::vector<base::FilePath> shortcuts;
430 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, 456 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false,
431 &shortcuts); 457 &shortcuts);
432 458
433 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 459 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
434 for (size_t i = 0; i < shortcuts.size(); ++i) { 460 for (size_t i = 0; i < shortcuts.size(); ++i) {
435 // Use file_util::Delete() instead of ShellUtil::RemoveShortcut(), as the 461 // Use file_util::Delete() instead of ShellUtil::RemoveShortcut(), as the
436 // latter causes non-profile taskbar shortcuts to be unpinned. 462 // latter causes non-profile taskbar shortcuts to be unpinned.
437 file_util::Delete(shortcuts[i], false); 463 file_util::Delete(shortcuts[i], false);
438 // Notify the shell that the shortcut was deleted to ensure desktop refresh. 464 // Notify the shell that the shortcut was deleted to ensure desktop refresh.
439 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), 465 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(),
440 NULL); 466 NULL);
441 } 467 }
442 468
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 469 // 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. 470 // last shortcuts to be removed, re-create a regular non-profile shortcut.
449 const bool had_shortcuts = !shortcuts.empty(); 471 const bool had_shortcuts = !shortcuts.empty();
450 if (ensure_shortcuts_remain && had_shortcuts && 472 if (ensure_shortcuts_remain && had_shortcuts &&
451 !ChromeDesktopShortcutsExist(chrome_exe)) { 473 !ChromeDesktopShortcutsExist(chrome_exe)) {
452 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 474 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
453 // Ensure that the distribution supports creating shortcuts. If it doesn't, 475 // Ensure that the distribution supports creating shortcuts. If it doesn't,
454 // the following code may result in NOTREACHED() being hit. 476 // the following code may result in NOTREACHED() being hit.
455 DCHECK(distribution->CanCreateDesktopShortcuts()); 477 DCHECK(distribution->CanCreateDesktopShortcuts());
456 installer::Product product(distribution); 478 installer::Product product(distribution);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 SkBitmap bitmap_copy; 540 SkBitmap bitmap_copy;
519 image_bitmap->deepCopyTo(&bitmap_copy, image_bitmap->getConfig()); 541 image_bitmap->deepCopyTo(&bitmap_copy, image_bitmap->getConfig());
520 return bitmap_copy; 542 return bitmap_copy;
521 } 543 }
522 544
523 } // namespace 545 } // namespace
524 546
525 namespace profiles { 547 namespace profiles {
526 namespace internal { 548 namespace internal {
527 549
550 base::FilePath GetProfileIconPath(const base::FilePath& profile_path) {
551 return profile_path.AppendASCII(profiles::internal::kProfileIconFileName);
gab 2013/05/07 12:38:39 nit: Remove profiles::internal:: namespace as this
calamity 2013/05/08 08:15:42 Done.
552 }
553
528 const char kProfileIconFileName[] = "Google Profile.ico"; 554 const char kProfileIconFileName[] = "Google Profile.ico";
gab 2013/05/07 12:38:39 nit: constants should remain at the top of the nam
calamity 2013/05/08 08:15:42 Done.
529 555
530 string16 GetShortcutFilenameForProfile(const string16& profile_name, 556 string16 GetShortcutFilenameForProfile(const string16& profile_name,
531 BrowserDistribution* distribution) { 557 BrowserDistribution* distribution) {
532 string16 shortcut_name; 558 string16 shortcut_name;
533 if (!profile_name.empty()) { 559 if (!profile_name.empty()) {
534 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name)); 560 shortcut_name.append(SanitizeShortcutProfileNameString(profile_name));
535 shortcut_name.append(L" - "); 561 shortcut_name.append(L" - ");
536 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 562 shortcut_name.append(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
537 } else { 563 } else {
538 shortcut_name.append(distribution->GetAppShortCutName()); 564 shortcut_name.append(distribution->GetAppShortCutName());
(...skipping 29 matching lines...) Expand all
568 arraysize(kProfileAvatarIconResources2x), 594 arraysize(kProfileAvatarIconResources2x),
569 profile_manager_->GetProfileInfoCache().GetDefaultAvatarIconCount()); 595 profile_manager_->GetProfileInfoCache().GetDefaultAvatarIconCount());
570 596
571 profile_manager_->GetProfileInfoCache().AddObserver(this); 597 profile_manager_->GetProfileInfoCache().AddObserver(this);
572 } 598 }
573 599
574 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { 600 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() {
575 profile_manager_->GetProfileInfoCache().RemoveObserver(this); 601 profile_manager_->GetProfileInfoCache().RemoveObserver(this);
576 } 602 }
577 603
604 void ProfileShortcutManagerWin::CreateProfileIcon(
605 const base::FilePath& profile_path) {
606 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY,
607 IGNORE_NON_PROFILE_SHORTCUTS);
608 }
609
578 void ProfileShortcutManagerWin::CreateProfileShortcut( 610 void ProfileShortcutManagerWin::CreateProfileShortcut(
579 const base::FilePath& profile_path) { 611 const base::FilePath& profile_path) {
580 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, 612 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND,
581 IGNORE_NON_PROFILE_SHORTCUTS); 613 IGNORE_NON_PROFILE_SHORTCUTS);
582 } 614 }
583 615
584 void ProfileShortcutManagerWin::RemoveProfileShortcuts( 616 void ProfileShortcutManagerWin::RemoveProfileShortcuts(
585 const base::FilePath& profile_path) { 617 const base::FilePath& profile_path) {
586 BrowserThread::PostTask( 618 BrowserThread::PostTask(
587 BrowserThread::FILE, FROM_HERE, 619 BrowserThread::FILE, FROM_HERE,
588 base::Bind(&DeleteDesktopShortcutsAndIconFile, profile_path, false)); 620 base::Bind(&DeleteDesktopShortcuts, profile_path, false));
589 } 621 }
590 622
591 void ProfileShortcutManagerWin::HasProfileShortcuts( 623 void ProfileShortcutManagerWin::HasProfileShortcuts(
592 const base::FilePath& profile_path, 624 const base::FilePath& profile_path,
593 const base::Callback<void(bool)>& callback) { 625 const base::Callback<void(bool)>& callback) {
594 BrowserThread::PostTaskAndReplyWithResult( 626 BrowserThread::PostTaskAndReplyWithResult(
595 BrowserThread::FILE, FROM_HERE, 627 BrowserThread::FILE, FROM_HERE,
596 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); 628 base::Bind(&HasAnyProfileShortcuts, profile_path), callback);
597 } 629 }
598 630
599 void ProfileShortcutManagerWin::OnProfileAdded( 631 void ProfileShortcutManagerWin::OnProfileAdded(
600 const base::FilePath& profile_path) { 632 const base::FilePath& profile_path) {
601 const size_t profile_count = 633 const size_t profile_count =
602 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); 634 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles();
603 if (profile_count == 1) { 635 if (profile_count == 1) {
604 CreateOrUpdateShortcutsForProfileAtPath(profile_path, 636 CreateOrUpdateShortcutsForProfileAtPath(profile_path,
605 CREATE_WHEN_NONE_FOUND, 637 CREATE_WHEN_NONE_FOUND,
606 UPDATE_NON_PROFILE_SHORTCUTS); 638 UPDATE_NON_PROFILE_SHORTCUTS);
607 } else if (profile_count == 2) { 639 } else {
608 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), 640 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY,
609 UPDATE_EXISTING_ONLY, 641 IGNORE_NON_PROFILE_SHORTCUTS);
610 UPDATE_NON_PROFILE_SHORTCUTS); 642 if (profile_count == 2) {
643 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path),
644 UPDATE_EXISTING_ONLY,
645 UPDATE_NON_PROFILE_SHORTCUTS);
646 }
611 } 647 }
612 } 648 }
613 649
614 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( 650 void ProfileShortcutManagerWin::OnProfileWillBeRemoved(
615 const base::FilePath& profile_path) { 651 const base::FilePath& profile_path) {
616 } 652 }
617 653
618 void ProfileShortcutManagerWin::OnProfileWasRemoved( 654 void ProfileShortcutManagerWin::OnProfileWasRemoved(
619 const base::FilePath& profile_path, 655 const base::FilePath& profile_path,
620 const string16& profile_name) { 656 const string16& profile_name) {
621 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 657 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
622 // If there is only one profile remaining, remove the badging information 658 // If there is only one profile remaining, remove the badging information
623 // from an existing shortcut. 659 // from an existing shortcut.
624 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1); 660 const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1);
625 if (deleting_down_to_last_profile) { 661 if (deleting_down_to_last_profile) {
626 CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), 662 // This is needed to unbadge the icon.
663 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(0);
664 CreateOrUpdateShortcutsForProfileAtPath(profile_path,
gab 2013/05/07 12:38:39 Why was this un-inlined? |profile_path| only seems
calamity 2013/05/08 08:15:42 Done.
627 UPDATE_EXISTING_ONLY, 665 UPDATE_EXISTING_ONLY,
628 IGNORE_NON_PROFILE_SHORTCUTS); 666 IGNORE_NON_PROFILE_SHORTCUTS);
629 } 667 }
630 668
631 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 669 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
632 base::Bind(&DeleteDesktopShortcutsAndIconFile, 670 base::Bind(&DeleteDesktopShortcuts,
633 profile_path, 671 profile_path,
634 deleting_down_to_last_profile)); 672 deleting_down_to_last_profile));
635 } 673 }
636 674
637 void ProfileShortcutManagerWin::OnProfileNameChanged( 675 void ProfileShortcutManagerWin::OnProfileNameChanged(
638 const base::FilePath& profile_path, 676 const base::FilePath& profile_path,
639 const string16& old_profile_name) { 677 const string16& old_profile_name) {
640 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, 678 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY,
641 IGNORE_NON_PROFILE_SHORTCUTS); 679 IGNORE_NON_PROFILE_SHORTCUTS);
642 } 680 }
643 681
644 void ProfileShortcutManagerWin::OnProfileAvatarChanged( 682 void ProfileShortcutManagerWin::OnProfileAvatarChanged(
645 const base::FilePath& profile_path) { 683 const base::FilePath& profile_path) {
646 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, 684 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_ICON_ONLY,
gab 2013/05/07 12:38:39 Should still update the desktop shortcut or will u
calamity 2013/05/08 08:15:42 Updating and notifying refreshes the shortcut.
647 IGNORE_NON_PROFILE_SHORTCUTS); 685 IGNORE_NON_PROFILE_SHORTCUTS);
648 } 686 }
649 687
650 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath( 688 base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath(
651 const base::FilePath& profile_path) { 689 const base::FilePath& profile_path) {
652 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 690 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
653 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); 691 DCHECK_EQ(2U, cache.GetNumberOfProfiles());
654 // Get the index of the current profile, in order to find the index of the 692 // Get the index of the current profile, in order to find the index of the
655 // other profile. 693 // other profile.
656 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); 694 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 = 730 const int resource_id_1x =
693 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index); 731 cache->GetDefaultAvatarIconResourceIDAtIndex(icon_index);
694 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index]; 732 const int resource_id_2x = kProfileAvatarIconResources2x[icon_index];
695 // Make a copy of the SkBitmaps to ensure that we can safely use the image 733 // Make a copy of the SkBitmaps to ensure that we can safely use the image
696 // data on the FILE thread. 734 // data on the FILE thread.
697 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x); 735 avatar_bitmap_copy_1x = GetImageResourceSkBitmapCopy(resource_id_1x);
698 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x); 736 avatar_bitmap_copy_2x = GetImageResourceSkBitmapCopy(resource_id_2x);
699 } 737 }
700 BrowserThread::PostTask( 738 BrowserThread::PostTask(
701 BrowserThread::FILE, FROM_HERE, 739 BrowserThread::FILE, FROM_HERE,
702 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, 740 base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, profile_path,
703 old_shortcut_appended_name, new_shortcut_appended_name, 741 old_shortcut_appended_name, new_shortcut_appended_name,
704 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, 742 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode,
705 action)); 743 action));
706 744
707 cache->SetShortcutNameOfProfileAtIndex(profile_index, 745 cache->SetShortcutNameOfProfileAtIndex(profile_index,
708 new_shortcut_appended_name); 746 new_shortcut_appended_name);
709 } 747 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698