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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 } | 159 } |
160 | 160 |
161 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { | 161 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { |
162 ProfilesToDelete().push_back(path); | 162 ProfilesToDelete().push_back(path); |
163 } | 163 } |
164 | 164 |
165 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
166 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, | 166 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, |
167 bool is_mounted) { | 167 bool is_mounted) { |
168 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | 168 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { |
169 LOG(ERROR) << "IsMounted call failed."; | 169 return; |
Alexei Svitkine (slow)
2013/06/12 21:02:31
Nit: Indention looks wrong.
| |
170 return; | |
171 } | 170 } |
172 if (!is_mounted) | 171 if (!is_mounted) |
Alexei Svitkine (slow)
2013/06/12 21:02:31
What's this dangling if?
| |
173 LOG(ERROR) << "Cryptohome is not mounted."; | 172 } |
174 } | |
175 | 173 |
176 #endif | 174 #endif |
177 | 175 |
178 } // namespace | 176 } // namespace |
179 | 177 |
180 #if defined(ENABLE_SESSION_SERVICE) | 178 #if defined(ENABLE_SESSION_SERVICE) |
181 // static | 179 // static |
182 void ProfileManager::ShutdownSessionServices() { | 180 void ProfileManager::ShutdownSessionServices() { |
183 ProfileManager* pm = g_browser_process->profile_manager(); | 181 ProfileManager* pm = g_browser_process->profile_manager(); |
184 if (!pm) // Is NULL when running unit tests. | 182 if (!pm) // Is NULL when running unit tests. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 | 390 |
393 std::vector<Profile*> to_return; | 391 std::vector<Profile*> to_return; |
394 if (local_state->HasPrefPath(prefs::kProfilesLastActive)) { | 392 if (local_state->HasPrefPath(prefs::kProfilesLastActive)) { |
395 const ListValue* profile_list = | 393 const ListValue* profile_list = |
396 local_state->GetList(prefs::kProfilesLastActive); | 394 local_state->GetList(prefs::kProfilesLastActive); |
397 if (profile_list) { | 395 if (profile_list) { |
398 ListValue::const_iterator it; | 396 ListValue::const_iterator it; |
399 std::string profile; | 397 std::string profile; |
400 for (it = profile_list->begin(); it != profile_list->end(); ++it) { | 398 for (it = profile_list->begin(); it != profile_list->end(); ++it) { |
401 if (!(*it)->GetAsString(&profile) || profile.empty()) { | 399 if (!(*it)->GetAsString(&profile) || profile.empty()) { |
402 LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; | 400 continue; |
Alexei Svitkine (slow)
2013/06/12 21:02:31
Nit: Indention looks wrong and inner loop shouldn'
noms (inactive)
2013/06/13 14:23:55
This is a rebase gone wrong. Same for the two abov
| |
403 continue; | |
404 } | 401 } |
405 to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile))); | 402 to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile))); |
406 } | 403 } |
407 } | 404 } |
408 } | 405 } |
409 return to_return; | 406 return to_return; |
410 } | 407 } |
411 | 408 |
412 Profile* ProfileManager::GetDefaultProfile( | 409 Profile* ProfileManager::GetDefaultProfile( |
413 const base::FilePath& user_data_dir) { | 410 const base::FilePath& user_data_dir) { |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 go_off_the_record = true; | 1033 go_off_the_record = true; |
1037 } | 1034 } |
1038 #endif | 1035 #endif |
1039 return go_off_the_record; | 1036 return go_off_the_record; |
1040 } | 1037 } |
1041 | 1038 |
1042 void ProfileManager::ScheduleProfileForDeletion( | 1039 void ProfileManager::ScheduleProfileForDeletion( |
1043 const base::FilePath& profile_dir, | 1040 const base::FilePath& profile_dir, |
1044 const CreateCallback& callback) { | 1041 const CreateCallback& callback) { |
1045 DCHECK(IsMultipleProfilesEnabled()); | 1042 DCHECK(IsMultipleProfilesEnabled()); |
1046 | |
1047 PrefService* local_state = g_browser_process->local_state(); | 1043 PrefService* local_state = g_browser_process->local_state(); |
1048 ProfileInfoCache& cache = GetProfileInfoCache(); | 1044 ProfileInfoCache& cache = GetProfileInfoCache(); |
1045 | |
1049 if (profile_dir.BaseName().MaybeAsASCII() == | 1046 if (profile_dir.BaseName().MaybeAsASCII() == |
1050 local_state->GetString(prefs::kProfileLastUsed)) { | 1047 local_state->GetString(prefs::kProfileLastUsed)) { |
1051 // Update the last used profile pref before closing browser windows. This | 1048 // Update the last used profile pref before closing browser windows. This |
1052 // way the correct last used profile is set for any notification observers. | 1049 // way the correct last used profile is set for any notification observers. |
1053 std::string last_non_managed_profile; | 1050 base::FilePath last_non_managed_profile_path; |
1054 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1051 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
1055 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1052 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
1056 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { | 1053 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { |
1057 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); | 1054 last_non_managed_profile_path = cur_path; |
1058 break; | 1055 break; |
1059 } | 1056 } |
1060 } | 1057 } |
1058 | |
1061 // If we're deleting the last (non-managed) profile, then create a new | 1059 // If we're deleting the last (non-managed) profile, then create a new |
1062 // profile in its place. | 1060 // profile in its place. |
1061 const std::string last_non_managed_profile = | |
1062 last_non_managed_profile_path.BaseName().MaybeAsASCII(); | |
1063 if (last_non_managed_profile.empty()) { | 1063 if (last_non_managed_profile.empty()) { |
1064 base::FilePath new_path = GenerateNextProfileDirectoryPath(); | 1064 base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
1065 // Make sure the last used profile path is pointing at it. This way the | 1065 // Make sure the last used profile path is pointing at it. This way the |
1066 // correct last used profile is set for any notification observers. | 1066 // correct last used profile is set for any notification observers. |
1067 local_state->SetString(prefs::kProfileLastUsed, | 1067 local_state->SetString(prefs::kProfileLastUsed, |
1068 new_path.BaseName().MaybeAsASCII()); | 1068 new_path.BaseName().MaybeAsASCII()); |
1069 CreateProfileAsync(new_path, | 1069 CreateProfileAsync(new_path, |
1070 callback, | 1070 callback, |
1071 string16(), | 1071 string16(), |
1072 string16(), | 1072 string16(), |
1073 false); | 1073 false); |
1074 } else { | 1074 } else { |
1075 // On the Mac, the browser process is not killed when all browser windows | |
sail
2013/06/12 21:16:49
Could we just implement this on all platforms?
noms (inactive)
2013/06/13 14:23:55
We could, but it would be a wasted operation -- on
sail
2013/06/13 14:33:50
Up to you.
There might be weird edge cases. For e
Alexei Svitkine (slow)
2013/06/13 14:48:00
Wouldn't any extension that's running still be run
| |
1076 // are closed, so just in case we are deleting the active profile, and no | |
1077 // other profile has been loaded, we must pre-load a next one. | |
1078 #if defined(OS_MACOSX) | |
1079 CreateProfileAsync(last_non_managed_profile_path, | |
1080 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | |
1081 base::Unretained(this), | |
1082 profile_dir, | |
1083 last_non_managed_profile, | |
1084 callback), | |
1085 string16(), | |
1086 string16(), | |
1087 false); | |
1088 return; | |
1089 #else | |
1090 // For OS_MACOSX the pref is updated in the callback | |
1091 // to make sure that it isn't used before the profile is actually loaded. | |
1075 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | 1092 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
1093 #endif | |
1076 } | 1094 } |
1077 } | 1095 } |
1096 FinishDeletingProfile(profile_dir); | |
1097 } | |
1078 | 1098 |
1099 void ProfileManager::OnNewActiveProfileLoaded( | |
1100 const base::FilePath& profile_to_delete_dir, | |
1101 const std::string& last_non_managed_profile, | |
1102 const CreateCallback& original_callback, | |
1103 Profile* loaded_profile, | |
1104 Profile::CreateStatus status) { | |
1105 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
1106 // Update the local state as promised in the ScheduleProfileForDeletion. | |
1107 PrefService* local_state = g_browser_process->local_state(); | |
1108 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | |
1109 FinishDeletingProfile(profile_to_delete_dir); | |
1110 } else if (status == Profile::CREATE_STATUS_LOCAL_FAIL || | |
1111 status == Profile::CREATE_STATUS_REMOTE_FAIL) { | |
1112 // This means that the profile we tried to load as the next active profile | |
1113 // has been deleted. Retry deleting this profile to redo the logic | |
1114 // and load the next available profile. | |
1115 ScheduleProfileForDeletion(profile_to_delete_dir, original_callback); | |
1116 } | |
1117 } | |
1118 | |
1119 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { | |
1120 ProfileInfoCache& cache = GetProfileInfoCache(); | |
1079 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1121 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
1080 // start deleting the profile instance we need to close background apps too. | 1122 // start deleting the profile instance we need to close background apps too. |
1081 Profile* profile = GetProfileByPath(profile_dir); | 1123 Profile* profile = GetProfileByPath(profile_dir); |
1124 | |
1082 if (profile) { | 1125 if (profile) { |
1083 BrowserList::CloseAllBrowsersWithProfile(profile); | 1126 BrowserList::CloseAllBrowsersWithProfile(profile); |
Alexei Svitkine (slow)
2013/06/12 21:02:31
Nit:Indention is wrong.
noms (inactive)
2013/06/13 20:56:25
Done.
| |
1084 | 1127 |
1085 // Disable sync for doomed profile. | 1128 // Disable sync for doomed profile. |
1086 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1129 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
1087 profile)) { | 1130 profile)) { |
1088 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1131 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
1089 profile)->DisableForUser(); | 1132 profile)->DisableForUser(); |
1090 } | 1133 } |
1091 } | 1134 } |
1092 | 1135 |
1093 QueueProfileDirectoryForDeletion(profile_dir); | 1136 QueueProfileDirectoryForDeletion(profile_dir); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 ProfileManager::ProfileInfo::ProfileInfo( | 1199 ProfileManager::ProfileInfo::ProfileInfo( |
1157 Profile* profile, | 1200 Profile* profile, |
1158 bool created) | 1201 bool created) |
1159 : profile(profile), | 1202 : profile(profile), |
1160 created(created) { | 1203 created(created) { |
1161 } | 1204 } |
1162 | 1205 |
1163 ProfileManager::ProfileInfo::~ProfileInfo() { | 1206 ProfileManager::ProfileInfo::~ProfileInfo() { |
1164 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1207 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1165 } | 1208 } |
OLD | NEW |