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 // Make sure that this profile is not pending deletion. |
1057 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); | 1057 bool is_marked_for_deletion = std::find(ProfilesToDelete().begin(), |
1058 ProfilesToDelete().end(), cur_path) != ProfilesToDelete().end(); | |
Alexei Svitkine (slow)
2013/06/18 21:45:57
Can you make a helper function for this, since it'
noms (inactive)
2013/06/18 22:19:56
Done.
| |
1059 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i) && | |
1060 !is_marked_for_deletion) { | |
1061 last_non_managed_profile_path = cur_path; | |
1058 break; | 1062 break; |
1059 } | 1063 } |
1060 } | 1064 } |
1065 | |
1061 // If we're deleting the last (non-managed) profile, then create a new | 1066 // If we're deleting the last (non-managed) profile, then create a new |
1062 // profile in its place. | 1067 // profile in its place. |
1068 const std::string last_non_managed_profile = | |
1069 last_non_managed_profile_path.BaseName().MaybeAsASCII(); | |
1063 if (last_non_managed_profile.empty()) { | 1070 if (last_non_managed_profile.empty()) { |
1064 base::FilePath new_path = GenerateNextProfileDirectoryPath(); | 1071 base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
1065 // Make sure the last used profile path is pointing at it. This way the | 1072 // 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. | 1073 // correct last used profile is set for any notification observers. |
1067 local_state->SetString(prefs::kProfileLastUsed, | 1074 local_state->SetString(prefs::kProfileLastUsed, |
1068 new_path.BaseName().MaybeAsASCII()); | 1075 new_path.BaseName().MaybeAsASCII()); |
1069 CreateProfileAsync(new_path, | 1076 CreateProfileAsync(new_path, |
1070 callback, | 1077 callback, |
1071 string16(), | 1078 string16(), |
1072 string16(), | 1079 string16(), |
1073 false); | 1080 false); |
1074 } else { | 1081 } else { |
1082 // On the Mac, the browser process is not killed when all browser windows | |
1083 // are closed, so just in case we are deleting the active profile, and no | |
1084 // other profile has been loaded, we must pre-load a next one. | |
1085 #if defined(OS_MACOSX) | |
1086 CreateProfileAsync(last_non_managed_profile_path, | |
1087 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | |
1088 base::Unretained(this), | |
1089 profile_dir, | |
1090 last_non_managed_profile, | |
1091 last_non_managed_profile_path, | |
1092 callback), | |
1093 string16(), | |
1094 string16(), | |
1095 false); | |
1096 return; | |
1097 #else | |
1098 // For OS_MACOSX the pref is updated in the callback to make sure that | |
1099 // it isn't used before the profile is actually loaded. | |
1075 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | 1100 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
1101 #endif | |
1076 } | 1102 } |
1077 } | 1103 } |
1104 FinishDeletingProfile(profile_dir); | |
1105 } | |
1078 | 1106 |
1107 void ProfileManager::OnNewActiveProfileLoaded( | |
1108 const base::FilePath& profile_to_delete_dir, | |
1109 const std::string& last_non_managed_profile, | |
1110 const base::FilePath& last_non_managed_profile_path, | |
Alexei Svitkine (slow)
2013/06/18 21:45:57
Now that you have this, can you remove the redunda
noms (inactive)
2013/06/18 22:19:56
Done.
| |
1111 const CreateCallback& original_callback, | |
1112 Profile* loaded_profile, | |
1113 Profile::CreateStatus status) { | |
1114 | |
Alexei Svitkine (slow)
2013/06/18 21:45:57
Nit: No empty line here.
noms (inactive)
2013/06/18 22:19:56
Done.
| |
1115 // Only run the code if the profile initialization has finished completely | |
1116 // (either completed successfully, or has failed). | |
1117 if (status != Profile::CREATE_STATUS_CREATED) { | |
Alexei Svitkine (slow)
2013/06/18 21:45:57
Please check specific statuses rather than not a s
noms (inactive)
2013/06/18 22:19:56
Done.
| |
1118 if (std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(), | |
1119 last_non_managed_profile_path) != ProfilesToDelete().end()) { | |
1120 // If the profile we tried to load as the next active profile has been | |
1121 // deleted, then retry deleting this profile to redo the logic and load | |
1122 // the next available profile. | |
1123 ScheduleProfileForDeletion(profile_to_delete_dir, original_callback); | |
1124 } else { | |
1125 // Update the local state as promised in the ScheduleProfileForDeletion. | |
1126 g_browser_process->local_state()->SetString( | |
1127 prefs::kProfileLastUsed, last_non_managed_profile); | |
1128 FinishDeletingProfile(profile_to_delete_dir); | |
1129 } | |
1130 } | |
1131 } | |
1132 | |
1133 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { | |
1134 ProfileInfoCache& cache = GetProfileInfoCache(); | |
1079 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1135 // 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. | 1136 // start deleting the profile instance we need to close background apps too. |
1081 Profile* profile = GetProfileByPath(profile_dir); | 1137 Profile* profile = GetProfileByPath(profile_dir); |
1138 | |
1082 if (profile) { | 1139 if (profile) { |
1083 BrowserList::CloseAllBrowsersWithProfile(profile); | 1140 BrowserList::CloseAllBrowsersWithProfile(profile); |
1084 | 1141 |
1085 // Disable sync for doomed profile. | 1142 // Disable sync for doomed profile. |
1086 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1143 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
1087 profile)) { | 1144 profile)) { |
1088 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1145 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
1089 profile)->DisableForUser(); | 1146 profile)->DisableForUser(); |
1090 } | 1147 } |
1091 } | 1148 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 ProfileManager::ProfileInfo::ProfileInfo( | 1213 ProfileManager::ProfileInfo::ProfileInfo( |
1157 Profile* profile, | 1214 Profile* profile, |
1158 bool created) | 1215 bool created) |
1159 : profile(profile), | 1216 : profile(profile), |
1160 created(created) { | 1217 created(created) { |
1161 } | 1218 } |
1162 | 1219 |
1163 ProfileManager::ProfileInfo::~ProfileInfo() { | 1220 ProfileManager::ProfileInfo::~ProfileInfo() { |
1164 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1221 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1165 } | 1222 } |
OLD | NEW |