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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 (shortcut_command_line.find(command_line) != string16::npos)) { | 179 (shortcut_command_line.find(command_line) != string16::npos)) { |
180 paths->push_back(path); | 180 paths->push_back(path); |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 // Renames an existing Chrome desktop profile shortcut. Must be called on the | 185 // Renames an existing Chrome desktop profile shortcut. Must be called on the |
186 // FILE thread. | 186 // FILE thread. |
187 void RenameChromeDesktopShortcutForProfile( | 187 void RenameChromeDesktopShortcutForProfile( |
188 const string16& old_shortcut_file, | 188 const string16& old_shortcut_file, |
189 const string16& new_shortcut_file) { | 189 const string16& new_shortcut_file) { |
gab
2013/01/14 21:49:30
optional nit: Rename these parameters to old_short
Alexei Svitkine (slow)
2013/01/15 22:03:02
Done.
sail
2013/01/15 22:12:15
Didn't see this change. I'm guessing you're doing
Alexei Svitkine (slow)
2013/01/15 22:18:34
It should be there, take a closer look at: https:/
sail
2013/01/15 22:21:36
Oops, I was thinking of the test member variable r
| |
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
191 | 191 |
192 FilePath shortcuts_directory; | 192 FilePath shortcuts_directory; |
193 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) | 193 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) |
194 return; | 194 return; |
195 | 195 |
196 FilePath old_shortcut_path = shortcuts_directory.Append(old_shortcut_file); | 196 FilePath old_shortcut_path = shortcuts_directory.Append(old_shortcut_file); |
197 // If the shortcut does not exist, it may have been renamed by the user. In | 197 // If the shortcut does not exist, it may have been renamed by the user. In |
198 // that case, its name should not be changed. | 198 // that case, its name should not be changed. |
199 if (!file_util::PathExists(old_shortcut_path)) | 199 if (!file_util::PathExists(old_shortcut_path)) |
200 return; | 200 return; |
201 | 201 |
202 // If a system shortcut exists at the destination, then simply delete the | |
203 // old shortcut. | |
204 FilePath system_shortcuts_directory; | |
205 DCHECK(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | |
gab
2013/01/14 21:49:30
Take the call out of the DCHECK, store the result
Alexei Svitkine (slow)
2013/01/15 22:03:02
Doh, thanks for catching this. Fixed.
| |
206 BrowserDistribution::GetDistribution(), | |
207 ShellUtil::SYSTEM_LEVEL, | |
208 &system_shortcuts_directory)); | |
209 const FilePath possible_system_shortcut = | |
sail
2013/01/14 21:45:19
new_system_shortcut_path
Alexei Svitkine (slow)
2013/01/15 22:03:02
I've changed it to |possible_new_system_shortcut|,
| |
210 system_shortcuts_directory.Append(new_shortcut_file); | |
211 if (file_util::PathExists(possible_system_shortcut)) { | |
212 file_util::Delete(old_shortcut_path, false); | |
213 return; | |
214 } | |
215 | |
202 FilePath new_shortcut_path = shortcuts_directory.Append(new_shortcut_file); | 216 FilePath new_shortcut_path = shortcuts_directory.Append(new_shortcut_file); |
sail
2013/01/14 21:45:19
new_user_shortcut_path
Alexei Svitkine (slow)
2013/01/15 22:03:02
All the paths here are assumed to be user paths ex
| |
203 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) | 217 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) |
204 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 218 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
205 } | 219 } |
206 | 220 |
207 // Updates all desktop shortcuts for the given profile to have the specified | 221 // Updates all desktop shortcuts for the given profile to have the specified |
208 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is | 222 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is |
209 // created if no existing ones were found. Whether non-profile shortcuts should | 223 // created if no existing ones were found. Whether non-profile shortcuts should |
210 // be updated is specified by |action|. Must be called on the FILE thread. | 224 // be updated is specified by |action|. Must be called on the FILE thread. |
211 void CreateOrUpdateDesktopShortcutsForProfile( | 225 void CreateOrUpdateDesktopShortcutsForProfile( |
212 const FilePath& profile_path, | 226 const FilePath& profile_path, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 std::vector<FilePath> shortcuts; | 269 std::vector<FilePath> shortcuts; |
256 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, | 270 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, |
257 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, | 271 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, |
258 &shortcuts); | 272 &shortcuts); |
259 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && | 273 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && |
260 shortcuts.empty()) { | 274 shortcuts.empty()) { |
261 const string16 shortcut_name = | 275 const string16 shortcut_name = |
262 profiles::internal::GetShortcutFilenameForProfile(profile_name, | 276 profiles::internal::GetShortcutFilenameForProfile(profile_name, |
263 distribution); | 277 distribution); |
264 shortcuts.push_back(FilePath(shortcut_name)); | 278 shortcuts.push_back(FilePath(shortcut_name)); |
265 operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; | 279 operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; |
gab
2013/01/14 21:49:30
This will prevent creation of all profile shortcut
Alexei Svitkine (slow)
2013/01/14 22:57:14
Makes sense. Just to clarify, SHELL_SHORTCUT_CREAT
gab
2013/01/14 23:04:42
Ah, you're right, I wrongly assumed it would preve
Alexei Svitkine (slow)
2013/01/15 22:03:02
Done.
| |
266 } | 280 } |
267 | 281 |
268 for (size_t i = 0; i < shortcuts.size(); ++i) { | 282 for (size_t i = 0; i < shortcuts.size(); ++i) { |
269 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension(); | 283 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension(); |
270 properties.set_shortcut_name(shortcut_name.value()); | 284 properties.set_shortcut_name(shortcut_name.value()); |
271 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 285 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
272 distribution, properties, operation); | 286 distribution, properties, operation); |
273 } | 287 } |
274 } | 288 } |
275 | 289 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 347 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
334 // the following code may result in NOTREACHED() being hit. | 348 // the following code may result in NOTREACHED() being hit. |
335 DCHECK(distribution->CanCreateDesktopShortcuts()); | 349 DCHECK(distribution->CanCreateDesktopShortcuts()); |
336 installer::Product product(distribution); | 350 installer::Product product(distribution); |
337 | 351 |
338 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 352 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
339 product.AddDefaultShortcutProperties(chrome_exe, &properties); | 353 product.AddDefaultShortcutProperties(chrome_exe, &properties); |
340 properties.set_shortcut_name( | 354 properties.set_shortcut_name( |
341 profiles::internal::GetShortcutFilenameForProfile(string16(), | 355 profiles::internal::GetShortcutFilenameForProfile(string16(), |
342 distribution)); | 356 distribution)); |
343 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 357 ShellUtil::CreateOrUpdateShortcut( |
344 distribution, properties, | 358 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties, |
345 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS); | 359 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
346 } | 360 } |
347 } | 361 } |
348 | 362 |
349 // Returns true if profile at |profile_path| has any shortcuts. Does not | 363 // Returns true if profile at |profile_path| has any shortcuts. Does not |
350 // consider non-profile shortcuts. Must be called on the FILE thread. | 364 // consider non-profile shortcuts. Must be called on the FILE thread. |
351 bool HasAnyProfileShortcuts(const FilePath& profile_path) { | 365 bool HasAnyProfileShortcuts(const FilePath& profile_path) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
353 | 367 |
354 FilePath chrome_exe; | 368 FilePath chrome_exe; |
355 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 369 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 } | 596 } |
583 BrowserThread::PostTask( | 597 BrowserThread::PostTask( |
584 BrowserThread::FILE, FROM_HERE, | 598 BrowserThread::FILE, FROM_HERE, |
585 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, | 599 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, |
586 profile_path, new_shortcut_appended_name, | 600 profile_path, new_shortcut_appended_name, |
587 profile_avatar_bitmap_copy, create_mode, action)); | 601 profile_avatar_bitmap_copy, create_mode, action)); |
588 | 602 |
589 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 603 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
590 new_shortcut_appended_name); | 604 new_shortcut_appended_name); |
591 } | 605 } |
OLD | NEW |