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

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 50293011: Improve ephemeral profiles clean up code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed param. Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | 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 <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { 159 void QueueProfileDirectoryForDeletion(const base::FilePath& path) {
160 ProfilesToDelete().push_back(path); 160 ProfilesToDelete().push_back(path);
161 } 161 }
162 162
163 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { 163 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) {
164 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(), 164 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(),
165 profile_path) != ProfilesToDelete().end(); 165 profile_path) != ProfilesToDelete().end();
166 } 166 }
167 167
168 // Physically remove deleted profile directories from disk.
169 void NukeProfileFromDisk(const base::FilePath& profile_path) {
170 // Delete both the profile directory and its corresponding cache.
171 base::FilePath cache_path;
172 chrome::GetUserCacheDirectory(profile_path, &cache_path);
173 base::DeleteFile(profile_path, true);
174 base::DeleteFile(cache_path, true);
175 }
176
168 #if defined(OS_CHROMEOS) 177 #if defined(OS_CHROMEOS)
169 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, 178 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status,
170 bool is_mounted) { 179 bool is_mounted) {
171 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { 180 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
172 LOG(ERROR) << "IsMounted call failed."; 181 LOG(ERROR) << "IsMounted call failed.";
173 return; 182 return;
174 } 183 }
175 if (!is_mounted) 184 if (!is_mounted)
176 LOG(ERROR) << "Cryptohome is not mounted."; 185 LOG(ERROR) << "Cryptohome is not mounted.";
177 } 186 }
(...skipping 13 matching lines...) Expand all
191 SessionServiceFactory::ShutdownForProfile(profiles[i]); 200 SessionServiceFactory::ShutdownForProfile(profiles[i]);
192 } 201 }
193 #endif 202 #endif
194 203
195 // static 204 // static
196 void ProfileManager::NukeDeletedProfilesFromDisk() { 205 void ProfileManager::NukeDeletedProfilesFromDisk() {
197 for (std::vector<base::FilePath>::iterator it = 206 for (std::vector<base::FilePath>::iterator it =
198 ProfilesToDelete().begin(); 207 ProfilesToDelete().begin();
199 it != ProfilesToDelete().end(); 208 it != ProfilesToDelete().end();
200 ++it) { 209 ++it) {
201 // Delete both the profile directory and its corresponding cache. 210 NukeProfileFromDisk(*it);
202 base::FilePath cache_path;
203 chrome::GetUserCacheDirectory(*it, &cache_path);
204 base::DeleteFile(*it, true);
205 base::DeleteFile(cache_path, true);
206 } 211 }
207 ProfilesToDelete().clear(); 212 ProfilesToDelete().clear();
208 } 213 }
209 214
210 namespace { 215 namespace {
211 216
212 bool s_allow_get_default_profile = false; 217 bool s_allow_get_default_profile = false;
213 218
214 } // namespace 219 } // namespace
215 220
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 chrome::NOTIFICATION_BROWSER_CLOSED, 298 chrome::NOTIFICATION_BROWSER_CLOSED,
294 content::NotificationService::AllSources()); 299 content::NotificationService::AllSources());
295 registrar_.Add( 300 registrar_.Add(
296 this, 301 this,
297 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, 302 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
298 content::NotificationService::AllSources()); 303 content::NotificationService::AllSources());
299 registrar_.Add( 304 registrar_.Add(
300 this, 305 this,
301 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 306 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
302 content::NotificationService::AllSources()); 307 content::NotificationService::AllSources());
308 registrar_.Add(
309 this,
310 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
311 content::NotificationService::AllSources());
303 312
304 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty()) 313 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty())
305 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( 314 profile_shortcut_manager_.reset(ProfileShortcutManager::Create(
306 this)); 315 this));
307 } 316 }
308 317
309 ProfileManager::~ProfileManager() { 318 ProfileManager::~ProfileManager() {
310 } 319 }
311 320
312 base::FilePath ProfileManager::GetInitialProfileDir() { 321 base::FilePath ProfileManager::GetInitialProfileDir() {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 DCHECK(browser); 653 DCHECK(browser);
645 Profile* profile = browser->profile(); 654 Profile* profile = browser->profile();
646 DCHECK(profile); 655 DCHECK(profile);
647 if (!profile->IsOffTheRecord() && --browser_counts_[profile] == 0) { 656 if (!profile->IsOffTheRecord() && --browser_counts_[profile] == 0) {
648 active_profiles_.erase(std::find(active_profiles_.begin(), 657 active_profiles_.erase(std::find(active_profiles_.begin(),
649 active_profiles_.end(), profile)); 658 active_profiles_.end(), profile));
650 save_active_profiles = !closing_all_browsers_; 659 save_active_profiles = !closing_all_browsers_;
651 } 660 }
652 break; 661 break;
653 } 662 }
663 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: {
664 save_active_profiles = !closing_all_browsers_;
665 break;
666 }
654 default: { 667 default: {
655 NOTREACHED(); 668 NOTREACHED();
656 break; 669 break;
657 } 670 }
658 } 671 }
659 672
660 if (save_active_profiles) { 673 if (save_active_profiles) {
661 PrefService* local_state = g_browser_process->local_state(); 674 PrefService* local_state = g_browser_process->local_state();
662 DCHECK(local_state); 675 DCHECK(local_state);
663 ListPrefUpdate update(local_state, prefs::kProfilesLastActive); 676 ListPrefUpdate update(local_state, prefs::kProfilesLastActive);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 if (success) { 868 if (success) {
856 DoFinalInit(profile, go_off_the_record); 869 DoFinalInit(profile, go_off_the_record);
857 if (go_off_the_record) 870 if (go_off_the_record)
858 profile = profile->GetOffTheRecordProfile(); 871 profile = profile->GetOffTheRecordProfile();
859 info->created = true; 872 info->created = true;
860 } else { 873 } else {
861 profile = NULL; 874 profile = NULL;
862 profiles_info_.erase(iter); 875 profiles_info_.erase(iter);
863 } 876 }
864 877
865 // If this was the guest profile, finish setting its incognito status. 878 if (profile) {
866 if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) 879 // If this was the guest profile, finish setting its incognito status.
867 SetGuestProfilePrefs(profile); 880 if (profile->GetPath() == ProfileManager::GetGuestProfilePath())
881 SetGuestProfilePrefs(profile);
868 882
869 // Invoke CREATED callback for incognito profiles. 883 // Invoke CREATED callback for incognito profiles.
870 if (profile && go_off_the_record) 884 if (go_off_the_record)
871 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); 885 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED);
886 }
872 887
873 // Invoke INITIALIZED or FAIL for all profiles. 888 // Invoke INITIALIZED or FAIL for all profiles.
874 RunCallbacks(callbacks, profile, 889 RunCallbacks(callbacks, profile,
875 profile ? Profile::CREATE_STATUS_INITIALIZED : 890 profile ? Profile::CREATE_STATUS_INITIALIZED :
876 Profile::CREATE_STATUS_LOCAL_FAIL); 891 Profile::CREATE_STATUS_LOCAL_FAIL);
877 } 892 }
878 893
879 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { 894 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() {
880 PrefService* local_state = g_browser_process->local_state(); 895 PrefService* local_state = g_browser_process->local_state();
881 DCHECK(local_state); 896 DCHECK(local_state);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 prefs::kProfileAvatarIndex); 992 prefs::kProfileAvatarIndex);
978 993
979 std::string managed_user_id = 994 std::string managed_user_id =
980 profile->GetPrefs()->GetString(prefs::kManagedUserId); 995 profile->GetPrefs()->GetString(prefs::kManagedUserId);
981 996
982 cache.AddProfileToCache(profile->GetPath(), 997 cache.AddProfileToCache(profile->GetPath(),
983 profile_name, 998 profile_name,
984 username, 999 username,
985 icon_index, 1000 icon_index,
986 managed_user_id); 1001 managed_user_id);
1002
1003 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
1004 cache.SetProfileIsEphemeralAtIndex(
1005 cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
1006 }
987 } 1007 }
988 1008
989 void ProfileManager::InitProfileUserPrefs(Profile* profile) { 1009 void ProfileManager::InitProfileUserPrefs(Profile* profile) {
990 ProfileInfoCache& cache = GetProfileInfoCache(); 1010 ProfileInfoCache& cache = GetProfileInfoCache();
991 1011
992 if (profile->GetPath().DirName() != cache.GetUserDataDir()) 1012 if (profile->GetPath().DirName() != cache.GetUserDataDir())
993 return; 1013 return;
994 1014
995 size_t avatar_index; 1015 size_t avatar_index;
996 std::string profile_name; 1016 std::string profile_name;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 #else 1129 #else
1110 // For OS_MACOSX the pref is updated in the callback to make sure that 1130 // For OS_MACOSX the pref is updated in the callback to make sure that
1111 // it isn't used before the profile is actually loaded. 1131 // it isn't used before the profile is actually loaded.
1112 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); 1132 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile);
1113 #endif 1133 #endif
1114 } 1134 }
1115 } 1135 }
1116 FinishDeletingProfile(profile_dir); 1136 FinishDeletingProfile(profile_dir);
1117 } 1137 }
1118 1138
1139 // static
1140 void ProfileManager::CleanUpStaleProfiles(
1141 const std::vector<base::FilePath>& profile_paths) {
1142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1143
1144 for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin();
1145 it != profile_paths.end(); ++it) {
1146 NukeProfileFromDisk(*it);
1147 }
1148 }
1149
1119 void ProfileManager::OnNewActiveProfileLoaded( 1150 void ProfileManager::OnNewActiveProfileLoaded(
1120 const base::FilePath& profile_to_delete_path, 1151 const base::FilePath& profile_to_delete_path,
1121 const base::FilePath& last_non_managed_profile_path, 1152 const base::FilePath& last_non_managed_profile_path,
1122 const CreateCallback& original_callback, 1153 const CreateCallback& original_callback,
1123 Profile* loaded_profile, 1154 Profile* loaded_profile,
1124 Profile::CreateStatus status) { 1155 Profile::CreateStatus status) {
1125 DCHECK(status != Profile::CREATE_STATUS_LOCAL_FAIL && 1156 DCHECK(status != Profile::CREATE_STATUS_LOCAL_FAIL &&
1126 status != Profile::CREATE_STATUS_REMOTE_FAIL); 1157 status != Profile::CREATE_STATUS_REMOTE_FAIL);
1127 1158
1128 // Only run the code if the profile initialization has finished completely. 1159 // Only run the code if the profile initialization has finished completely.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ProfileManager::ProfileInfo::ProfileInfo( 1243 ProfileManager::ProfileInfo::ProfileInfo(
1213 Profile* profile, 1244 Profile* profile,
1214 bool created) 1245 bool created)
1215 : profile(profile), 1246 : profile(profile),
1216 created(created) { 1247 created(created) {
1217 } 1248 }
1218 1249
1219 ProfileManager::ProfileInfo::~ProfileInfo() { 1250 ProfileManager::ProfileInfo::~ProfileInfo() {
1220 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1251 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1221 } 1252 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698