OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromeos/login/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 UserManagerImpl::~UserManagerImpl() { | 204 UserManagerImpl::~UserManagerImpl() { |
205 // Can't use STLDeleteElements because of the private destructor of User. | 205 // Can't use STLDeleteElements because of the private destructor of User. |
206 for (UserList::iterator it = users_.begin(); it != users_.end(); | 206 for (UserList::iterator it = users_.begin(); it != users_.end(); |
207 it = users_.erase(it)) { | 207 it = users_.erase(it)) { |
208 if (active_user_ == *it) | 208 if (active_user_ == *it) |
209 active_user_ = NULL; | 209 active_user_ = NULL; |
210 delete *it; | 210 delete *it; |
211 } | 211 } |
212 // These are pointers to the same User instances that were in users_ list. | 212 // These are pointers to the same User instances that were in users_ list. |
213 logged_in_users_.clear(); | 213 logged_in_users_.clear(); |
| 214 lru_logged_in_users_.clear(); |
| 215 |
214 delete active_user_; | 216 delete active_user_; |
215 } | 217 } |
216 | 218 |
217 void UserManagerImpl::Shutdown() { | 219 void UserManagerImpl::Shutdown() { |
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
219 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, | 221 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, |
220 this); | 222 this); |
221 // Stop the session length limiter. | 223 // Stop the session length limiter. |
222 session_length_limiter_.reset(); | 224 session_length_limiter_.reset(); |
223 | 225 |
224 if (device_local_account_policy_service_) | 226 if (device_local_account_policy_service_) |
225 device_local_account_policy_service_->RemoveObserver(this); | 227 device_local_account_policy_service_->RemoveObserver(this); |
226 } | 228 } |
227 | 229 |
228 UserImageManager* UserManagerImpl::GetUserImageManager() { | 230 UserImageManager* UserManagerImpl::GetUserImageManager() { |
229 return user_image_manager_.get(); | 231 return user_image_manager_.get(); |
230 } | 232 } |
231 | 233 |
232 const UserList& UserManagerImpl::GetUsers() const { | 234 const UserList& UserManagerImpl::GetUsers() const { |
233 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); | 235 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); |
234 return users_; | 236 return users_; |
235 } | 237 } |
236 | 238 |
237 const UserList& UserManagerImpl::GetLoggedInUsers() const { | 239 const UserList& UserManagerImpl::GetLoggedInUsers() const { |
238 return logged_in_users_; | 240 return logged_in_users_; |
239 } | 241 } |
240 | 242 |
| 243 const UserList& UserManagerImpl::GetLRULoggedInUsers() { |
| 244 // If there is no user logged in, we return the active user as the only one. |
| 245 if (lru_logged_in_users_.empty() && active_user_) { |
| 246 temp_single_logged_in_users_.clear(); |
| 247 temp_single_logged_in_users_.insert(temp_single_logged_in_users_.begin(), |
| 248 active_user_); |
| 249 return temp_single_logged_in_users_; |
| 250 } |
| 251 return lru_logged_in_users_; |
| 252 } |
| 253 |
241 void UserManagerImpl::UserLoggedIn(const std::string& email, | 254 void UserManagerImpl::UserLoggedIn(const std::string& email, |
242 const std::string& username_hash, | 255 const std::string& username_hash, |
243 bool browser_restart) { | 256 bool browser_restart) { |
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
245 | 258 |
246 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) | 259 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) |
247 DCHECK(!IsUserLoggedIn()); | 260 DCHECK(!IsUserLoggedIn()); |
248 | 261 |
249 if (active_user_) | 262 if (active_user_) |
250 active_user_->set_is_active(false); | 263 active_user_->set_is_active(false); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 session_length_limiter_.reset(new SessionLengthLimiter(NULL, | 295 session_length_limiter_.reset(new SessionLengthLimiter(NULL, |
283 browser_restart)); | 296 browser_restart)); |
284 } | 297 } |
285 DCHECK(active_user_); | 298 DCHECK(active_user_); |
286 active_user_->set_is_logged_in(true); | 299 active_user_->set_is_logged_in(true); |
287 active_user_->set_is_active(true); | 300 active_user_->set_is_active(true); |
288 active_user_->set_username_hash(username_hash); | 301 active_user_->set_username_hash(username_hash); |
289 | 302 |
290 // Place user who just signed in to the top of the logged in users. | 303 // Place user who just signed in to the top of the logged in users. |
291 logged_in_users_.insert(logged_in_users_.begin(), active_user_); | 304 logged_in_users_.insert(logged_in_users_.begin(), active_user_); |
| 305 SetLRUUser(active_user_); |
292 | 306 |
293 NotifyOnLogin(); | 307 NotifyOnLogin(); |
294 } | 308 } |
295 | 309 |
296 void UserManagerImpl::SwitchActiveUser(const std::string& email) { | 310 void UserManagerImpl::SwitchActiveUser(const std::string& email) { |
297 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) | 311 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) |
298 return; | 312 return; |
299 | 313 |
300 User* user = FindUserAndModify(email); | 314 User* user = FindUserAndModify(email); |
301 if (!user) { | 315 if (!user) { |
(...skipping 15 matching lines...) Expand all Loading... |
317 if (user->username_hash().empty()) { | 331 if (user->username_hash().empty()) { |
318 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; | 332 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; |
319 return; | 333 return; |
320 } | 334 } |
321 | 335 |
322 DCHECK(active_user_); | 336 DCHECK(active_user_); |
323 active_user_->set_is_active(false); | 337 active_user_->set_is_active(false); |
324 user->set_is_active(true); | 338 user->set_is_active(true); |
325 active_user_ = user; | 339 active_user_ = user; |
326 | 340 |
| 341 // Move the user to the front. |
| 342 SetLRUUser(active_user_); |
| 343 |
327 NotifyActiveUserHashChanged(active_user_->username_hash()); | 344 NotifyActiveUserHashChanged(active_user_->username_hash()); |
328 | 345 |
329 // TODO(nkostylev): Notify session_manager on active user change. | 346 // TODO(nkostylev): Notify session_manager on active user change. |
330 // http://crbug.com/230857 | 347 // http://crbug.com/230857 |
331 content::NotificationService::current()->Notify( | 348 content::NotificationService::current()->Notify( |
332 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, | 349 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, |
333 content::Source<UserManager>(this), | 350 content::Source<UserManager>(this), |
334 content::Details<const User>(active_user_)); | 351 content::Details<const User>(active_user_)); |
335 } | 352 } |
336 | 353 |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 } | 1518 } |
1502 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP: | 1519 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP: |
1503 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the | 1520 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the |
1504 // standard login framework: http://crbug.com/234694 | 1521 // standard login framework: http://crbug.com/234694 |
1505 break; | 1522 break; |
1506 } | 1523 } |
1507 } | 1524 } |
1508 } | 1525 } |
1509 } | 1526 } |
1510 | 1527 |
| 1528 void UserManagerImpl::SetLRUUser(User* user) { |
| 1529 UserList::iterator it = std::find(lru_logged_in_users_.begin(), |
| 1530 lru_logged_in_users_.end(), |
| 1531 user); |
| 1532 if (it != lru_logged_in_users_.end()) |
| 1533 lru_logged_in_users_.erase(it); |
| 1534 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
| 1535 } |
| 1536 |
1511 } // namespace chromeos | 1537 } // namespace chromeos |
OLD | NEW |