OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" | 5 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
6 | 6 |
7 #include <shlobj.h> // For SHChangeNotify(). | 7 #include <shlobj.h> // For SHChangeNotify(). |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_enumerator.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/string16.h" | 17 #include "base/string16.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "base/win/shortcut.h" | 21 #include "base/win/shortcut.h" |
21 #include "chrome/browser/app_icon_win.h" | 22 #include "chrome/browser/app_icon_win.h" |
22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 24 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
24 #include "chrome/browser/profiles/profile_info_util.h" | 25 #include "chrome/browser/profiles/profile_info_util.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // the specified |command_line|. If |include_empty_command_lines| is true, | 226 // the specified |command_line|. If |include_empty_command_lines| is true, |
226 // Chrome desktop shortcuts with empty command lines will also be included. | 227 // Chrome desktop shortcuts with empty command lines will also be included. |
227 void ListDesktopShortcutsWithCommandLine(const base::FilePath& chrome_exe, | 228 void ListDesktopShortcutsWithCommandLine(const base::FilePath& chrome_exe, |
228 const string16& command_line, | 229 const string16& command_line, |
229 bool include_empty_command_lines, | 230 bool include_empty_command_lines, |
230 std::vector<base::FilePath>* paths) { | 231 std::vector<base::FilePath>* paths) { |
231 base::FilePath user_shortcuts_directory; | 232 base::FilePath user_shortcuts_directory; |
232 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, NULL)) | 233 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, NULL)) |
233 return; | 234 return; |
234 | 235 |
235 file_util::FileEnumerator enumerator(user_shortcuts_directory, false, | 236 base::FileEnumerator enumerator(user_shortcuts_directory, false, |
236 file_util::FileEnumerator::FILES); | 237 base::FileEnumerator::FILES); |
237 for (base::FilePath path = enumerator.Next(); !path.empty(); | 238 for (base::FilePath path = enumerator.Next(); !path.empty(); |
238 path = enumerator.Next()) { | 239 path = enumerator.Next()) { |
239 string16 shortcut_command_line; | 240 string16 shortcut_command_line; |
240 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line)) | 241 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line)) |
241 continue; | 242 continue; |
242 | 243 |
243 // TODO(asvitkine): Change this to build a CommandLine object and ensure all | 244 // TODO(asvitkine): Change this to build a CommandLine object and ensure all |
244 // args from |command_line| are present in the shortcut's CommandLine. This | 245 // args from |command_line| are present in the shortcut's CommandLine. This |
245 // will be more robust when |command_line| contains multiple args. | 246 // will be more robust when |command_line| contains multiple args. |
246 if ((shortcut_command_line.empty() && include_empty_command_lines) || | 247 if ((shortcut_command_line.empty() && include_empty_command_lines) || |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 393 } |
393 } | 394 } |
394 | 395 |
395 // Returns true if any desktop shortcuts exist with target |chrome_exe|, | 396 // Returns true if any desktop shortcuts exist with target |chrome_exe|, |
396 // regardless of their command line arguments. | 397 // regardless of their command line arguments. |
397 bool ChromeDesktopShortcutsExist(const base::FilePath& chrome_exe) { | 398 bool ChromeDesktopShortcutsExist(const base::FilePath& chrome_exe) { |
398 base::FilePath user_shortcuts_directory; | 399 base::FilePath user_shortcuts_directory; |
399 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, NULL)) | 400 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, NULL)) |
400 return false; | 401 return false; |
401 | 402 |
402 file_util::FileEnumerator enumerator(user_shortcuts_directory, false, | 403 base::FileEnumerator enumerator(user_shortcuts_directory, false, |
403 file_util::FileEnumerator::FILES); | 404 base::FileEnumerator::FILES); |
404 for (base::FilePath path = enumerator.Next(); !path.empty(); | 405 for (base::FilePath path = enumerator.Next(); !path.empty(); |
405 path = enumerator.Next()) { | 406 path = enumerator.Next()) { |
406 if (IsChromeShortcut(path, chrome_exe, NULL)) | 407 if (IsChromeShortcut(path, chrome_exe, NULL)) |
407 return true; | 408 return true; |
408 } | 409 } |
409 | 410 |
410 return false; | 411 return false; |
411 } | 412 } |
412 | 413 |
413 // Deletes all desktop shortcuts for the specified profile and also removes the | 414 // Deletes all desktop shortcuts for the specified profile and also removes the |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 BrowserThread::PostTask( | 701 BrowserThread::PostTask( |
701 BrowserThread::FILE, FROM_HERE, | 702 BrowserThread::FILE, FROM_HERE, |
702 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, | 703 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, profile_path, |
703 old_shortcut_appended_name, new_shortcut_appended_name, | 704 old_shortcut_appended_name, new_shortcut_appended_name, |
704 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, | 705 avatar_bitmap_copy_1x, avatar_bitmap_copy_2x, create_mode, |
705 action)); | 706 action)); |
706 | 707 |
707 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 708 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
708 new_shortcut_appended_name); | 709 new_shortcut_appended_name); |
709 } | 710 } |
OLD | NEW |