| Index: chrome/browser/profiles/profile_manager.cc
|
| diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
|
| index 3a69b5e042999d0a461ac0d6f890292d44b5057f..cd6e4ee7655803fa819d876fdbade162bf68855e 100644
|
| --- a/chrome/browser/profiles/profile_manager.cc
|
| +++ b/chrome/browser/profiles/profile_manager.cc
|
| @@ -1313,10 +1313,31 @@ Profile* ProfileManager::CreateAndInitializeProfile(
|
| #if !defined(OS_ANDROID)
|
| void ProfileManager::EnsureActiveProfileExistsBeforeDeletion(
|
| const CreateCallback& callback, const base::FilePath& profile_dir) {
|
| + // In case we delete non-active profile, just proceed.
|
| + const base::FilePath last_used_profile =
|
| + GetLastUsedProfileDir(user_data_dir_);
|
| + if (last_used_profile != profile_dir &&
|
| + last_used_profile != GetGuestProfilePath()) {
|
| + FinishDeletingProfile(profile_dir, last_used_profile);
|
| + return;
|
| + }
|
| +
|
| + // Search for an active browser and use its profile as active if possible.
|
| + for (Browser* browser : *BrowserList::GetInstance()) {
|
| + Profile* profile = browser->profile();
|
| + base::FilePath cur_path = profile->GetPath();
|
| + if (cur_path != profile_dir &&
|
| + !profile->IsLegacySupervised() &&
|
| + !IsProfileDirectoryMarkedForDeletion(cur_path)) {
|
| + OnNewActiveProfileLoaded(profile_dir, cur_path, callback, profile,
|
| + Profile::CREATE_STATUS_INITIALIZED);
|
| + return;
|
| + }
|
| + }
|
| +
|
| + // There no valid browsers to fallback, search for any existing valid profile.
|
| ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
| - // If we're deleting the last (non-legacy-supervised) profile, then create a
|
| - // new profile in its place.
|
| - base::FilePath last_non_supervised_profile_path;
|
| + base::FilePath fallback_profile_path;
|
| std::vector<ProfileAttributesEntry*> entries =
|
| storage.GetAllProfilesAttributes();
|
| for (ProfileAttributesEntry* entry : entries) {
|
| @@ -1326,59 +1347,33 @@ void ProfileManager::EnsureActiveProfileExistsBeforeDeletion(
|
| if (cur_path != profile_dir &&
|
| !entry->IsLegacySupervised() &&
|
| !IsProfileDirectoryMarkedForDeletion(cur_path)) {
|
| - last_non_supervised_profile_path = cur_path;
|
| + fallback_profile_path = cur_path;
|
| break;
|
| }
|
| }
|
|
|
| - if (last_non_supervised_profile_path.empty()) {
|
| - std::string new_avatar_url;
|
| - base::string16 new_profile_name;
|
| -
|
| -#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
|
| + // If we're deleting the last (non-legacy-supervised) profile, then create a
|
| + // new profile in its place. Load existing profile otherwise.
|
| + std::string new_avatar_url;
|
| + base::string16 new_profile_name;
|
| + if (fallback_profile_path.empty()) {
|
| + fallback_profile_path = GenerateNextProfileDirectoryPath();
|
| +#if !defined(OS_CHROMEOS)
|
| int avatar_index = profiles::GetPlaceholderAvatarIndex();
|
| new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index);
|
| new_profile_name = storage.ChooseNameForNewProfile(avatar_index);
|
| #endif
|
| -
|
| - base::FilePath new_path(GenerateNextProfileDirectoryPath());
|
| - CreateProfileAsync(new_path,
|
| - base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
|
| - base::Unretained(this),
|
| - profile_dir,
|
| - new_path,
|
| - callback),
|
| - new_profile_name,
|
| - new_avatar_url,
|
| - std::string());
|
| -
|
| + // A new profile about to be created.
|
| ProfileMetrics::LogProfileAddNewUser(
|
| ProfileMetrics::ADD_NEW_USER_LAST_DELETED);
|
| - return;
|
| - }
|
| -
|
| -#if defined(OS_MACOSX)
|
| - // 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.
|
| - const base::FilePath last_used_profile =
|
| - GetLastUsedProfileDir(user_data_dir_);
|
| - if (last_used_profile == profile_dir ||
|
| - last_used_profile == GetGuestProfilePath()) {
|
| - CreateProfileAsync(last_non_supervised_profile_path,
|
| - base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
|
| - base::Unretained(this),
|
| - profile_dir,
|
| - last_non_supervised_profile_path,
|
| - callback),
|
| - base::string16(),
|
| - std::string(),
|
| - std::string());
|
| - return;
|
| }
|
| -#endif // defined(OS_MACOSX)
|
|
|
| - FinishDeletingProfile(profile_dir, last_non_supervised_profile_path);
|
| + // Create and/or load fallback profile.
|
| + CreateProfileAsync(fallback_profile_path,
|
| + base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
|
| + base::Unretained(this), profile_dir,
|
| + fallback_profile_path, callback),
|
| + new_profile_name, new_avatar_url, std::string());
|
| }
|
|
|
| void ProfileManager::FinishDeletingProfile(
|
|
|