Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Unified Diff: chrome/browser/profiles/profile_manager.cc

Issue 2201793002: Fixed sole profile double deletion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewrite comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_manager.cc
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index 1c992d410357ccbe7f9db73fac8bc686aedbb1fa..070f28fe54478a42f44f462a73ce89aea513fc76 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -6,6 +6,7 @@
#include <stdint.h>
+#include <map>
#include <set>
#include <string>
@@ -131,8 +132,13 @@ using content::BrowserThread;
namespace {
// Profiles that should be deleted on shutdown.
-std::vector<base::FilePath>& ProfilesToDelete() {
- CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ());
+enum class ProfileDeletionStage { SCHEDULED, ABANDONED };
+using ProfileDeletionMap = std::map<base::FilePath, ProfileDeletionStage>;
+// Profile deletion can pass thru two stages: scheduled for deletion when where
Bernhard Bauer 2016/08/04 12:24:34 Nit: "through". Also, would it make sense to move
+// performing necessary activity prior to deletion, and abandoned stage when it
Bernhard Bauer 2016/08/04 12:24:34 I think we can also go into detail about what the
+// can be safely removed from disk.
+ProfileDeletionMap& ProfilesToDelete() {
+ CR_DEFINE_STATIC_LOCAL(ProfileDeletionMap, profiles_to_delete, ());
return profiles_to_delete;
}
@@ -201,14 +207,25 @@ void ProfileSizeTask(const base::FilePath& path, int enabled_app_count) {
}
#if !defined(OS_ANDROID)
+// Return true if profile can be scheduled for deletion.
Bernhard Bauer 2016/08/04 12:24:34 I think we should explain in the comment under whi
+bool ScheduleProfileDirectoryForDeletion(const base::FilePath& path) {
+ if (ContainsKey(ProfilesToDelete(), path))
+ return false;
+ ProfilesToDelete()[path] = ProfileDeletionStage::SCHEDULED;
+ return true;
+}
+
void QueueProfileDirectoryForDeletion(const base::FilePath& path) {
Bernhard Bauer 2016/08/04 12:24:34 Should we maybe use the term "marked" for the seco
- ProfilesToDelete().push_back(path);
+ DCHECK(!ContainsKey(ProfilesToDelete(), path) ||
+ ProfilesToDelete()[path] == ProfileDeletionStage::SCHEDULED);
+ ProfilesToDelete()[path] = ProfileDeletionStage::ABANDONED;
}
#endif
bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) {
Bernhard Bauer 2016/08/04 12:24:34 For consistency, this method should then probably
- return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(),
- profile_path) != ProfilesToDelete().end();
+ auto it = ProfilesToDelete().find(profile_path);
+ return it != ProfilesToDelete().end() &&
+ it->second == ProfileDeletionStage::ABANDONED;
}
// Physically remove deleted profile directories from disk.
@@ -333,11 +350,9 @@ void ProfileManager::ShutdownSessionServices() {
// static
void ProfileManager::NukeDeletedProfilesFromDisk() {
- for (std::vector<base::FilePath>::iterator it =
- ProfilesToDelete().begin();
- it != ProfilesToDelete().end();
- ++it) {
- NukeProfileFromDisk(*it);
+ for (const auto& item : ProfilesToDelete()) {
+ if (item.second == ProfileDeletionStage::ABANDONED)
+ NukeProfileFromDisk(item.first);
}
ProfilesToDelete().clear();
}
@@ -735,7 +750,7 @@ bool ProfileManager::MaybeScheduleProfileForDeletion(
const base::FilePath& profile_dir,
const CreateCallback& callback,
ProfileMetrics::ProfileDelete deletion_source) {
- if (IsProfileMarkedForDeletion(profile_dir))
+ if (!ScheduleProfileDirectoryForDeletion(profile_dir))
return false;
ScheduleProfileForDeletion(profile_dir, callback);
ProfileMetrics::LogProfileDeleteUser(deletion_source);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698