Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 return go_off_the_record; | 1061 return go_off_the_record; |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 // TODO(robertshield): ProfileManager should not be opening windows and should | 1064 // TODO(robertshield): ProfileManager should not be opening windows and should |
| 1065 // not have to care about HostDesktopType. See http://crbug.com/153864 | 1065 // not have to care about HostDesktopType. See http://crbug.com/153864 |
| 1066 void ProfileManager::ScheduleProfileForDeletion( | 1066 void ProfileManager::ScheduleProfileForDeletion( |
| 1067 const base::FilePath& profile_dir, | 1067 const base::FilePath& profile_dir, |
| 1068 chrome::HostDesktopType desktop_type) { | 1068 chrome::HostDesktopType desktop_type) { |
| 1069 DCHECK(IsMultipleProfilesEnabled()); | 1069 DCHECK(IsMultipleProfilesEnabled()); |
| 1070 | 1070 |
| 1071 bool new_last_profile_being_loaded = false; | |
|
Alexei Svitkine (slow)
2013/05/14 15:34:12
Instead of keeping track of this here, just do an
noms (inactive)
2013/06/05 18:16:38
Done.
| |
| 1072 size_t last_non_managed_profile_index; | |
| 1073 | |
| 1071 PrefService* local_state = g_browser_process->local_state(); | 1074 PrefService* local_state = g_browser_process->local_state(); |
| 1072 ProfileInfoCache& cache = GetProfileInfoCache(); | 1075 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 1073 if (profile_dir.BaseName().MaybeAsASCII() == | 1076 if (profile_dir.BaseName().MaybeAsASCII() == |
| 1074 local_state->GetString(prefs::kProfileLastUsed)) { | 1077 local_state->GetString(prefs::kProfileLastUsed)) { |
| 1075 // Update the last used profile pref before closing browser windows. This | 1078 // Update the last used profile pref before closing browser windows. This |
| 1076 // way the correct last used profile is set for any notification observers. | 1079 // way the correct last used profile is set for any notification observers. |
| 1077 std::string last_non_managed_profile; | 1080 std::string last_non_managed_profile; |
| 1078 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1081 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 1079 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1082 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| 1080 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { | 1083 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { |
| 1081 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); | 1084 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); |
| 1085 last_non_managed_profile_index = i; | |
| 1082 break; | 1086 break; |
| 1083 } | 1087 } |
| 1084 } | 1088 } |
| 1085 // If we're deleting the last (non-managed) profile, then create a new | 1089 // If we're deleting the last (non-managed) profile, then create a new |
| 1086 // profile in its place. | 1090 // profile in its place. |
| 1087 if (last_non_managed_profile.empty()) { | 1091 if (last_non_managed_profile.empty()) { |
| 1088 base::FilePath new_path = GenerateNextProfileDirectoryPath(); | 1092 base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
| 1089 // Make sure the last used profile path is pointing at it. This way the | 1093 // Make sure the last used profile path is pointing at it. This way the |
| 1090 // correct last used profile is set for any notification observers. | 1094 // correct last used profile is set for any notification observers. |
| 1091 local_state->SetString(prefs::kProfileLastUsed, | 1095 local_state->SetString(prefs::kProfileLastUsed, |
| 1092 new_path.BaseName().MaybeAsASCII()); | 1096 new_path.BaseName().MaybeAsASCII()); |
| 1093 // TODO(robertshield): This desktop type needs to come from the invoker, | 1097 // TODO(robertshield): This desktop type needs to come from the invoker, |
| 1094 // currently that involves plumbing this through web UI. | 1098 // currently that involves plumbing this through web UI. |
| 1095 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | 1099 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 1096 CreateProfileAsync(new_path, | 1100 CreateProfileAsync(new_path, |
| 1097 base::Bind(&OnOpenWindowForNewProfile, | 1101 base::Bind(&OnOpenWindowForNewProfile, |
| 1098 desktop_type, | 1102 desktop_type, |
| 1099 CreateCallback()), | 1103 CreateCallback()), |
| 1100 string16(), | 1104 string16(), |
| 1101 string16(), | 1105 string16(), |
| 1102 false); | 1106 false); |
| 1103 } else { | 1107 } else { |
| 1104 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | 1108 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
| 1109 | |
| 1110 // On the Mac, the browser process is not killed when all browser windows | |
| 1111 // are closed, so just in case we are deleting the active profile, and no | |
| 1112 // other profile has been loaded, we must pre-load a next one. | |
| 1113 #if defined(OS_MACOSX) | |
| 1114 new_last_profile_being_loaded = true; | |
| 1115 base::FilePath path = profile_info_cache_->GetPathOfProfileAtIndex( | |
| 1116 last_non_managed_profile_index); | |
|
Alexei Svitkine (slow)
2013/05/14 15:34:12
If you're just going to query the path of that pro
noms (inactive)
2013/06/05 18:16:38
Done.
| |
| 1117 CreateProfileAsync(path, | |
| 1118 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | |
|
Alexei Svitkine (slow)
2013/05/14 15:34:12
Hmm, this may be tricky. I think you should loop i
noms (inactive)
2013/06/05 18:16:38
Done most of the comments. Working on the tests.
| |
| 1119 base::Unretained(this), | |
| 1120 profile_dir), | |
| 1121 string16(), | |
| 1122 string16(), | |
| 1123 false); | |
| 1124 #endif | |
| 1105 } | 1125 } |
| 1106 } | 1126 } |
| 1107 | 1127 |
| 1128 if (!new_last_profile_being_loaded) | |
| 1129 FinishDeletingProfile(profile_dir); | |
| 1130 } | |
| 1131 | |
| 1132 void ProfileManager::OnNewActiveProfileLoaded(const base::FilePath& profile_dir, | |
| 1133 Profile* profile, | |
| 1134 Profile::CreateStatus status) { | |
| 1135 // Ensure we only call the callback once per profile creation. | |
| 1136 if (status == Profile::CREATE_STATUS_INITIALIZED) | |
| 1137 FinishDeletingProfile(profile_dir); | |
| 1138 } | |
| 1139 | |
| 1140 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { | |
| 1141 ProfileInfoCache& cache = GetProfileInfoCache(); | |
| 1108 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1142 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
| 1109 // start deleting the profile instance we need to close background apps too. | 1143 // start deleting the profile instance we need to close background apps too. |
| 1110 Profile* profile = GetProfileByPath(profile_dir); | 1144 Profile* profile = GetProfileByPath(profile_dir); |
| 1111 if (profile) { | 1145 if (profile) { |
| 1112 BrowserList::CloseAllBrowsersWithProfile(profile); | 1146 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 1113 | 1147 |
| 1114 // Disable sync for doomed profile. | 1148 // Disable sync for doomed profile. |
| 1115 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1149 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 1116 profile)) { | 1150 profile)) { |
| 1117 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1151 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1185 ProfileManager::ProfileInfo::ProfileInfo( | 1219 ProfileManager::ProfileInfo::ProfileInfo( |
| 1186 Profile* profile, | 1220 Profile* profile, |
| 1187 bool created) | 1221 bool created) |
| 1188 : profile(profile), | 1222 : profile(profile), |
| 1189 created(created) { | 1223 created(created) { |
| 1190 } | 1224 } |
| 1191 | 1225 |
| 1192 ProfileManager::ProfileInfo::~ProfileInfo() { | 1226 ProfileManager::ProfileInfo::~ProfileInfo() { |
| 1193 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1227 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
| 1194 } | 1228 } |
| OLD | NEW |