diff options
author | pastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-06 20:30:11 +0000 |
---|---|---|
committer | pastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-06 20:30:11 +0000 |
commit | a02c4ef5af828b99bd1b81d97cf45a43c0276242 (patch) | |
tree | 54bd3b2c2aae3a9935570d9a2306e84eda13ae82 | |
parent | b69ac914734e86e9a5cf8740539db18e49c7b7ea (diff) | |
download | chromium_src-a02c4ef5af828b99bd1b81d97cf45a43c0276242.zip chromium_src-a02c4ef5af828b99bd1b81d97cf45a43c0276242.tar.gz chromium_src-a02c4ef5af828b99bd1b81d97cf45a43c0276242.tar.bz2 |
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
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 13 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 1 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.cc | 53 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.h | 6 |
4 files changed, 59 insertions, 14 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index ec233fa..2da396d 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -1045,9 +1045,16 @@ void ChromeBrowserMainParts::PreProfileInit() { if (profile_cache.ProfileIsEphemeralAtIndex(i)) profiles_to_delete.push_back(profile_cache.GetPathOfProfileAtIndex(i)); } - for (size_t i = 0;i < profiles_to_delete.size(); ++i) { - profile_manager->ScheduleProfileForDeletion( - profiles_to_delete[i], ProfileManager::CreateCallback()); + + if (profiles_to_delete.size()) { + 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 diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index f8e9e3c..aad52c4 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -507,6 +507,7 @@ void ProfileImpl::DoFinalInit() { // kGoogleServicesUsername, initialize components that depend on it to reflect // the current value. UpdateProfileUserNameCache(); + UpdateProfileIsEphemeralCache(); GAIAInfoUpdateServiceFactory::GetForProfile(this); PrefService* local_state = g_browser_process->local_state(); diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index 602766e..c598ee2 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -165,6 +165,15 @@ bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { 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) void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, bool is_mounted) { @@ -198,11 +207,7 @@ void ProfileManager::NukeDeletedProfilesFromDisk() { ProfilesToDelete().begin(); it != ProfilesToDelete().end(); ++it) { - // Delete both the profile directory and its corresponding cache. - base::FilePath cache_path; - chrome::GetUserCacheDirectory(*it, &cache_path); - base::DeleteFile(*it, true); - base::DeleteFile(cache_path, true); + NukeProfileFromDisk(*it); } ProfilesToDelete().clear(); } @@ -300,6 +305,10 @@ ProfileManager::ProfileManager(const base::FilePath& user_data_dir) this, chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, content::NotificationService::AllSources()); + registrar_.Add( + this, + chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, + content::NotificationService::AllSources()); if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty()) profile_shortcut_manager_.reset(ProfileShortcutManager::Create( @@ -651,6 +660,10 @@ void ProfileManager::Observe( } break; } + case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: { + save_active_profiles = !closing_all_browsers_; + break; + } default: { NOTREACHED(); break; @@ -862,13 +875,15 @@ void ProfileManager::OnProfileCreated(Profile* profile, profiles_info_.erase(iter); } - // If this was the guest profile, finish setting its incognito status. - if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) - SetGuestProfilePrefs(profile); + if (profile) { + // If this was the guest profile, finish setting its incognito status. + if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) + SetGuestProfilePrefs(profile); - // Invoke CREATED callback for incognito profiles. - if (profile && go_off_the_record) - RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); + // Invoke CREATED callback for incognito profiles. + if (go_off_the_record) + RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); + } // Invoke INITIALIZED or FAIL for all profiles. RunCallbacks(callbacks, profile, @@ -984,6 +999,11 @@ void ProfileManager::AddProfileToCache(Profile* profile) { username, icon_index, managed_user_id); + + if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { + cache.SetProfileIsEphemeralAtIndex( + cache.GetIndexOfProfileWithPath(profile->GetPath()), true); + } } void ProfileManager::InitProfileUserPrefs(Profile* profile) { @@ -1116,6 +1136,17 @@ void ProfileManager::ScheduleProfileForDeletion( 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( const base::FilePath& profile_to_delete_path, const base::FilePath& last_non_managed_profile_path, diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index a8674de..dc849cb 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -187,6 +187,12 @@ class ProfileManager : public base::NonThreadSafe, void ScheduleProfileForDeletion(const base::FilePath& profile_dir, 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. void AutoloadProfiles(); |