Improve ephemeral profiles clean up code.

BUG=302461
TEST=No new ones. Existing tests cover this code well enough.

Review URL: https://codereview.chromium.org/50293011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233341 0039d316-1c4b-4281-b951-d872f2087c98
parent b69ac914
...@@ -1045,9 +1045,16 @@ void ChromeBrowserMainParts::PreProfileInit() { ...@@ -1045,9 +1045,16 @@ void ChromeBrowserMainParts::PreProfileInit() {
if (profile_cache.ProfileIsEphemeralAtIndex(i)) if (profile_cache.ProfileIsEphemeralAtIndex(i))
profiles_to_delete.push_back(profile_cache.GetPathOfProfileAtIndex(i)); profiles_to_delete.push_back(profile_cache.GetPathOfProfileAtIndex(i));
} }
for (size_t i = 0;i < profiles_to_delete.size(); ++i) {
profile_manager->ScheduleProfileForDeletion( if (profiles_to_delete.size()) {
profiles_to_delete[i], ProfileManager::CreateCallback()); for (size_t i = 0;i < profiles_to_delete.size(); ++i) {
profile_manager->ScheduleProfileForDeletion(
profiles_to_delete[i], ProfileManager::CreateCallback());
}
// Clean up stale profiles immediately after browser start.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&ProfileManager::CleanUpStaleProfiles, profiles_to_delete));
} }
#endif // OS_ANDROID #endif // OS_ANDROID
......
...@@ -507,6 +507,7 @@ void ProfileImpl::DoFinalInit() { ...@@ -507,6 +507,7 @@ void ProfileImpl::DoFinalInit() {
// kGoogleServicesUsername, initialize components that depend on it to reflect // kGoogleServicesUsername, initialize components that depend on it to reflect
// the current value. // the current value.
UpdateProfileUserNameCache(); UpdateProfileUserNameCache();
UpdateProfileIsEphemeralCache();
GAIAInfoUpdateServiceFactory::GetForProfile(this); GAIAInfoUpdateServiceFactory::GetForProfile(this);
PrefService* local_state = g_browser_process->local_state(); PrefService* local_state = g_browser_process->local_state();
......
...@@ -165,6 +165,15 @@ bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { ...@@ -165,6 +165,15 @@ bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) {
profile_path) != ProfilesToDelete().end(); profile_path) != ProfilesToDelete().end();
} }
// Physically remove deleted profile directories from disk.
void NukeProfileFromDisk(const base::FilePath& profile_path) {
// Delete both the profile directory and its corresponding cache.
base::FilePath cache_path;
chrome::GetUserCacheDirectory(profile_path, &cache_path);
base::DeleteFile(profile_path, true);
base::DeleteFile(cache_path, true);
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status,
bool is_mounted) { bool is_mounted) {
...@@ -198,11 +207,7 @@ void ProfileManager::NukeDeletedProfilesFromDisk() { ...@@ -198,11 +207,7 @@ void ProfileManager::NukeDeletedProfilesFromDisk() {
ProfilesToDelete().begin(); ProfilesToDelete().begin();
it != ProfilesToDelete().end(); it != ProfilesToDelete().end();
++it) { ++it) {
// Delete both the profile directory and its corresponding cache. NukeProfileFromDisk(*it);
base::FilePath cache_path;
chrome::GetUserCacheDirectory(*it, &cache_path);
base::DeleteFile(*it, true);
base::DeleteFile(cache_path, true);
} }
ProfilesToDelete().clear(); ProfilesToDelete().clear();
} }
...@@ -300,6 +305,10 @@ ProfileManager::ProfileManager(const base::FilePath& user_data_dir) ...@@ -300,6 +305,10 @@ ProfileManager::ProfileManager(const base::FilePath& user_data_dir)
this, this,
chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
registrar_.Add(
this,
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
content::NotificationService::AllSources());
if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty()) if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty())
profile_shortcut_manager_.reset(ProfileShortcutManager::Create( profile_shortcut_manager_.reset(ProfileShortcutManager::Create(
...@@ -651,6 +660,10 @@ void ProfileManager::Observe( ...@@ -651,6 +660,10 @@ void ProfileManager::Observe(
} }
break; break;
} }
case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: {
save_active_profiles = !closing_all_browsers_;
break;
}
default: { default: {
NOTREACHED(); NOTREACHED();
break; break;
...@@ -862,13 +875,15 @@ void ProfileManager::OnProfileCreated(Profile* profile, ...@@ -862,13 +875,15 @@ void ProfileManager::OnProfileCreated(Profile* profile,
profiles_info_.erase(iter); profiles_info_.erase(iter);
} }
// If this was the guest profile, finish setting its incognito status. if (profile) {
if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) // If this was the guest profile, finish setting its incognito status.
SetGuestProfilePrefs(profile); if (profile->GetPath() == ProfileManager::GetGuestProfilePath())
SetGuestProfilePrefs(profile);
// Invoke CREATED callback for incognito profiles. // Invoke CREATED callback for incognito profiles.
if (profile && go_off_the_record) if (go_off_the_record)
RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED);
}
// Invoke INITIALIZED or FAIL for all profiles. // Invoke INITIALIZED or FAIL for all profiles.
RunCallbacks(callbacks, profile, RunCallbacks(callbacks, profile,
...@@ -984,6 +999,11 @@ void ProfileManager::AddProfileToCache(Profile* profile) { ...@@ -984,6 +999,11 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
username, username,
icon_index, icon_index,
managed_user_id); managed_user_id);
if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
cache.SetProfileIsEphemeralAtIndex(
cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
}
} }
void ProfileManager::InitProfileUserPrefs(Profile* profile) { void ProfileManager::InitProfileUserPrefs(Profile* profile) {
...@@ -1116,6 +1136,17 @@ void ProfileManager::ScheduleProfileForDeletion( ...@@ -1116,6 +1136,17 @@ void ProfileManager::ScheduleProfileForDeletion(
FinishDeletingProfile(profile_dir); FinishDeletingProfile(profile_dir);
} }
// static
void ProfileManager::CleanUpStaleProfiles(
const std::vector<base::FilePath>& profile_paths) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin();
it != profile_paths.end(); ++it) {
NukeProfileFromDisk(*it);
}
}
void ProfileManager::OnNewActiveProfileLoaded( void ProfileManager::OnNewActiveProfileLoaded(
const base::FilePath& profile_to_delete_path, const base::FilePath& profile_to_delete_path,
const base::FilePath& last_non_managed_profile_path, const base::FilePath& last_non_managed_profile_path,
......
...@@ -187,6 +187,12 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -187,6 +187,12 @@ class ProfileManager : public base::NonThreadSafe,
void ScheduleProfileForDeletion(const base::FilePath& profile_dir, void ScheduleProfileForDeletion(const base::FilePath& profile_dir,
const CreateCallback& callback); const CreateCallback& callback);
// Called on start-up if there are any stale ephemeral profiles to be deleted.
// This can be the case if the browser has crashed and the clean-up code had
// no chance to run then.
static void CleanUpStaleProfiles(
const std::vector<base::FilePath>& profile_paths);
// Autoloads profiles if they are running background apps. // Autoloads profiles if they are running background apps.
void AutoloadProfiles(); void AutoloadProfiles();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment