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