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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 user_shortcuts_directory.Append(old_shortcut_filename); | 285 user_shortcuts_directory.Append(old_shortcut_filename); |
286 const base::FilePath new_shortcut_path = | 286 const base::FilePath new_shortcut_path = |
287 user_shortcuts_directory.Append(new_shortcut_filename); | 287 user_shortcuts_directory.Append(new_shortcut_filename); |
288 | 288 |
289 if (base::PathExists(old_shortcut_path)) { | 289 if (base::PathExists(old_shortcut_path)) { |
290 // Rename the old shortcut unless a system-level shortcut exists at the | 290 // Rename the old shortcut unless a system-level shortcut exists at the |
291 // destination, in which case the old shortcut is simply deleted. | 291 // destination, in which case the old shortcut is simply deleted. |
292 const base::FilePath possible_new_system_shortcut = | 292 const base::FilePath possible_new_system_shortcut = |
293 system_shortcuts_directory.Append(new_shortcut_filename); | 293 system_shortcuts_directory.Append(new_shortcut_filename); |
294 if (base::PathExists(possible_new_system_shortcut)) | 294 if (base::PathExists(possible_new_system_shortcut)) |
295 base::Delete(old_shortcut_path, false); | 295 base::DeleteFile(old_shortcut_path, false); |
296 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) | 296 else if (!RenameDesktopShortcut(old_shortcut_path, new_shortcut_path)) |
297 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 297 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
298 } else { | 298 } else { |
299 // If the shortcut does not exist, it may have been renamed by the user. In | 299 // If the shortcut does not exist, it may have been renamed by the user. In |
300 // that case, its name should not be changed. | 300 // that case, its name should not be changed. |
301 // It's also possible that a system-level shortcut exists instead - this | 301 // 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 | 302 // 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 | 303 // installation. If that's the case, copy that one over - it will get its |
304 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. | 304 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. |
305 const base::FilePath possible_old_system_shortcut = | 305 const base::FilePath possible_old_system_shortcut = |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 } | 430 } |
431 | 431 |
432 const string16 command_line = | 432 const string16 command_line = |
433 profiles::internal::CreateProfileShortcutFlags(profile_path); | 433 profiles::internal::CreateProfileShortcutFlags(profile_path); |
434 std::vector<base::FilePath> shortcuts; | 434 std::vector<base::FilePath> shortcuts; |
435 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, | 435 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, |
436 &shortcuts); | 436 &shortcuts); |
437 | 437 |
438 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 438 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
439 for (size_t i = 0; i < shortcuts.size(); ++i) { | 439 for (size_t i = 0; i < shortcuts.size(); ++i) { |
440 // Use base::Delete() instead of ShellUtil::RemoveShortcut(), as the | 440 // Use base::DeleteFile() instead of ShellUtil::RemoveShortcut(), as the |
441 // latter causes non-profile taskbar shortcuts to be unpinned. | 441 // latter causes non-profile taskbar shortcuts to be unpinned. |
442 base::Delete(shortcuts[i], false); | 442 base::DeleteFile(shortcuts[i], false); |
443 // Notify the shell that the shortcut was deleted to ensure desktop refresh. | 443 // Notify the shell that the shortcut was deleted to ensure desktop refresh. |
444 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), | 444 SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, shortcuts[i].value().c_str(), |
445 NULL); | 445 NULL); |
446 } | 446 } |
447 | 447 |
448 const base::FilePath icon_path = | 448 const base::FilePath icon_path = |
449 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); | 449 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); |
450 base::Delete(icon_path, false); | 450 base::DeleteFile(icon_path, false); |
451 | 451 |
452 // If |ensure_shortcuts_remain| is true and deleting this profile caused the | 452 // 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. | 453 // last shortcuts to be removed, re-create a regular non-profile shortcut. |
454 const bool had_shortcuts = !shortcuts.empty(); | 454 const bool had_shortcuts = !shortcuts.empty(); |
455 if (ensure_shortcuts_remain && had_shortcuts && | 455 if (ensure_shortcuts_remain && had_shortcuts && |
456 !ChromeDesktopShortcutsExist(chrome_exe)) { | 456 !ChromeDesktopShortcutsExist(chrome_exe)) { |
457 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 457 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
458 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 458 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
459 // the following code may result in NOTREACHED() being hit. | 459 // the following code may result in NOTREACHED() being hit. |
460 DCHECK(distribution->CanCreateDesktopShortcuts()); | 460 DCHECK(distribution->CanCreateDesktopShortcuts()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 BrowserThread::PostTask( | 696 BrowserThread::PostTask( |
697 BrowserThread::FILE, FROM_HERE, | 697 BrowserThread::FILE, FROM_HERE, |
698 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, | 698 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, |
699 old_shortcut_appended_name, new_shortcut_appended_name, | 699 old_shortcut_appended_name, new_shortcut_appended_name, |
700 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, | 700 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, |
701 action)); | 701 action)); |
702 | 702 |
703 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 703 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
704 new_shortcut_appended_name); | 704 new_shortcut_appended_name); |
705 } | 705 } |
OLD | NEW |