Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 14756019: Adding new user menu section to the SystemTrayMenu & refactoring of user access (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include <vector> 9 #include <vector>
10 10
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 UserManagerImpl::~UserManagerImpl() { 214 UserManagerImpl::~UserManagerImpl() {
215 // Can't use STLDeleteElements because of the private destructor of User. 215 // Can't use STLDeleteElements because of the private destructor of User.
216 for (UserList::iterator it = users_.begin(); it != users_.end(); 216 for (UserList::iterator it = users_.begin(); it != users_.end();
217 it = users_.erase(it)) { 217 it = users_.erase(it)) {
218 if (active_user_ == *it) 218 if (active_user_ == *it)
219 active_user_ = NULL; 219 active_user_ = NULL;
220 delete *it; 220 delete *it;
221 } 221 }
222 // These are pointers to the same User instances that were in users_ list. 222 // These are pointers to the same User instances that were in users_ list.
223 logged_in_users_.clear(); 223 logged_in_users_.clear();
224 lru_logged_in_users_.clear();
225
224 delete active_user_; 226 delete active_user_;
225 } 227 }
226 228
227 void UserManagerImpl::Shutdown() { 229 void UserManagerImpl::Shutdown() {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
229 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, 231 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts,
230 this); 232 this);
231 // Stop the session length limiter. 233 // Stop the session length limiter.
232 session_length_limiter_.reset(); 234 session_length_limiter_.reset();
233 235
234 if (device_local_account_policy_service_) 236 if (device_local_account_policy_service_)
235 device_local_account_policy_service_->RemoveObserver(this); 237 device_local_account_policy_service_->RemoveObserver(this);
236 } 238 }
237 239
238 UserImageManager* UserManagerImpl::GetUserImageManager() { 240 UserImageManager* UserManagerImpl::GetUserImageManager() {
239 return user_image_manager_.get(); 241 return user_image_manager_.get();
240 } 242 }
241 243
242 const UserList& UserManagerImpl::GetUsers() const { 244 const UserList& UserManagerImpl::GetUsers() const {
243 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 245 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
244 return users_; 246 return users_;
245 } 247 }
246 248
247 const UserList& UserManagerImpl::GetLoggedInUsers() const { 249 const UserList& UserManagerImpl::GetLoggedInUsers() const {
248 return logged_in_users_; 250 return logged_in_users_;
249 } 251 }
250 252
253 const UserList& UserManagerImpl::GetLRULoggedInUsers() {
254 // If there is no user logged in, we return the active user as the only one.
255 if (lru_logged_in_users_.empty() && active_user_) {
256 temp_single_logged_in_users_.clear();
Nikita (slow) 2013/05/17 17:00:32 Why not use the same lru_logged_in_users_?
Mr4D (OOO till 08-26) 2013/05/17 18:45:09 Because as I was looking at the code it appears th
Nikita (slow) 2013/05/17 19:15:47 When does this happen?
Mr4D (OOO till 08-26) 2013/05/17 20:04:43 Okay, let's address that then with the second patc
257 temp_single_logged_in_users_.insert(temp_single_logged_in_users_.begin(),
258 active_user_);
259 return temp_single_logged_in_users_;
260 }
261 return lru_logged_in_users_;
262 }
263
251 void UserManagerImpl::UserLoggedIn(const std::string& email, 264 void UserManagerImpl::UserLoggedIn(const std::string& email,
252 const std::string& username_hash, 265 const std::string& username_hash,
253 bool browser_restart) { 266 bool browser_restart) {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
255 268
256 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) 269 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
257 DCHECK(!IsUserLoggedIn()); 270 DCHECK(!IsUserLoggedIn());
258 271
259 if (active_user_) 272 if (active_user_)
260 active_user_->set_is_active(false); 273 active_user_->set_is_active(false);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 session_length_limiter_.reset(new SessionLengthLimiter(NULL, 305 session_length_limiter_.reset(new SessionLengthLimiter(NULL,
293 browser_restart)); 306 browser_restart));
294 } 307 }
295 DCHECK(active_user_); 308 DCHECK(active_user_);
296 active_user_->set_is_logged_in(true); 309 active_user_->set_is_logged_in(true);
297 active_user_->set_is_active(true); 310 active_user_->set_is_active(true);
298 active_user_->set_username_hash(username_hash); 311 active_user_->set_username_hash(username_hash);
299 312
300 // Place user who just signed in to the top of the logged in users. 313 // Place user who just signed in to the top of the logged in users.
301 logged_in_users_.insert(logged_in_users_.begin(), active_user_); 314 logged_in_users_.insert(logged_in_users_.begin(), active_user_);
315 SetLRUUser(active_user_);
302 316
303 NotifyOnLogin(); 317 NotifyOnLogin();
304 } 318 }
305 319
306 void UserManagerImpl::SwitchActiveUser(const std::string& email) { 320 void UserManagerImpl::SwitchActiveUser(const std::string& email) {
307 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) 321 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
308 return; 322 return;
309 323
310 User* user = FindUserAndModify(email); 324 User* user = FindUserAndModify(email);
311 if (!user) { 325 if (!user) {
(...skipping 15 matching lines...) Expand all
327 if (user->username_hash().empty()) { 341 if (user->username_hash().empty()) {
328 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; 342 NOTREACHED() << "Switching to a user that doesn't have username_hash set";
329 return; 343 return;
330 } 344 }
331 345
332 DCHECK(active_user_); 346 DCHECK(active_user_);
333 active_user_->set_is_active(false); 347 active_user_->set_is_active(false);
334 user->set_is_active(true); 348 user->set_is_active(true);
335 active_user_ = user; 349 active_user_ = user;
336 350
351 // Move the user to the front.
352 SetLRUUser(active_user_);
353
337 NotifyActiveUserHashChanged(active_user_->username_hash()); 354 NotifyActiveUserHashChanged(active_user_->username_hash());
338 355
339 // TODO(nkostylev): Notify session_manager on active user change. 356 // TODO(nkostylev): Notify session_manager on active user change.
340 // http://crbug.com/230857 357 // http://crbug.com/230857
341 content::NotificationService::current()->Notify( 358 content::NotificationService::current()->Notify(
342 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, 359 chrome::NOTIFICATION_ACTIVE_USER_CHANGED,
343 content::Source<UserManager>(this), 360 content::Source<UserManager>(this),
344 content::Details<const User>(active_user_)); 361 content::Details<const User>(active_user_));
345 } 362 }
346 363
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 SaveUserDisplayName(active_user_->email(), 1020 SaveUserDisplayName(active_user_->email(),
1004 UTF8ToUTF16(active_user_->GetAccountName(true))); 1021 UTF8ToUTF16(active_user_->GetAccountName(true)));
1005 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); 1022 WallpaperManager::Get()->SetInitialUserWallpaper(email, true);
1006 } 1023 }
1007 1024
1008 // Add the user to the front of the user list. 1025 // Add the user to the front of the user list.
1009 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), 1026 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
1010 kRegularUsers); 1027 kRegularUsers);
1011 prefs_users_update->Insert(0, new base::StringValue(email)); 1028 prefs_users_update->Insert(0, new base::StringValue(email));
1012 users_.insert(users_.begin(), active_user_); 1029 users_.insert(users_.begin(), active_user_);
1030 SetLRUUser(active_user_);
Nikita (slow) 2013/05/17 17:00:32 You already move this user in UserLoggedIn().
Mr4D (OOO till 08-26) 2013/05/17 18:45:09 Following all calls - indeed! Done!
1013 1031
1014 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); 1032 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
1015 1033
1016 if (!browser_restart) { 1034 if (!browser_restart) {
1017 // For GAIA login flow, logged in user wallpaper may not be loaded. 1035 // For GAIA login flow, logged in user wallpaper may not be loaded.
1018 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 1036 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
1019 } 1037 }
1020 1038
1021 default_pinned_apps_field_trial::SetupForUser(email, is_current_user_new_); 1039 default_pinned_apps_field_trial::SetupForUser(email, is_current_user_new_);
1022 1040
(...skipping 29 matching lines...) Expand all
1052 is_current_user_new_ = true; 1070 is_current_user_new_ = true;
1053 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); 1071 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
1054 } 1072 }
1055 } 1073 }
1056 1074
1057 // Add the user to the front of the user list. 1075 // Add the user to the front of the user list.
1058 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), 1076 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
1059 kRegularUsers); 1077 kRegularUsers);
1060 prefs_users_update->Insert(0, new base::StringValue(username)); 1078 prefs_users_update->Insert(0, new base::StringValue(username));
1061 users_.insert(users_.begin(), active_user_); 1079 users_.insert(users_.begin(), active_user_);
1080 SetLRUUser(active_user_);
Nikita (slow) 2013/05/17 17:00:32 Not needed, is handled in UserLoggedIn()
Mr4D (OOO till 08-26) 2013/05/17 18:45:09 Ditto.
1062 1081
1063 // Now that user is in the list, save display name. 1082 // Now that user is in the list, save display name.
1064 if (is_current_user_new_) { 1083 if (is_current_user_new_) {
1065 SaveUserDisplayName(active_user_->email(), 1084 SaveUserDisplayName(active_user_->email(),
1066 active_user_->GetDisplayName()); 1085 active_user_->GetDisplayName());
1067 } 1086 }
1068 1087
1069 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true); 1088 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true);
1070 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 1089 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
1071 1090
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 } 1506 }
1488 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP: 1507 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP:
1489 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the 1508 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the
1490 // standard login framework: http://crbug.com/234694 1509 // standard login framework: http://crbug.com/234694
1491 break; 1510 break;
1492 } 1511 }
1493 } 1512 }
1494 } 1513 }
1495 } 1514 }
1496 1515
1516 void UserManagerImpl::SetLRUUser(User* user) {
1517 UserList::iterator it = std::find(lru_logged_in_users_.begin(),
1518 lru_logged_in_users_.end(),
1519 user);
1520 if (it != lru_logged_in_users_.end())
1521 lru_logged_in_users_.erase(it);
1522 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user);
1523 }
1524
1497 } // namespace chromeos 1525 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698