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 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 } | 810 } |
811 } | 811 } |
812 | 812 |
813 void ProfileManager::Observe( | 813 void ProfileManager::Observe( |
814 int type, | 814 int type, |
815 const content::NotificationSource& source, | 815 const content::NotificationSource& source, |
816 const content::NotificationDetails& details) { | 816 const content::NotificationDetails& details) { |
817 #if defined(OS_CHROMEOS) | 817 #if defined(OS_CHROMEOS) |
818 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 818 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
819 logged_in_ = true; | 819 logged_in_ = true; |
| 820 // Find out what the current user is and update it. This has only to be done |
| 821 // when the profile was already loaded, since otherwise this will be set by |
| 822 // the profile loading process. |
| 823 user_manager::UserManager* manager = user_manager::UserManager::Get(); |
| 824 const user_manager::User* user = manager->GetActiveUser(); |
| 825 if (user && user->is_profile_created()) { |
| 826 UpdateLastUser( |
| 827 chromeos::ProfileHelper::Get()->GetProfileByUser(user)); |
| 828 } |
820 | 829 |
821 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 830 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
822 if (!command_line.HasSwitch(switches::kTestType)) { | 831 if (!command_line.HasSwitch(switches::kTestType)) { |
823 // If we don't have a mounted profile directory we're in trouble. | 832 // If we don't have a mounted profile directory we're in trouble. |
824 // TODO(davemoore) Once we have better api this check should ensure that | 833 // TODO(davemoore) Once we have better api this check should ensure that |
825 // our profile directory is the one that's mounted, and that it's mounted | 834 // our profile directory is the one that's mounted, and that it's mounted |
826 // as the current user. | 835 // as the current user. |
827 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( | 836 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( |
828 base::Bind(&CheckCryptohomeIsMounted)); | 837 base::Bind(&CheckCryptohomeIsMounted)); |
829 | 838 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 bool created) | 1219 bool created) |
1211 : profile(profile), | 1220 : profile(profile), |
1212 created(created) { | 1221 created(created) { |
1213 } | 1222 } |
1214 | 1223 |
1215 ProfileManager::ProfileInfo::~ProfileInfo() { | 1224 ProfileManager::ProfileInfo::~ProfileInfo() { |
1216 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1225 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1217 } | 1226 } |
1218 | 1227 |
1219 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 1228 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 1229 void ProfileManager::UpdateLastUser(Profile* last_active) { |
| 1230 PrefService* local_state = g_browser_process->local_state(); |
| 1231 DCHECK(local_state); |
| 1232 // Only keep track of profiles that we are managing; tests may create others. |
| 1233 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { |
| 1234 local_state->SetString(prefs::kProfileLastUsed, |
| 1235 last_active->GetPath().BaseName().MaybeAsASCII()); |
| 1236 |
| 1237 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 1238 size_t profile_index = |
| 1239 cache.GetIndexOfProfileWithPath(last_active->GetPath()); |
| 1240 if (profile_index != std::string::npos) |
| 1241 cache.SetProfileActiveTimeAtIndex(profile_index); |
| 1242 } |
| 1243 } |
| 1244 |
1220 ProfileManager::BrowserListObserver::BrowserListObserver( | 1245 ProfileManager::BrowserListObserver::BrowserListObserver( |
1221 ProfileManager* manager) | 1246 ProfileManager* manager) |
1222 : profile_manager_(manager) { | 1247 : profile_manager_(manager) { |
1223 BrowserList::AddObserver(this); | 1248 BrowserList::AddObserver(this); |
1224 } | 1249 } |
1225 | 1250 |
1226 ProfileManager::BrowserListObserver::~BrowserListObserver() { | 1251 ProfileManager::BrowserListObserver::~BrowserListObserver() { |
1227 BrowserList::RemoveObserver(this); | 1252 BrowserList::RemoveObserver(this); |
1228 } | 1253 } |
1229 | 1254 |
(...skipping 28 matching lines...) Expand all Loading... |
1258 if (profile_manager_->closing_all_browsers_) | 1283 if (profile_manager_->closing_all_browsers_) |
1259 return; | 1284 return; |
1260 | 1285 |
1261 Profile* last_active = browser->profile(); | 1286 Profile* last_active = browser->profile(); |
1262 | 1287 |
1263 // Don't remember ephemeral profiles as last because they are not going to | 1288 // Don't remember ephemeral profiles as last because they are not going to |
1264 // persist after restart. | 1289 // persist after restart. |
1265 if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) | 1290 if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) |
1266 return; | 1291 return; |
1267 | 1292 |
1268 PrefService* local_state = g_browser_process->local_state(); | 1293 profile_manager_->UpdateLastUser(last_active); |
1269 DCHECK(local_state); | |
1270 // Only keep track of profiles that we are managing; tests may create others. | |
1271 if (profile_manager_->profiles_info_.find( | |
1272 last_active->GetPath()) != profile_manager_->profiles_info_.end()) { | |
1273 local_state->SetString(prefs::kProfileLastUsed, | |
1274 last_active->GetPath().BaseName().MaybeAsASCII()); | |
1275 | |
1276 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | |
1277 size_t profile_index = | |
1278 cache.GetIndexOfProfileWithPath(last_active->GetPath()); | |
1279 if (profile_index != std::string::npos) | |
1280 cache.SetProfileActiveTimeAtIndex(profile_index); | |
1281 } | |
1282 } | 1294 } |
1283 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 1295 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
1284 | 1296 |
1285 #if defined(OS_MACOSX) | 1297 #if defined(OS_MACOSX) |
1286 void ProfileManager::OnNewActiveProfileLoaded( | 1298 void ProfileManager::OnNewActiveProfileLoaded( |
1287 const base::FilePath& profile_to_delete_path, | 1299 const base::FilePath& profile_to_delete_path, |
1288 const base::FilePath& last_non_supervised_profile_path, | 1300 const base::FilePath& last_non_supervised_profile_path, |
1289 const CreateCallback& original_callback, | 1301 const CreateCallback& original_callback, |
1290 Profile* loaded_profile, | 1302 Profile* loaded_profile, |
1291 Profile::CreateStatus status) { | 1303 Profile::CreateStatus status) { |
(...skipping 14 matching lines...) Expand all Loading... |
1306 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); | 1318 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); |
1307 FinishDeletingProfile(profile_to_delete_path); | 1319 FinishDeletingProfile(profile_to_delete_path); |
1308 } | 1320 } |
1309 } | 1321 } |
1310 } | 1322 } |
1311 #endif | 1323 #endif |
1312 | 1324 |
1313 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1325 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1314 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1326 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1315 } | 1327 } |
OLD | NEW |