| Index: chrome/browser/profiles/profile_manager.cc
|
| diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
|
| index 2735519ad44c3de93ba549f0c84a1cfce7d33e00..19959bcc3e3b1754bb361916add453131ce1c542 100644
|
| --- a/chrome/browser/profiles/profile_manager.cc
|
| +++ b/chrome/browser/profiles/profile_manager.cc
|
| @@ -55,6 +55,7 @@
|
| #include "chrome/browser/signin/signin_manager_factory.h"
|
| #include "chrome/browser/sync/profile_sync_service_factory.h"
|
| #include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/browser_finder.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| #include "chrome/browser/ui/sync/sync_promo_ui.h"
|
| #include "chrome/common/chrome_constants.h"
|
| @@ -323,6 +324,16 @@ void OnProfileLoaded(
|
| client_callback.Run(incognito ? profile->GetOffTheRecordProfile() : profile);
|
| }
|
|
|
| +#if !defined(OS_ANDROID)
|
| +// Helper function for ScheduleForcedEphemeralProfileForDeletion.
|
| +bool IsProfileEphemeral(ProfileAttributesStorage* storage,
|
| + const base::FilePath& profile_dir) {
|
| + ProfileAttributesEntry* entry = nullptr;
|
| + return storage->GetProfileAttributesWithPath(profile_dir, &entry) &&
|
| + entry->IsEphemeral();
|
| +}
|
| +#endif
|
| +
|
| } // namespace
|
|
|
| ProfileManager::ProfileManager(const base::FilePath& user_data_dir)
|
| @@ -1666,8 +1677,8 @@ void ProfileManager::BrowserListObserver::OnBrowserRemoved(
|
| // Do nothing if the profile is already being deleted.
|
| } else if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
|
| // Delete if the profile is an ephemeral profile.
|
| - g_browser_process->profile_manager()->ScheduleProfileForDeletion(
|
| - path, ProfileManager::CreateCallback());
|
| + g_browser_process->profile_manager()
|
| + ->ScheduleForcedEphemeralProfileForDeletion(path);
|
| } else {
|
| #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
|
| // Gather statistics and store into ProfileInfoCache. For incognito profile
|
| @@ -1726,6 +1737,37 @@ void ProfileManager::OnNewActiveProfileLoaded(
|
| if (!original_callback.is_null())
|
| original_callback.Run(loaded_profile, status);
|
| }
|
| +
|
| +void ProfileManager::ScheduleForcedEphemeralProfileForDeletion(
|
| + const base::FilePath& profile_dir) {
|
| + DCHECK_EQ(0u, chrome::GetBrowserCount(GetProfileByPath(profile_dir)));
|
| + DCHECK(IsProfileEphemeral(&GetProfileAttributesStorage(), profile_dir));
|
| +
|
| + // Search for latest active profile, already loaded preferably.
|
| + bool found_entry_loaded = false;
|
| + ProfileAttributesEntry* found_entry = nullptr;
|
| + ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
| + for (ProfileAttributesEntry* entry : storage.GetAllProfilesAttributes()) {
|
| + // Skip all profiles forbidden to rollback.
|
| + base::FilePath entry_path = entry->GetPath();
|
| + if (entry_path == profile_dir ||
|
| + entry_path == GetGuestProfilePath() ||
|
| + entry->IsLegacySupervised() ||
|
| + IsProfileDirectoryMarkedForDeletion(entry_path))
|
| + continue;
|
| + // Check if |entry| preferable over |found_entry|.
|
| + bool entry_loaded = !!GetProfileByPath(entry_path);
|
| + if (!found_entry || (!found_entry_loaded && entry_loaded) ||
|
| + found_entry->GetActiveTime() < entry->GetActiveTime()) {
|
| + found_entry = entry;
|
| + found_entry_loaded = entry_loaded;
|
| + }
|
| + }
|
| +
|
| + const base::FilePath new_active_profile_dir =
|
| + found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath();
|
| + FinishDeletingProfile(profile_dir, new_active_profile_dir);
|
| +}
|
| #endif // !defined(OS_ANDROID)
|
|
|
| ProfileManagerWithoutInit::ProfileManagerWithoutInit(
|
|
|