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

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: Created 4 years, 5 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 6451dd64211c2e6b0a0a6f153b8409e04b6f7c16..b0b4962d21a85af140731a97bcacb3b0de02c148 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>
@@ -133,8 +134,10 @@ 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>;
+ProfileDeletionMap& ProfilesToDelete() {
+ CR_DEFINE_STATIC_LOCAL(ProfileDeletionMap, profiles_to_delete, ());
return profiles_to_delete;
}
@@ -203,14 +206,25 @@ void ProfileSizeTask(const base::FilePath& path, int enabled_app_count) {
}
#if !defined(OS_ANDROID)
+bool ScheduleProfileDirectoryForDeletion(const base::FilePath& path) {
Bernhard Bauer 2016/08/03 16:38:05 Document what the return value means and what the
+ if (ContainsKey(ProfilesToDelete(), path)) {
Bernhard Bauer 2016/08/03 16:38:05 Nit: no braces for single-line bodies.
+ return false;
+ }
+ ProfilesToDelete()[path] = ProfileDeletionStage::SCHEDULED;
+ return true;
Bernhard Bauer 2016/08/03 16:38:05 Nit: remove one space after `return`.
+}
+
void QueueProfileDirectoryForDeletion(const base::FilePath& path) {
- ProfilesToDelete().push_back(path);
+ DCHECK(!ContainsKey(ProfilesToDelete(), path) ||
+ ProfilesToDelete()[path] == ProfileDeletionStage::SCHEDULED);
+ ProfilesToDelete()[path] = ProfileDeletionStage::ABANDONED;
}
#endif
bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) {
- 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.
@@ -335,11 +349,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();
}
@@ -737,7 +749,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