OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 // place. | 636 // place. |
637 ProfileInfoCache& cache = GetProfileInfoCache(); | 637 ProfileInfoCache& cache = GetProfileInfoCache(); |
638 if (cache.GetNumberOfProfiles() == 1) { | 638 if (cache.GetNumberOfProfiles() == 1) { |
639 FilePath new_path = GenerateNextProfileDirectoryPath(); | 639 FilePath new_path = GenerateNextProfileDirectoryPath(); |
640 | 640 |
641 // The launcher is deleted by the manager when profile creation is finished. | 641 // The launcher is deleted by the manager when profile creation is finished. |
642 NewProfileLauncher* launcher = new NewProfileLauncher(); | 642 NewProfileLauncher* launcher = new NewProfileLauncher(); |
643 CreateProfileAsync(new_path, launcher); | 643 CreateProfileAsync(new_path, launcher); |
644 } | 644 } |
645 | 645 |
| 646 // Update the last used profile pref before closing browser windows. This way |
| 647 // the correct last used profile is set for any notification observers. |
| 648 PrefService* local_state = g_browser_process->local_state(); |
| 649 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); |
| 650 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { |
| 651 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 652 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| 653 if (cur_path != profile_dir) { |
| 654 local_state->SetString( |
| 655 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); |
| 656 break; |
| 657 } |
| 658 } |
| 659 } |
| 660 |
646 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 661 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
647 // start deleting the profile instance we need to close background apps too. | 662 // start deleting the profile instance we need to close background apps too. |
648 Profile* profile = GetProfileByPath(profile_dir); | 663 Profile* profile = GetProfileByPath(profile_dir); |
649 if (profile) | 664 if (profile) |
650 BrowserList::CloseAllBrowsersWithProfile(profile); | 665 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 666 |
651 QueueProfileDirectoryForDeletion(profile_dir); | 667 QueueProfileDirectoryForDeletion(profile_dir); |
652 cache.DeleteProfileFromCache(profile_dir); | 668 cache.DeleteProfileFromCache(profile_dir); |
653 } | 669 } |
654 | 670 |
655 // static | 671 // static |
656 bool ProfileManager::IsMultipleProfilesEnabled() { | 672 bool ProfileManager::IsMultipleProfilesEnabled() { |
657 #if defined(OS_CHROMEOS) | 673 #if defined(OS_CHROMEOS) |
658 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); | 674 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); |
659 #else | 675 #else |
660 return true; | 676 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
677 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 693 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
678 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 694 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
679 } | 695 } |
680 | 696 |
681 void ProfileManager::RegisterTestingProfile(Profile* profile, | 697 void ProfileManager::RegisterTestingProfile(Profile* profile, |
682 bool add_to_cache) { | 698 bool add_to_cache) { |
683 RegisterProfile(profile, true); | 699 RegisterProfile(profile, true); |
684 if (add_to_cache) | 700 if (add_to_cache) |
685 AddProfileToCache(profile); | 701 AddProfileToCache(profile); |
686 } | 702 } |
OLD | NEW |