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 1 | |
Mr4D (OOO till 08-26)
2013/05/17 04:08:33
As mentioned in my CL comment, this define is only
James Cook
2013/05/17 14:03:25
That's fine.
| |
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::NumberOfLoggedInUsers() const { |
20 return chromeos::UserManager::Get()->IsUserLoggedIn(); | 24 return chromeos::UserManager::Get()->GetLoggedInUsers().size() + |
James Cook
2013/05/17 14:03:25
Does this mean that all canary build users will se
Mr4D (OOO till 08-26)
2013/05/17 16:26:40
Just with the flag turned on. But again - before s
| |
25 ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT; | |
21 } | 26 } |
22 | 27 |
23 bool SessionStateDelegate::IsActiveUserSessionStarted() const { | 28 bool SessionStateDelegate::IsActiveUserSessionStarted() const { |
24 return chromeos::UserManager::Get()->IsSessionStarted(); | 29 return chromeos::UserManager::Get()->IsSessionStarted(); |
25 } | 30 } |
26 | 31 |
27 bool SessionStateDelegate::CanLockScreen() const { | 32 bool SessionStateDelegate::CanLockScreen() const { |
28 return chromeos::UserManager::Get()->CanCurrentUserLock(); | 33 return chromeos::UserManager::Get()->CanCurrentUserLock(); |
29 } | 34 } |
30 | 35 |
31 bool SessionStateDelegate::IsScreenLocked() const { | 36 bool SessionStateDelegate::IsScreenLocked() const { |
32 return chromeos::ScreenLocker::default_screen_locker() && | 37 return chromeos::ScreenLocker::default_screen_locker() && |
33 chromeos::ScreenLocker::default_screen_locker()->locked(); | 38 chromeos::ScreenLocker::default_screen_locker()->locked(); |
34 } | 39 } |
35 | 40 |
36 void SessionStateDelegate::LockScreen() { | 41 void SessionStateDelegate::LockScreen() { |
37 if (!CanLockScreen()) | 42 if (!CanLockScreen()) |
38 return; | 43 return; |
39 | 44 |
40 // TODO(antrim): Additional logging for http://crbug.com/173178. | 45 // TODO(antrim): Additional logging for http://crbug.com/173178. |
41 LOG(WARNING) << "Requesting screen lock from SessionStateDelegate"; | 46 LOG(WARNING) << "Requesting screen lock from SessionStateDelegate"; |
42 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 47 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
43 RequestLockScreen(); | 48 RequestLockScreen(); |
44 } | 49 } |
45 | 50 |
46 void SessionStateDelegate::UnlockScreen() { | 51 void SessionStateDelegate::UnlockScreen() { |
47 // This is used only for testing thus far. | 52 // This is used only for testing thus far. |
48 NOTIMPLEMENTED(); | 53 NOTIMPLEMENTED(); |
49 } | 54 } |
55 | |
56 const base::string16 SessionStateDelegate::GetUserDisplayName( | |
57 ash::MultiProfileIndex index) const { | |
58 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && | |
59 index >= (int)chromeos::UserManager::Get()->GetLoggedInUsers().size()) | |
James Cook
2013/05/17 14:03:25
(int) -> static_cast<int>()
It hurts, but casting
Mr4D (OOO till 08-26)
2013/05/17 16:26:40
Done.
| |
60 index = 0; | |
61 DCHECK_LT(index, NumberOfLoggedInUsers()); | |
62 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[ | |
63 index]->display_name(); | |
64 } | |
65 | |
66 const std::string SessionStateDelegate::GetUserEmail( | |
67 ash::MultiProfileIndex index) const { | |
68 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && | |
69 index >= (int)chromeos::UserManager::Get()->GetLoggedInUsers().size()) | |
70 index = 0; | |
71 DCHECK_LT(index, NumberOfLoggedInUsers()); | |
72 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[ | |
73 index]->display_email(); | |
74 } | |
75 | |
76 const gfx::ImageSkia& SessionStateDelegate::GetUserImage( | |
77 ash::MultiProfileIndex index) const { | |
78 if (ADD_TEST_USER_ACCOUNTS_FOR_MULTI_USER_TEST_ENVIRONMENT && | |
79 index >= (int)chromeos::UserManager::Get()->GetLoggedInUsers().size()) | |
80 index = 0; | |
81 DCHECK_LT(index, NumberOfLoggedInUsers()); | |
82 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]->image(); | |
83 } | |
84 | |
85 void SessionStateDelegate::GetLoggedInUsers( | |
86 ash::UserEmailList* users) { | |
87 const chromeos::UserList& logged_in_users = | |
88 chromeos::UserManager::Get()->GetLoggedInUsers(); | |
89 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); | |
90 it != logged_in_users.end(); ++it) { | |
91 const chromeos::User* user = (*it); | |
92 users->push_back(user->email()); | |
93 } | |
94 } | |
95 | |
96 void SessionStateDelegate::SwitchActiveUser(const std::string& email) { | |
97 chromeos::UserManager::Get()->SwitchActiveUser(email); | |
98 } | |
OLD | NEW |