Chromium Code Reviews| 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/ui/ash/session_state_delegate.h" | 5 #include "chrome/browser/ui/ash/session_state_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chromeos/login/screen_locker.h" | 8 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 9 #include "chrome/browser/chromeos/login/user_manager.h" | 9 #include "chrome/browser/chromeos/login/user_manager.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/session_manager_client.h" | 11 #include "chromeos/dbus/session_manager_client.h" |
| 12 | 12 |
| 13 // TODO(skuhne): To be able to test this I had to hardcode the number of known | |
| 14 // users. Get rid of it once it works. | |
| 15 #define ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT 0 | |
|
Nikita (slow)
2013/05/17 17:00:32
Why is this needed?
Mr4D (OOO till 08-26)
2013/05/17 18:45:09
As stated - only for testing all the different men
| |
| 16 | |
| 13 SessionStateDelegate::SessionStateDelegate() { | 17 SessionStateDelegate::SessionStateDelegate() { |
| 14 } | 18 } |
| 15 | 19 |
| 16 SessionStateDelegate::~SessionStateDelegate() { | 20 SessionStateDelegate::~SessionStateDelegate() { |
| 17 } | 21 } |
| 18 | 22 |
| 19 bool SessionStateDelegate::HasActiveUser() const { | 23 int SessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const { |
| 20 return chromeos::UserManager::Get()->IsUserLoggedIn(); | 24 return 3; |
| 25 } | |
| 26 | |
| 27 int SessionStateDelegate::NumberOfLoggedInUsers() const { | |
| 28 return chromeos::UserManager::Get()->GetLoggedInUsers().size() + | |
| 29 ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT; | |
| 21 } | 30 } |
| 22 | 31 |
| 23 bool SessionStateDelegate::IsActiveUserSessionStarted() const { | 32 bool SessionStateDelegate::IsActiveUserSessionStarted() const { |
| 24 return chromeos::UserManager::Get()->IsSessionStarted(); | 33 return chromeos::UserManager::Get()->IsSessionStarted(); |
| 25 } | 34 } |
| 26 | 35 |
| 27 bool SessionStateDelegate::CanLockScreen() const { | 36 bool SessionStateDelegate::CanLockScreen() const { |
| 28 return chromeos::UserManager::Get()->CanCurrentUserLock(); | 37 return chromeos::UserManager::Get()->CanCurrentUserLock(); |
| 29 } | 38 } |
| 30 | 39 |
| 31 bool SessionStateDelegate::IsScreenLocked() const { | 40 bool SessionStateDelegate::IsScreenLocked() const { |
| 32 return chromeos::ScreenLocker::default_screen_locker() && | 41 return chromeos::ScreenLocker::default_screen_locker() && |
| 33 chromeos::ScreenLocker::default_screen_locker()->locked(); | 42 chromeos::ScreenLocker::default_screen_locker()->locked(); |
| 34 } | 43 } |
| 35 | 44 |
| 36 void SessionStateDelegate::LockScreen() { | 45 void SessionStateDelegate::LockScreen() { |
| 37 if (!CanLockScreen()) | 46 if (!CanLockScreen()) |
| 38 return; | 47 return; |
| 39 | 48 |
| 40 // TODO(antrim): Additional logging for http://crbug.com/173178. | 49 // TODO(antrim): Additional logging for http://crbug.com/173178. |
| 41 LOG(WARNING) << "Requesting screen lock from SessionStateDelegate"; | 50 LOG(WARNING) << "Requesting screen lock from SessionStateDelegate"; |
| 42 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 51 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 43 RequestLockScreen(); | 52 RequestLockScreen(); |
| 44 } | 53 } |
| 45 | 54 |
| 46 void SessionStateDelegate::UnlockScreen() { | 55 void SessionStateDelegate::UnlockScreen() { |
| 47 // This is used only for testing thus far. | 56 // This is used only for testing thus far. |
| 48 NOTIMPLEMENTED(); | 57 NOTIMPLEMENTED(); |
| 49 } | 58 } |
| 59 | |
| 60 const base::string16 SessionStateDelegate::GetUserDisplayName( | |
| 61 ash::MultiProfileIndex index) const { | |
| 62 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && | |
| 63 static_cast<size_t>(index) >= | |
| 64 chromeos::UserManager::Get()->GetLoggedInUsers().size()) | |
| 65 index = 0; | |
|
Nikita (slow)
2013/05/17 17:00:32
nit: Add {}
Mr4D (OOO till 08-26)
2013/05/17 18:45:09
Done.
| |
| 66 DCHECK_LT(index, NumberOfLoggedInUsers()); | |
| 67 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[ | |
|
Nikita (slow)
2013/05/17 17:00:32
nit: Makes sense to move method name to next line:
Mr4D (OOO till 08-26)
2013/05/17 18:45:09
Done.
| |
| 68 index]->display_name(); | |
| 69 } | |
| 70 | |
| 71 const std::string SessionStateDelegate::GetUserEmail( | |
| 72 ash::MultiProfileIndex index) const { | |
| 73 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && | |
| 74 static_cast<size_t>(index) >= | |
| 75 chromeos::UserManager::Get()->GetLoggedInUsers().size()) | |
| 76 index = 0; | |
| 77 DCHECK_LT(index, NumberOfLoggedInUsers()); | |
| 78 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[ | |
|
Nikita (slow)
2013/05/17 17:00:32
nit: Same here.
Mr4D (OOO till 08-26)
2013/05/17 18:45:09
Done.
| |
| 79 index]->display_email(); | |
| 80 } | |
| 81 | |
| 82 const gfx::ImageSkia& SessionStateDelegate::GetUserImage( | |
| 83 ash::MultiProfileIndex index) const { | |
| 84 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && | |
|
Nikita (slow)
2013/05/17 17:00:32
Makes sense to extract code that returns user by i
Mr4D (OOO till 08-26)
2013/05/17 18:45:09
This is only for the lifetime of this CL. My next
| |
| 85 static_cast<size_t>(index) >= | |
| 86 chromeos::UserManager::Get()->GetLoggedInUsers().size()) | |
| 87 index = 0; | |
| 88 DCHECK_LT(index, NumberOfLoggedInUsers()); | |
| 89 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]->image(); | |
| 90 } | |
| 91 | |
| 92 void SessionStateDelegate::GetLoggedInUsers( | |
| 93 ash::UserEmailList* users) { | |
| 94 const chromeos::UserList& logged_in_users = | |
| 95 chromeos::UserManager::Get()->GetLoggedInUsers(); | |
| 96 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); | |
| 97 it != logged_in_users.end(); ++it) { | |
| 98 const chromeos::User* user = (*it); | |
| 99 users->push_back(user->email()); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void SessionStateDelegate::SwitchActiveUser(const std::string& email) { | |
| 104 chromeos::UserManager::Get()->SwitchActiveUser(email); | |
| 105 } | |
| OLD | NEW |