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 |
| 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; |
| 66 } |
| 67 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 68 return chromeos::UserManager::Get()-> |
| 69 GetLRULoggedInUsers()[index]->display_name(); |
| 70 } |
| 71 |
| 72 const std::string SessionStateDelegate::GetUserEmail( |
| 73 ash::MultiProfileIndex index) const { |
| 74 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && |
| 75 static_cast<size_t>(index) >= |
| 76 chromeos::UserManager::Get()->GetLoggedInUsers().size()) { |
| 77 index = 0; |
| 78 } |
| 79 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 80 return chromeos::UserManager::Get()-> |
| 81 GetLRULoggedInUsers()[index]->display_email(); |
| 82 } |
| 83 |
| 84 const gfx::ImageSkia& SessionStateDelegate::GetUserImage( |
| 85 ash::MultiProfileIndex index) const { |
| 86 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && |
| 87 static_cast<size_t>(index) >= |
| 88 chromeos::UserManager::Get()->GetLoggedInUsers().size()) { |
| 89 index = 0; |
| 90 } |
| 91 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 92 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]->image(); |
| 93 } |
| 94 |
| 95 void SessionStateDelegate::GetLoggedInUsers( |
| 96 ash::UserEmailList* users) { |
| 97 const chromeos::UserList& logged_in_users = |
| 98 chromeos::UserManager::Get()->GetLoggedInUsers(); |
| 99 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); |
| 100 it != logged_in_users.end(); ++it) { |
| 101 const chromeos::User* user = (*it); |
| 102 users->push_back(user->email()); |
| 103 } |
| 104 } |
| 105 |
| 106 void SessionStateDelegate::SwitchActiveUser(const std::string& email) { |
| 107 chromeos::UserManager::Get()->SwitchActiveUser(email); |
| 108 } |
OLD | NEW |