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

Side by Side 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, 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_manager.h" 5 #include "chrome/browser/profiles/profile_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map>
9 #include <set> 10 #include <set>
10 #include <string> 11 #include <string>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/deferred_sequenced_task_runner.h" 15 #include "base/deferred_sequenced_task_runner.h"
15 #include "base/feature_list.h" 16 #include "base/feature_list.h"
16 #include "base/files/file_enumerator.h" 17 #include "base/files/file_enumerator.h"
17 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 #include "chrome/browser/profiles/profile_statistics.h" 127 #include "chrome/browser/profiles/profile_statistics.h"
127 #include "chrome/browser/profiles/profile_statistics_factory.h" 128 #include "chrome/browser/profiles/profile_statistics_factory.h"
128 #endif 129 #endif
129 130
130 using base::UserMetricsAction; 131 using base::UserMetricsAction;
131 using content::BrowserThread; 132 using content::BrowserThread;
132 133
133 namespace { 134 namespace {
134 135
135 // Profiles that should be deleted on shutdown. 136 // Profiles that should be deleted on shutdown.
136 std::vector<base::FilePath>& ProfilesToDelete() { 137 enum class ProfileDeletionStage { SCHEDULED, ABANDONED };
137 CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ()); 138 using ProfileDeletionMap = std::map<base::FilePath, ProfileDeletionStage>;
139 ProfileDeletionMap& ProfilesToDelete() {
140 CR_DEFINE_STATIC_LOCAL(ProfileDeletionMap, profiles_to_delete, ());
138 return profiles_to_delete; 141 return profiles_to_delete;
139 } 142 }
140 143
141 int64_t ComputeFilesSize(const base::FilePath& directory, 144 int64_t ComputeFilesSize(const base::FilePath& directory,
142 const base::FilePath::StringType& pattern) { 145 const base::FilePath::StringType& pattern) {
143 int64_t running_size = 0; 146 int64_t running_size = 0;
144 base::FileEnumerator iter(directory, false, base::FileEnumerator::FILES, 147 base::FileEnumerator iter(directory, false, base::FileEnumerator::FILES,
145 pattern); 148 pattern);
146 while (!iter.Next().empty()) 149 while (!iter.Next().empty())
147 running_size += iter.GetInfo().GetSize(); 150 running_size += iter.GetInfo().GetSize();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 size = ComputeFilesSize(path, FILE_PATH_LITERAL("Policy")); 199 size = ComputeFilesSize(path, FILE_PATH_LITERAL("Policy"));
197 size_MB = static_cast<int>(size / kBytesInOneMB); 200 size_MB = static_cast<int>(size / kBytesInOneMB);
198 UMA_HISTOGRAM_COUNTS_10000("Profile.PolicySize", size_MB); 201 UMA_HISTOGRAM_COUNTS_10000("Profile.PolicySize", size_MB);
199 202
200 // Count number of enabled apps in this profile, if we know. 203 // Count number of enabled apps in this profile, if we know.
201 if (enabled_app_count != -1) 204 if (enabled_app_count != -1)
202 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count); 205 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count);
203 } 206 }
204 207
205 #if !defined(OS_ANDROID) 208 #if !defined(OS_ANDROID)
209 bool ScheduleProfileDirectoryForDeletion(const base::FilePath& path) {
Bernhard Bauer 2016/08/03 16:38:05 Document what the return value means and what the
210 if (ContainsKey(ProfilesToDelete(), path)) {
Bernhard Bauer 2016/08/03 16:38:05 Nit: no braces for single-line bodies.
211 return false;
212 }
213 ProfilesToDelete()[path] = ProfileDeletionStage::SCHEDULED;
214 return true;
Bernhard Bauer 2016/08/03 16:38:05 Nit: remove one space after `return`.
215 }
216
206 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { 217 void QueueProfileDirectoryForDeletion(const base::FilePath& path) {
207 ProfilesToDelete().push_back(path); 218 DCHECK(!ContainsKey(ProfilesToDelete(), path) ||
219 ProfilesToDelete()[path] == ProfileDeletionStage::SCHEDULED);
220 ProfilesToDelete()[path] = ProfileDeletionStage::ABANDONED;
208 } 221 }
209 #endif 222 #endif
210 223
211 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { 224 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) {
212 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(), 225 auto it = ProfilesToDelete().find(profile_path);
213 profile_path) != ProfilesToDelete().end(); 226 return it != ProfilesToDelete().end() &&
227 it->second == ProfileDeletionStage::ABANDONED;
214 } 228 }
215 229
216 // Physically remove deleted profile directories from disk. 230 // Physically remove deleted profile directories from disk.
217 void NukeProfileFromDisk(const base::FilePath& profile_path) { 231 void NukeProfileFromDisk(const base::FilePath& profile_path) {
218 // Delete both the profile directory and its corresponding cache. 232 // Delete both the profile directory and its corresponding cache.
219 base::FilePath cache_path; 233 base::FilePath cache_path;
220 chrome::GetUserCacheDirectory(profile_path, &cache_path); 234 chrome::GetUserCacheDirectory(profile_path, &cache_path);
221 base::DeleteFile(profile_path, true); 235 base::DeleteFile(profile_path, true);
222 base::DeleteFile(cache_path, true); 236 base::DeleteFile(cache_path, true);
223 } 237 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (!pm) // Is NULL when running unit tests. 342 if (!pm) // Is NULL when running unit tests.
329 return; 343 return;
330 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); 344 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
331 for (size_t i = 0; i < profiles.size(); ++i) 345 for (size_t i = 0; i < profiles.size(); ++i)
332 SessionServiceFactory::ShutdownForProfile(profiles[i]); 346 SessionServiceFactory::ShutdownForProfile(profiles[i]);
333 } 347 }
334 #endif 348 #endif
335 349
336 // static 350 // static
337 void ProfileManager::NukeDeletedProfilesFromDisk() { 351 void ProfileManager::NukeDeletedProfilesFromDisk() {
338 for (std::vector<base::FilePath>::iterator it = 352 for (const auto& item : ProfilesToDelete()) {
339 ProfilesToDelete().begin(); 353 if (item.second == ProfileDeletionStage::ABANDONED)
340 it != ProfilesToDelete().end(); 354 NukeProfileFromDisk(item.first);
341 ++it) {
342 NukeProfileFromDisk(*it);
343 } 355 }
344 ProfilesToDelete().clear(); 356 ProfilesToDelete().clear();
345 } 357 }
346 358
347 // static 359 // static
348 Profile* ProfileManager::GetLastUsedProfile() { 360 Profile* ProfileManager::GetLastUsedProfile() {
349 ProfileManager* profile_manager = g_browser_process->profile_manager(); 361 ProfileManager* profile_manager = g_browser_process->profile_manager();
350 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_); 362 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
351 } 363 }
352 364
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 742
731 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() { 743 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() {
732 return profile_shortcut_manager_.get(); 744 return profile_shortcut_manager_.get();
733 } 745 }
734 746
735 #if !defined(OS_ANDROID) 747 #if !defined(OS_ANDROID)
736 bool ProfileManager::MaybeScheduleProfileForDeletion( 748 bool ProfileManager::MaybeScheduleProfileForDeletion(
737 const base::FilePath& profile_dir, 749 const base::FilePath& profile_dir,
738 const CreateCallback& callback, 750 const CreateCallback& callback,
739 ProfileMetrics::ProfileDelete deletion_source) { 751 ProfileMetrics::ProfileDelete deletion_source) {
740 if (IsProfileMarkedForDeletion(profile_dir)) 752 if (!ScheduleProfileDirectoryForDeletion(profile_dir))
741 return false; 753 return false;
742 ScheduleProfileForDeletion(profile_dir, callback); 754 ScheduleProfileForDeletion(profile_dir, callback);
743 ProfileMetrics::LogProfileDeleteUser(deletion_source); 755 ProfileMetrics::LogProfileDeleteUser(deletion_source);
744 return true; 756 return true;
745 } 757 }
746 758
747 void ProfileManager::ScheduleProfileForDeletion( 759 void ProfileManager::ScheduleProfileForDeletion(
748 const base::FilePath& profile_dir, 760 const base::FilePath& profile_dir,
749 const CreateCallback& callback) { 761 const CreateCallback& callback) {
750 DCHECK(profiles::IsMultipleProfilesEnabled()); 762 DCHECK(profiles::IsMultipleProfilesEnabled());
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 1643
1632 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1644 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1633 if (!original_callback.is_null()) 1645 if (!original_callback.is_null())
1634 original_callback.Run(loaded_profile, status); 1646 original_callback.Run(loaded_profile, status);
1635 } 1647 }
1636 #endif // !defined(OS_ANDROID) 1648 #endif // !defined(OS_ANDROID)
1637 1649
1638 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1650 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1639 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1651 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1640 } 1652 }
OLDNEW
« 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