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_chromeos.h" | 5 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h" |
6 | 6 |
7 #include "ash/multi_profile_uma.h" | 7 #include "ash/multi_profile_uma.h" |
8 #include "ash/session/session_state_observer.h" | 8 #include "ash/session/session_state_observer.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 12 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
14 #include "chrome/browser/chromeos/login/users/user.h" | |
15 #include "chrome/browser/chromeos/login/users/user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/user_manager.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
22 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
23 #include "chromeos/dbus/session_manager_client.h" | 22 #include "chromeos/dbus/session_manager_client.h" |
24 #include "chromeos/login/login_state.h" | 23 #include "chromeos/login/login_state.h" |
| 24 #include "components/user_manager/user.h" |
25 #include "google_apis/gaia/gaia_auth_util.h" | 25 #include "google_apis/gaia/gaia_auth_util.h" |
26 | 26 |
27 SessionStateDelegateChromeos::SessionStateDelegateChromeos() | 27 SessionStateDelegateChromeos::SessionStateDelegateChromeos() |
28 : session_state_(SESSION_STATE_LOGIN_PRIMARY) { | 28 : session_state_(SESSION_STATE_LOGIN_PRIMARY) { |
29 chromeos::UserManager::Get()->AddSessionStateObserver(this); | 29 chromeos::UserManager::Get()->AddSessionStateObserver(this); |
30 chromeos::UserAddingScreen::Get()->AddObserver(this); | 30 chromeos::UserAddingScreen::Get()->AddObserver(this); |
31 | 31 |
32 // LoginState is not initialized in unit_tests. | 32 // LoginState is not initialized in unit_tests. |
33 if (chromeos::LoginState::IsInitialized()) { | 33 if (chromeos::LoginState::IsInitialized()) { |
34 chromeos::LoginState::Get()->AddObserver(this); | 34 chromeos::LoginState::Get()->AddObserver(this); |
35 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? | 35 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? |
36 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); | 36 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { | 40 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { |
41 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | 41 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); |
42 chromeos::UserAddingScreen::Get()->RemoveObserver(this); | 42 chromeos::UserAddingScreen::Get()->RemoveObserver(this); |
43 | 43 |
44 // LoginState is not initialized in unit_tests. | 44 // LoginState is not initialized in unit_tests. |
45 if (chromeos::LoginState::IsInitialized()) | 45 if (chromeos::LoginState::IsInitialized()) |
46 chromeos::LoginState::Get()->RemoveObserver(this); | 46 chromeos::LoginState::Get()->RemoveObserver(this); |
47 } | 47 } |
48 | 48 |
49 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( | 49 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( |
50 ash::MultiProfileIndex index) { | 50 ash::MultiProfileIndex index) { |
51 DCHECK_LT(index, NumberOfLoggedInUsers()); | 51 DCHECK_LT(index, NumberOfLoggedInUsers()); |
52 chromeos::User* user = | 52 user_manager::User* user = |
53 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; | 53 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; |
54 DCHECK(user); | 54 DCHECK(user); |
55 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 55 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
56 } | 56 } |
57 | 57 |
58 content::BrowserContext* | 58 content::BrowserContext* |
59 SessionStateDelegateChromeos::GetBrowserContextForWindow( | 59 SessionStateDelegateChromeos::GetBrowserContextForWindow( |
60 aura::Window* window) { | 60 aura::Window* window) { |
61 const std::string& user_id = | 61 const std::string& user_id = |
62 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); | 62 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); |
63 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(user_id); | 63 const user_manager::User* user = |
| 64 chromeos::UserManager::Get()->FindUser(user_id); |
64 DCHECK(user); | 65 DCHECK(user); |
65 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 66 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
66 } | 67 } |
67 | 68 |
68 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { | 69 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { |
69 // We limit list of logged in users to 10 due to memory constraints. | 70 // We limit list of logged in users to 10 due to memory constraints. |
70 // Note that 10 seems excessive, but we want to test how many users are | 71 // Note that 10 seems excessive, but we want to test how many users are |
71 // actually added to a session. | 72 // actually added to a session. |
72 // TODO(nkostylev): Adjust this limitation based on device capabilites. | 73 // TODO(nkostylev): Adjust this limitation based on device capabilites. |
73 // http://crbug.com/230865 | 74 // http://crbug.com/230865 |
74 return 10; | 75 return 10; |
75 } | 76 } |
76 | 77 |
77 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { | 78 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { |
78 return chromeos::UserManager::Get()->GetLoggedInUsers().size(); | 79 return chromeos::UserManager::Get()->GetLoggedInUsers().size(); |
79 } | 80 } |
80 | 81 |
81 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { | 82 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { |
82 return chromeos::UserManager::Get()->IsSessionStarted(); | 83 return chromeos::UserManager::Get()->IsSessionStarted(); |
83 } | 84 } |
84 | 85 |
85 bool SessionStateDelegateChromeos::CanLockScreen() const { | 86 bool SessionStateDelegateChromeos::CanLockScreen() const { |
86 const chromeos::UserList unlock_users = | 87 const user_manager::UserList unlock_users = |
87 chromeos::UserManager::Get()->GetUnlockUsers(); | 88 chromeos::UserManager::Get()->GetUnlockUsers(); |
88 return !unlock_users.empty(); | 89 return !unlock_users.empty(); |
89 } | 90 } |
90 | 91 |
91 bool SessionStateDelegateChromeos::IsScreenLocked() const { | 92 bool SessionStateDelegateChromeos::IsScreenLocked() const { |
92 return chromeos::ScreenLocker::default_screen_locker() && | 93 return chromeos::ScreenLocker::default_screen_locker() && |
93 chromeos::ScreenLocker::default_screen_locker()->locked(); | 94 chromeos::ScreenLocker::default_screen_locker()->locked(); |
94 } | 95 } |
95 | 96 |
96 bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const { | 97 bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const { |
97 const chromeos::UserList logged_in_users = | 98 const user_manager::UserList logged_in_users = |
98 chromeos::UserManager::Get()->GetLoggedInUsers(); | 99 chromeos::UserManager::Get()->GetLoggedInUsers(); |
99 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); | 100 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); |
100 it != logged_in_users.end(); ++it) { | 101 it != logged_in_users.end(); |
101 chromeos::User* user = (*it); | 102 ++it) { |
| 103 user_manager::User* user = (*it); |
102 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 104 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
103 if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) | 105 if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) |
104 return true; | 106 return true; |
105 } | 107 } |
106 return false; | 108 return false; |
107 } | 109 } |
108 | 110 |
109 void SessionStateDelegateChromeos::LockScreen() { | 111 void SessionStateDelegateChromeos::LockScreen() { |
110 if (!CanLockScreen()) | 112 if (!CanLockScreen()) |
111 return; | 113 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) | 163 if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) |
162 return; | 164 return; |
163 chromeos::UserManager::Get()->SwitchActiveUser(user_id); | 165 chromeos::UserManager::Get()->SwitchActiveUser(user_id); |
164 } | 166 } |
165 | 167 |
166 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { | 168 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { |
167 // Make sure there is a user to switch to. | 169 // Make sure there is a user to switch to. |
168 if (NumberOfLoggedInUsers() <= 1) | 170 if (NumberOfLoggedInUsers() <= 1) |
169 return; | 171 return; |
170 | 172 |
171 const chromeos::UserList& logged_in_users = | 173 const user_manager::UserList& logged_in_users = |
172 chromeos::UserManager::Get()->GetLoggedInUsers(); | 174 chromeos::UserManager::Get()->GetLoggedInUsers(); |
173 | 175 |
174 std::string user_id = chromeos::UserManager::Get()->GetActiveUser()->email(); | 176 std::string user_id = chromeos::UserManager::Get()->GetActiveUser()->email(); |
175 | 177 |
176 // Get an iterator positioned at the active user. | 178 // Get an iterator positioned at the active user. |
177 chromeos::UserList::const_iterator it; | 179 user_manager::UserList::const_iterator it; |
178 for (it = logged_in_users.begin(); | 180 for (it = logged_in_users.begin(); |
179 it != logged_in_users.end(); ++it) { | 181 it != logged_in_users.end(); ++it) { |
180 if ((*it)->email() == user_id) | 182 if ((*it)->email() == user_id) |
181 break; | 183 break; |
182 } | 184 } |
183 | 185 |
184 // Active user not found. | 186 // Active user not found. |
185 if (it == logged_in_users.end()) | 187 if (it == logged_in_users.end()) |
186 return; | 188 return; |
187 | 189 |
(...skipping 26 matching lines...) Expand all Loading... |
214 ash::SessionStateObserver* observer) { | 216 ash::SessionStateObserver* observer) { |
215 session_state_observer_list_.RemoveObserver(observer); | 217 session_state_observer_list_.RemoveObserver(observer); |
216 } | 218 } |
217 | 219 |
218 void SessionStateDelegateChromeos::LoggedInStateChanged() { | 220 void SessionStateDelegateChromeos::LoggedInStateChanged() { |
219 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? | 221 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? |
220 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); | 222 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); |
221 } | 223 } |
222 | 224 |
223 void SessionStateDelegateChromeos::ActiveUserChanged( | 225 void SessionStateDelegateChromeos::ActiveUserChanged( |
224 const chromeos::User* active_user) { | 226 const user_manager::User* active_user) { |
225 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 227 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
226 session_state_observer_list_, | 228 session_state_observer_list_, |
227 ActiveUserChanged(active_user->email())); | 229 ActiveUserChanged(active_user->email())); |
228 } | 230 } |
229 | 231 |
230 void SessionStateDelegateChromeos::UserAddedToSession( | 232 void SessionStateDelegateChromeos::UserAddedToSession( |
231 const chromeos::User* added_user) { | 233 const user_manager::User* added_user) { |
232 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 234 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
233 session_state_observer_list_, | 235 session_state_observer_list_, |
234 UserAddedToSession(added_user->email())); | 236 UserAddedToSession(added_user->email())); |
235 } | 237 } |
236 | 238 |
237 void SessionStateDelegateChromeos::OnUserAddingStarted() { | 239 void SessionStateDelegateChromeos::OnUserAddingStarted() { |
238 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); | 240 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); |
239 } | 241 } |
240 | 242 |
241 void SessionStateDelegateChromeos::OnUserAddingFinished() { | 243 void SessionStateDelegateChromeos::OnUserAddingFinished() { |
242 SetSessionState(SESSION_STATE_ACTIVE, false); | 244 SetSessionState(SESSION_STATE_ACTIVE, false); |
243 } | 245 } |
244 | 246 |
245 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, | 247 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, |
246 bool force) { | 248 bool force) { |
247 if (session_state_ == new_state && !force) | 249 if (session_state_ == new_state && !force) |
248 return; | 250 return; |
249 | 251 |
250 session_state_ = new_state; | 252 session_state_ = new_state; |
251 NotifySessionStateChanged(); | 253 NotifySessionStateChanged(); |
252 } | 254 } |
253 | 255 |
254 void SessionStateDelegateChromeos::NotifySessionStateChanged() { | 256 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
255 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 257 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
256 session_state_observer_list_, | 258 session_state_observer_list_, |
257 SessionStateChanged(session_state_)); | 259 SessionStateChanged(session_state_)); |
258 } | 260 } |
OLD | NEW |