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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 go_off_the_record = true; | 1036 go_off_the_record = true; |
1037 } | 1037 } |
1038 #endif | 1038 #endif |
1039 return go_off_the_record; | 1039 return go_off_the_record; |
1040 } | 1040 } |
1041 | 1041 |
1042 void ProfileManager::ScheduleProfileForDeletion( | 1042 void ProfileManager::ScheduleProfileForDeletion( |
1043 const base::FilePath& profile_dir, | 1043 const base::FilePath& profile_dir, |
1044 const CreateCallback& callback) { | 1044 const CreateCallback& callback) { |
1045 DCHECK(IsMultipleProfilesEnabled()); | 1045 DCHECK(IsMultipleProfilesEnabled()); |
1046 | |
1047 PrefService* local_state = g_browser_process->local_state(); | 1046 PrefService* local_state = g_browser_process->local_state(); |
1048 ProfileInfoCache& cache = GetProfileInfoCache(); | 1047 ProfileInfoCache& cache = GetProfileInfoCache(); |
1048 | |
1049 if (profile_dir.BaseName().MaybeAsASCII() == | 1049 if (profile_dir.BaseName().MaybeAsASCII() == |
1050 local_state->GetString(prefs::kProfileLastUsed)) { | 1050 local_state->GetString(prefs::kProfileLastUsed)) { |
1051 // Update the last used profile pref before closing browser windows. This | 1051 // Update the last used profile pref before closing browser windows. This |
1052 // way the correct last used profile is set for any notification observers. | 1052 // way the correct last used profile is set for any notification observers. |
1053 std::string last_non_managed_profile; | 1053 base::FilePath last_non_managed_profile_path; |
1054 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1054 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
1055 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1055 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
1056 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { | 1056 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { |
1057 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); | 1057 last_non_managed_profile_path = cur_path; |
1058 break; | 1058 break; |
1059 } | 1059 } |
1060 } | 1060 } |
1061 | |
1061 // If we're deleting the last (non-managed) profile, then create a new | 1062 // If we're deleting the last (non-managed) profile, then create a new |
1062 // profile in its place. | 1063 // profile in its place. |
1064 const std::string last_non_managed_profile = | |
1065 last_non_managed_profile_path.BaseName().MaybeAsASCII(); | |
1063 if (last_non_managed_profile.empty()) { | 1066 if (last_non_managed_profile.empty()) { |
1064 base::FilePath new_path = GenerateNextProfileDirectoryPath(); | 1067 base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
1065 // Make sure the last used profile path is pointing at it. This way the | 1068 // 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. | 1069 // correct last used profile is set for any notification observers. |
1067 local_state->SetString(prefs::kProfileLastUsed, | 1070 local_state->SetString(prefs::kProfileLastUsed, |
1068 new_path.BaseName().MaybeAsASCII()); | 1071 new_path.BaseName().MaybeAsASCII()); |
1069 CreateProfileAsync(new_path, | 1072 CreateProfileAsync(new_path, |
1070 callback, | 1073 callback, |
1071 string16(), | 1074 string16(), |
1072 string16(), | 1075 string16(), |
1073 false); | 1076 false); |
1074 } else { | 1077 } else { |
1078 // On the Mac, the browser process is not killed when all browser windows | |
1079 // are closed, so just in case we are deleting the active profile, and no | |
1080 // other profile has been loaded, we must pre-load a next one. | |
1081 #if defined(OS_MACOSX) | |
1082 CreateProfileAsync(last_non_managed_profile_path, | |
1083 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | |
1084 base::Unretained(this), | |
1085 profile_dir, | |
1086 last_non_managed_profile, | |
1087 callback), | |
1088 string16(), | |
1089 string16(), | |
1090 false); | |
1091 return; | |
1092 #else | |
1093 // For OS_MACOSX the pref is updated in the callback | |
Alexei Svitkine (slow)
2013/06/14 22:04:58
Nit: comment wrapping is weird
noms (inactive)
2013/06/18 21:38:11
Done.
| |
1094 // to make sure that it isn't used before the profile is actually loaded. | |
1075 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | 1095 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
1096 #endif | |
1076 } | 1097 } |
1077 } | 1098 } |
1099 FinishDeletingProfile(profile_dir); | |
1100 } | |
1078 | 1101 |
1102 void ProfileManager::OnNewActiveProfileLoaded( | |
1103 const base::FilePath& profile_to_delete_dir, | |
1104 const std::string& last_non_managed_profile, | |
1105 const CreateCallback& original_callback, | |
1106 Profile* loaded_profile, | |
1107 Profile::CreateStatus status) { | |
1108 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
1109 // Update the local state as promised in the ScheduleProfileForDeletion. | |
1110 PrefService* local_state = g_browser_process->local_state(); | |
1111 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | |
1112 FinishDeletingProfile(profile_to_delete_dir); | |
1113 } else if (status == Profile::CREATE_STATUS_LOCAL_FAIL || | |
1114 status == Profile::CREATE_STATUS_REMOTE_FAIL) { | |
1115 // This means that the profile we tried to load as the next active profile | |
1116 // has been deleted. Retry deleting this profile to redo the logic | |
1117 // and load the next available profile. | |
1118 ScheduleProfileForDeletion(profile_to_delete_dir, original_callback); | |
1119 } | |
1120 } | |
1121 | |
1122 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { | |
1123 ProfileInfoCache& cache = GetProfileInfoCache(); | |
1079 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1124 // 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. | 1125 // start deleting the profile instance we need to close background apps too. |
1081 Profile* profile = GetProfileByPath(profile_dir); | 1126 Profile* profile = GetProfileByPath(profile_dir); |
1127 | |
1082 if (profile) { | 1128 if (profile) { |
1083 BrowserList::CloseAllBrowsersWithProfile(profile); | 1129 BrowserList::CloseAllBrowsersWithProfile(profile); |
1084 | 1130 |
1085 // Disable sync for doomed profile. | 1131 // Disable sync for doomed profile. |
1086 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1132 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
1087 profile)) { | 1133 profile)) { |
1088 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1134 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
1089 profile)->DisableForUser(); | 1135 profile)->DisableForUser(); |
1090 } | 1136 } |
1091 } | 1137 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 ProfileManager::ProfileInfo::ProfileInfo( | 1202 ProfileManager::ProfileInfo::ProfileInfo( |
1157 Profile* profile, | 1203 Profile* profile, |
1158 bool created) | 1204 bool created) |
1159 : profile(profile), | 1205 : profile(profile), |
1160 created(created) { | 1206 created(created) { |
1161 } | 1207 } |
1162 | 1208 |
1163 ProfileManager::ProfileInfo::~ProfileInfo() { | 1209 ProfileManager::ProfileInfo::~ProfileInfo() { |
1164 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1210 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1165 } | 1211 } |
OLD | NEW |