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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 PrefService* local_state = g_browser_process->local_state(); | 1071 PrefService* local_state = g_browser_process->local_state(); |
1072 ProfileInfoCache& cache = GetProfileInfoCache(); | 1072 ProfileInfoCache& cache = GetProfileInfoCache(); |
1073 | |
1073 if (profile_dir.BaseName().MaybeAsASCII() == | 1074 if (profile_dir.BaseName().MaybeAsASCII() == |
1074 local_state->GetString(prefs::kProfileLastUsed)) { | 1075 local_state->GetString(prefs::kProfileLastUsed)) { |
1075 // Update the last used profile pref before closing browser windows. This | 1076 // Update the last used profile pref before closing browser windows. This |
1076 // way the correct last used profile is set for any notification observers. | 1077 // way the correct last used profile is set for any notification observers. |
1077 std::string last_non_managed_profile; | 1078 base::FilePath last_non_managed_profile_path; |
1078 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1079 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
1079 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1080 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
1080 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { | 1081 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { |
1081 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); | 1082 last_non_managed_profile_path = cur_path; |
1082 break; | 1083 break; |
1083 } | 1084 } |
1084 } | 1085 } |
1086 | |
1085 // If we're deleting the last (non-managed) profile, then create a new | 1087 // If we're deleting the last (non-managed) profile, then create a new |
1086 // profile in its place. | 1088 // profile in its place. |
1089 std::string last_non_managed_profile = | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
Nit: Make it const
noms (inactive)
2013/06/11 19:32:17
Done.
| |
1090 last_non_managed_profile_path.BaseName().MaybeAsASCII(); | |
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 { |
1108 // On the Mac, the browser process is not killed when all browser windows | |
1109 // are closed, so just in case we are deleting the active profile, and no | |
1110 // other profile has been loaded, we must pre-load a next one. | |
1111 #if defined(OS_MACOSX) | |
1112 CreateProfileAsync(last_non_managed_profile_path, | |
1113 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | |
1114 base::Unretained(this), | |
1115 profile_dir, | |
1116 last_non_managed_profile, | |
1117 desktop_type), | |
1118 string16(), | |
1119 string16(), | |
1120 false); | |
1121 return; | |
1122 #else | |
1123 // For OS_MACOSX we will update the local_state in the callback | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
Nit: "update the local_state" -> "update the pref"
noms (inactive)
2013/06/11 19:32:17
Done.
| |
1124 // to make sure that it isn't used before the profile is actually loaded. | |
1104 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | 1125 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
1126 #endif | |
1105 } | 1127 } |
1106 } | 1128 } |
1129 FinishDeletingProfile(profile_dir); | |
1130 } | |
1107 | 1131 |
1132 void ProfileManager::OnNewActiveProfileLoaded(const base::FilePath& profile_dir, | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
This param should be on the next line, aligned wit
noms (inactive)
2013/06/11 19:32:17
Done.
| |
1133 const std::string last_non_managed_profile, | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
Should be a "const std::string&".
noms (inactive)
2013/06/11 19:32:17
Done.
| |
1134 chrome::HostDesktopType desktop_type, | |
1135 Profile* profile, | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
Rename to |loaded_profile|.
noms (inactive)
2013/06/11 19:32:17
Done.
| |
1136 Profile::CreateStatus status) { | |
1137 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
1138 // Update the local state as promised in the ScheduleProfileForDeletion. | |
1139 PrefService* local_state = g_browser_process->local_state(); | |
1140 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | |
1141 FinishDeletingProfile(profile_dir); | |
1142 } else if (status == Profile::CREATE_STATUS_FAIL) { | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
Hmm, I see CREATE_STATUS_LOCAL_FAIL and CREATE_STA
noms (inactive)
2013/06/11 19:32:17
And how!
On 2013/06/05 20:00:52, Alexei Svitkine
| |
1143 // If we are here, it means that the profile we tried to load as the | |
Alexei Svitkine (slow)
2013/06/05 20:00:52
Nit: No "we"'s
noms (inactive)
2013/06/11 19:32:17
Done.
| |
1144 // next active profile has been deleted. We should retry to delete | |
1145 // this profile to redo the logic and load the next available profile. | |
1146 ScheduleProfileForDeletion(profile_dir, desktop_type); | |
1147 } | |
1148 } | |
1149 | |
1150 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { | |
1151 ProfileInfoCache& cache = GetProfileInfoCache(); | |
1108 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1152 // 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. | 1153 // start deleting the profile instance we need to close background apps too. |
1110 Profile* profile = GetProfileByPath(profile_dir); | 1154 Profile* profile = GetProfileByPath(profile_dir); |
1111 if (profile) { | 1155 if (profile) { |
1112 BrowserList::CloseAllBrowsersWithProfile(profile); | 1156 BrowserList::CloseAllBrowsersWithProfile(profile); |
1113 | 1157 |
1114 // Disable sync for doomed profile. | 1158 // Disable sync for doomed profile. |
1115 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1159 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
1116 profile)) { | 1160 profile)) { |
1117 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1161 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 ProfileManager::ProfileInfo::ProfileInfo( | 1229 ProfileManager::ProfileInfo::ProfileInfo( |
1186 Profile* profile, | 1230 Profile* profile, |
1187 bool created) | 1231 bool created) |
1188 : profile(profile), | 1232 : profile(profile), |
1189 created(created) { | 1233 created(created) { |
1190 } | 1234 } |
1191 | 1235 |
1192 ProfileManager::ProfileInfo::~ProfileInfo() { | 1236 ProfileManager::ProfileInfo::~ProfileInfo() { |
1193 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1237 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1194 } | 1238 } |
OLD | NEW |