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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 } | 808 } |
809 } | 809 } |
810 | 810 |
811 void ProfileManager::Observe( | 811 void ProfileManager::Observe( |
812 int type, | 812 int type, |
813 const content::NotificationSource& source, | 813 const content::NotificationSource& source, |
814 const content::NotificationDetails& details) { | 814 const content::NotificationDetails& details) { |
815 #if defined(OS_CHROMEOS) | 815 #if defined(OS_CHROMEOS) |
816 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 816 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
817 logged_in_ = true; | 817 logged_in_ = true; |
818 // Find out what the current user is and update it. This has only to be done | |
819 // when the profile was already loaded, since otherwise this will be set by | |
820 // the profile loading process. | |
821 user_manager::UserManager* manager = user_manager::UserManager::Get(); | |
822 const user_manager::User* user = manager->GetActiveUser(); | |
823 if (user && user->is_profile_created()) { | |
824 UpdateLastUser( | |
825 chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user)); | |
Dmitry Polukhin
2014/09/08 09:51:53
I think you can use new safe version of the functi
Mr4D (OOO till 08-26)
2014/09/08 14:12:16
Done.
| |
826 } | |
818 | 827 |
819 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 828 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
820 if (!command_line.HasSwitch(switches::kTestType)) { | 829 if (!command_line.HasSwitch(switches::kTestType)) { |
821 // If we don't have a mounted profile directory we're in trouble. | 830 // If we don't have a mounted profile directory we're in trouble. |
822 // TODO(davemoore) Once we have better api this check should ensure that | 831 // TODO(davemoore) Once we have better api this check should ensure that |
823 // our profile directory is the one that's mounted, and that it's mounted | 832 // our profile directory is the one that's mounted, and that it's mounted |
824 // as the current user. | 833 // as the current user. |
825 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( | 834 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( |
826 base::Bind(&CheckCryptohomeIsMounted)); | 835 base::Bind(&CheckCryptohomeIsMounted)); |
827 | 836 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1196 return profile->IsGuestSession(); | 1205 return profile->IsGuestSession(); |
1197 } | 1206 } |
1198 | 1207 |
1199 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, | 1208 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, |
1200 Profile* profile, | 1209 Profile* profile, |
1201 Profile::CreateStatus status) { | 1210 Profile::CreateStatus status) { |
1202 for (size_t i = 0; i < callbacks.size(); ++i) | 1211 for (size_t i = 0; i < callbacks.size(); ++i) |
1203 callbacks[i].Run(profile, status); | 1212 callbacks[i].Run(profile, status); |
1204 } | 1213 } |
1205 | 1214 |
1215 void ProfileManager::UpdateLastUser(Profile* last_active) { | |
1216 PrefService* local_state = g_browser_process->local_state(); | |
1217 DCHECK(local_state); | |
1218 // Only keep track of profiles that we are managing; tests may create others. | |
1219 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { | |
1220 local_state->SetString(prefs::kProfileLastUsed, | |
1221 last_active->GetPath().BaseName().MaybeAsASCII()); | |
1222 | |
1223 ProfileInfoCache& cache = GetProfileInfoCache(); | |
1224 size_t profile_index = | |
1225 cache.GetIndexOfProfileWithPath(last_active->GetPath()); | |
1226 if (profile_index != std::string::npos) | |
1227 cache.SetProfileActiveTimeAtIndex(profile_index); | |
1228 } | |
1229 } | |
1230 | |
1206 ProfileManager::ProfileInfo::ProfileInfo( | 1231 ProfileManager::ProfileInfo::ProfileInfo( |
1207 Profile* profile, | 1232 Profile* profile, |
1208 bool created) | 1233 bool created) |
1209 : profile(profile), | 1234 : profile(profile), |
1210 created(created) { | 1235 created(created) { |
1211 } | 1236 } |
1212 | 1237 |
1213 ProfileManager::ProfileInfo::~ProfileInfo() { | 1238 ProfileManager::ProfileInfo::~ProfileInfo() { |
1214 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1239 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1215 } | 1240 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 if (profile_manager_->closing_all_browsers_) | 1281 if (profile_manager_->closing_all_browsers_) |
1257 return; | 1282 return; |
1258 | 1283 |
1259 Profile* last_active = browser->profile(); | 1284 Profile* last_active = browser->profile(); |
1260 | 1285 |
1261 // Don't remember ephemeral profiles as last because they are not going to | 1286 // Don't remember ephemeral profiles as last because they are not going to |
1262 // persist after restart. | 1287 // persist after restart. |
1263 if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) | 1288 if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) |
1264 return; | 1289 return; |
1265 | 1290 |
1266 PrefService* local_state = g_browser_process->local_state(); | 1291 profile_manager_->UpdateLastUser(last_active); |
1267 DCHECK(local_state); | |
1268 // Only keep track of profiles that we are managing; tests may create others. | |
1269 if (profile_manager_->profiles_info_.find( | |
1270 last_active->GetPath()) != profile_manager_->profiles_info_.end()) { | |
1271 local_state->SetString(prefs::kProfileLastUsed, | |
1272 last_active->GetPath().BaseName().MaybeAsASCII()); | |
1273 | |
1274 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | |
1275 size_t profile_index = | |
1276 cache.GetIndexOfProfileWithPath(last_active->GetPath()); | |
1277 if (profile_index != std::string::npos) | |
1278 cache.SetProfileActiveTimeAtIndex(profile_index); | |
1279 } | |
1280 } | 1292 } |
1281 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 1293 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
1282 | 1294 |
1283 #if defined(OS_MACOSX) | 1295 #if defined(OS_MACOSX) |
1284 void ProfileManager::OnNewActiveProfileLoaded( | 1296 void ProfileManager::OnNewActiveProfileLoaded( |
1285 const base::FilePath& profile_to_delete_path, | 1297 const base::FilePath& profile_to_delete_path, |
1286 const base::FilePath& last_non_supervised_profile_path, | 1298 const base::FilePath& last_non_supervised_profile_path, |
1287 const CreateCallback& original_callback, | 1299 const CreateCallback& original_callback, |
1288 Profile* loaded_profile, | 1300 Profile* loaded_profile, |
1289 Profile::CreateStatus status) { | 1301 Profile::CreateStatus status) { |
(...skipping 14 matching lines...) Expand all Loading... | |
1304 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); | 1316 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); |
1305 FinishDeletingProfile(profile_to_delete_path); | 1317 FinishDeletingProfile(profile_to_delete_path); |
1306 } | 1318 } |
1307 } | 1319 } |
1308 } | 1320 } |
1309 #endif | 1321 #endif |
1310 | 1322 |
1311 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1323 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1312 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1324 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1313 } | 1325 } |
OLD | NEW |