Chromium Code Reviews| Index: chrome/browser/profiles/profile_manager.cc |
| diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc |
| index a1ed001fe17b19e9026519dde70ace801855abf0..94df50ed84266932db54b4ef25876a474056e67f 100644 |
| --- a/chrome/browser/profiles/profile_manager.cc |
| +++ b/chrome/browser/profiles/profile_manager.cc |
| @@ -1070,20 +1070,24 @@ void ProfileManager::ScheduleProfileForDeletion( |
| PrefService* local_state = g_browser_process->local_state(); |
| ProfileInfoCache& cache = GetProfileInfoCache(); |
| + |
| if (profile_dir.BaseName().MaybeAsASCII() == |
| local_state->GetString(prefs::kProfileLastUsed)) { |
| // Update the last used profile pref before closing browser windows. This |
| // way the correct last used profile is set for any notification observers. |
| - std::string last_non_managed_profile; |
| + base::FilePath last_non_managed_profile_path; |
| for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { |
| - last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); |
| + last_non_managed_profile_path = cur_path; |
| break; |
| } |
| } |
| + |
| // If we're deleting the last (non-managed) profile, then create a new |
| // profile in its place. |
| + std::string last_non_managed_profile = |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
Nit: Make it const
noms (inactive)
2013/06/11 19:32:17
Done.
|
| + last_non_managed_profile_path.BaseName().MaybeAsASCII(); |
| if (last_non_managed_profile.empty()) { |
| base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
| // Make sure the last used profile path is pointing at it. This way the |
| @@ -1101,10 +1105,50 @@ void ProfileManager::ScheduleProfileForDeletion( |
| string16(), |
| false); |
| } else { |
| + // On the Mac, the browser process is not killed when all browser windows |
| + // are closed, so just in case we are deleting the active profile, and no |
| + // other profile has been loaded, we must pre-load a next one. |
| +#if defined(OS_MACOSX) |
| + CreateProfileAsync(last_non_managed_profile_path, |
| + base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
| + base::Unretained(this), |
| + profile_dir, |
| + last_non_managed_profile, |
| + desktop_type), |
| + string16(), |
| + string16(), |
| + false); |
| + return; |
| +#else |
| + // For OS_MACOSX we will update the local_state in the callback |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
Nit: "update the local_state" -> "update the pref"
noms (inactive)
2013/06/11 19:32:17
Done.
|
| + // to make sure that it isn't used before the profile is actually loaded. |
| local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
| +#endif |
| } |
| } |
| + FinishDeletingProfile(profile_dir); |
| +} |
| + |
| +void ProfileManager::OnNewActiveProfileLoaded(const base::FilePath& profile_dir, |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
This param should be on the next line, aligned wit
noms (inactive)
2013/06/11 19:32:17
Done.
|
| + const std::string last_non_managed_profile, |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
Should be a "const std::string&".
noms (inactive)
2013/06/11 19:32:17
Done.
|
| + chrome::HostDesktopType desktop_type, |
| + Profile* profile, |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
Rename to |loaded_profile|.
noms (inactive)
2013/06/11 19:32:17
Done.
|
| + Profile::CreateStatus status) { |
| + if (status == Profile::CREATE_STATUS_INITIALIZED) { |
| + // Update the local state as promised in the ScheduleProfileForDeletion. |
| + PrefService* local_state = g_browser_process->local_state(); |
| + local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
| + FinishDeletingProfile(profile_dir); |
| + } else if (status == Profile::CREATE_STATUS_FAIL) { |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
Hmm, I see CREATE_STATUS_LOCAL_FAIL and CREATE_STA
noms (inactive)
2013/06/11 19:32:17
And how!
On 2013/06/05 20:00:52, Alexei Svitkine
|
| + // If we are here, it means that the profile we tried to load as the |
|
Alexei Svitkine (slow)
2013/06/05 20:00:52
Nit: No "we"'s
noms (inactive)
2013/06/11 19:32:17
Done.
|
| + // next active profile has been deleted. We should retry to delete |
| + // this profile to redo the logic and load the next available profile. |
| + ScheduleProfileForDeletion(profile_dir, desktop_type); |
| + } |
| +} |
| +void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { |
| + ProfileInfoCache& cache = GetProfileInfoCache(); |
| // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
| // start deleting the profile instance we need to close background apps too. |
| Profile* profile = GetProfileByPath(profile_dir); |