| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 product.AddDefaultShortcutProperties(chrome_exe, &properties); | 339 product.AddDefaultShortcutProperties(chrome_exe, &properties); |
| 340 properties.set_shortcut_name( | 340 properties.set_shortcut_name( |
| 341 profiles::internal::GetShortcutFilenameForProfile(string16(), | 341 profiles::internal::GetShortcutFilenameForProfile(string16(), |
| 342 distribution)); | 342 distribution)); |
| 343 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 343 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 344 distribution, properties, | 344 distribution, properties, |
| 345 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS); | 345 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 // Returns true if profile at |profile_path| has any shortcuts. Does not |
| 350 // consider non-profile shortcuts. Must be called on the FILE thread. |
| 351 bool HasAnyProfileShortcuts(const FilePath& profile_path) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 353 |
| 354 FilePath chrome_exe; |
| 355 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 356 NOTREACHED(); |
| 357 return false; |
| 358 } |
| 359 |
| 360 const string16 command_line = |
| 361 profiles::internal::CreateProfileShortcutFlags(profile_path); |
| 362 std::vector<FilePath> shortcuts; |
| 363 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false, |
| 364 &shortcuts); |
| 365 return !shortcuts.empty(); |
| 366 } |
| 367 |
| 349 // Replaces any reserved characters with spaces, and trims the resulting string | 368 // Replaces any reserved characters with spaces, and trims the resulting string |
| 350 // to prevent any leading and trailing spaces. Also makes sure that the | 369 // to prevent any leading and trailing spaces. Also makes sure that the |
| 351 // resulting filename doesn't exceed |kMaxProfileShortcutFileNameLength|. | 370 // resulting filename doesn't exceed |kMaxProfileShortcutFileNameLength|. |
| 352 // TODO(macourteau): find a way to limit the total path's length to MAX_PATH | 371 // TODO(macourteau): find a way to limit the total path's length to MAX_PATH |
| 353 // instead of limiting the profile's name to |kMaxProfileShortcutFileNameLength| | 372 // instead of limiting the profile's name to |kMaxProfileShortcutFileNameLength| |
| 354 // characters. | 373 // characters. |
| 355 string16 SanitizeShortcutProfileNameString(const string16& profile_name) { | 374 string16 SanitizeShortcutProfileNameString(const string16& profile_name) { |
| 356 string16 sanitized = profile_name; | 375 string16 sanitized = profile_name; |
| 357 size_t pos = sanitized.find_first_of(kReservedCharacters); | 376 size_t pos = sanitized.find_first_of(kReservedCharacters); |
| 358 while (pos != string16::npos) { | 377 while (pos != string16::npos) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { | 433 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { |
| 415 profile_manager_->GetProfileInfoCache().RemoveObserver(this); | 434 profile_manager_->GetProfileInfoCache().RemoveObserver(this); |
| 416 } | 435 } |
| 417 | 436 |
| 418 void ProfileShortcutManagerWin::CreateProfileShortcut( | 437 void ProfileShortcutManagerWin::CreateProfileShortcut( |
| 419 const FilePath& profile_path) { | 438 const FilePath& profile_path) { |
| 420 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, | 439 CreateOrUpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND, |
| 421 IGNORE_NON_PROFILE_SHORTCUTS); | 440 IGNORE_NON_PROFILE_SHORTCUTS); |
| 422 } | 441 } |
| 423 | 442 |
| 443 void ProfileShortcutManagerWin::RemoveProfileShortcuts( |
| 444 const FilePath& profile_path) { |
| 445 BrowserThread::PostTask( |
| 446 BrowserThread::FILE, FROM_HERE, |
| 447 base::Bind(&DeleteDesktopShortcutsAndIconFile, profile_path, false)); |
| 448 } |
| 449 |
| 450 void ProfileShortcutManagerWin::HasProfileShortcuts( |
| 451 const FilePath& profile_path, |
| 452 const base::Callback<void(bool)>& callback) { |
| 453 BrowserThread::PostTaskAndReplyWithResult( |
| 454 BrowserThread::FILE, FROM_HERE, |
| 455 base::Bind(&HasAnyProfileShortcuts, profile_path), callback); |
| 456 } |
| 457 |
| 424 void ProfileShortcutManagerWin::OnProfileAdded(const FilePath& profile_path) { | 458 void ProfileShortcutManagerWin::OnProfileAdded(const FilePath& profile_path) { |
| 425 const size_t profile_count = | 459 const size_t profile_count = |
| 426 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); | 460 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); |
| 427 if (profile_count == 1) { | 461 if (profile_count == 1) { |
| 428 CreateOrUpdateShortcutsForProfileAtPath(profile_path, | 462 CreateOrUpdateShortcutsForProfileAtPath(profile_path, |
| 429 CREATE_WHEN_NONE_FOUND, | 463 CREATE_WHEN_NONE_FOUND, |
| 430 UPDATE_NON_PROFILE_SHORTCUTS); | 464 UPDATE_NON_PROFILE_SHORTCUTS); |
| 431 } else if (profile_count == 2) { | 465 } else if (profile_count == 2) { |
| 432 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), | 466 CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), |
| 433 UPDATE_EXISTING_ONLY, | 467 UPDATE_EXISTING_ONLY, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 582 } |
| 549 BrowserThread::PostTask( | 583 BrowserThread::PostTask( |
| 550 BrowserThread::FILE, FROM_HERE, | 584 BrowserThread::FILE, FROM_HERE, |
| 551 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, | 585 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, |
| 552 profile_path, new_shortcut_appended_name, | 586 profile_path, new_shortcut_appended_name, |
| 553 profile_avatar_bitmap_copy, create_mode, action)); | 587 profile_avatar_bitmap_copy, create_mode, action)); |
| 554 | 588 |
| 555 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 589 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
| 556 new_shortcut_appended_name); | 590 new_shortcut_appended_name); |
| 557 } | 591 } |
| OLD | NEW |