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/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
8 #include "ash/common/session/session_state_observer.h" | 8 #include "ash/common/session/session_state_observer.h" |
9 #include "ash/content/shell_content_state.h" | 9 #include "ash/content/shell_content_state.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 14 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
15 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 15 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
16 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 16 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
21 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" | 21 #include "chrome/browser/ui/ash/session_controller_client.h" |
22 #include "chrome/browser/ui/ash/session_util.h" | 22 #include "chrome/browser/ui/ash/session_util.h" |
23 #include "chrome/common/pref_names.h" | |
24 #include "chromeos/chromeos_switches.h" | 23 #include "chromeos/chromeos_switches.h" |
25 #include "chromeos/dbus/dbus_thread_manager.h" | |
26 #include "chromeos/dbus/session_manager_client.h" | |
27 #include "chromeos/login/login_state.h" | 24 #include "chromeos/login/login_state.h" |
28 #include "components/prefs/pref_service.h" | |
29 #include "components/session_manager/core/session_manager.h" | 25 #include "components/session_manager/core/session_manager.h" |
30 #include "components/signin/core/account_id/account_id.h" | 26 #include "components/signin/core/account_id/account_id.h" |
31 #include "components/user_manager/user.h" | 27 #include "components/user_manager/user.h" |
32 #include "components/user_manager/user_info.h" | 28 #include "components/user_manager/user_info.h" |
33 #include "components/user_manager/user_manager.h" | 29 #include "components/user_manager/user_manager.h" |
34 #include "google_apis/gaia/gaia_auth_util.h" | 30 #include "google_apis/gaia/gaia_auth_util.h" |
35 #include "ui/gfx/image/image_skia.h" | 31 #include "ui/gfx/image/image_skia.h" |
36 | 32 |
37 SessionStateDelegateChromeos::SessionStateDelegateChromeos() | 33 SessionStateDelegateChromeos::SessionStateDelegateChromeos() |
38 : session_state_(session_manager::SessionState::LOGIN_PRIMARY) { | 34 : session_state_(session_manager::SessionState::LOGIN_PRIMARY) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // http://crbug.com/230865 | 68 // http://crbug.com/230865 |
73 return 10; | 69 return 10; |
74 } | 70 } |
75 | 71 |
76 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { | 72 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { |
77 return user_manager::UserManager::Get()->GetLoggedInUsers().size(); | 73 return user_manager::UserManager::Get()->GetLoggedInUsers().size(); |
78 } | 74 } |
79 | 75 |
80 ash::AddUserSessionPolicy | 76 ash::AddUserSessionPolicy |
81 SessionStateDelegateChromeos::GetAddUserSessionPolicy() const { | 77 SessionStateDelegateChromeos::GetAddUserSessionPolicy() const { |
82 if (user_manager::UserManager::Get() | 78 return SessionControllerClient::GetAddUserSessionPolicy(); |
83 ->GetUsersAllowedForMultiProfile() | |
84 .size() == 0) { | |
85 return ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS; | |
86 } | |
87 return SessionStateDelegate::GetAddUserSessionPolicy(); | |
88 } | 79 } |
89 | 80 |
90 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { | 81 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { |
91 return session_manager::SessionManager::Get() && | 82 return session_manager::SessionManager::Get() && |
92 session_manager::SessionManager::Get()->IsSessionStarted(); | 83 session_manager::SessionManager::Get()->IsSessionStarted(); |
93 } | 84 } |
94 | 85 |
95 bool SessionStateDelegateChromeos::CanLockScreen() const { | 86 bool SessionStateDelegateChromeos::CanLockScreen() const { |
96 const user_manager::UserList unlock_users = | 87 return SessionControllerClient::CanLockScreen(); |
97 user_manager::UserManager::Get()->GetUnlockUsers(); | |
98 return !unlock_users.empty(); | |
99 } | 88 } |
100 | 89 |
101 bool SessionStateDelegateChromeos::IsScreenLocked() const { | 90 bool SessionStateDelegateChromeos::IsScreenLocked() const { |
102 return chromeos::ScreenLocker::default_screen_locker() && | 91 return chromeos::ScreenLocker::default_screen_locker() && |
103 chromeos::ScreenLocker::default_screen_locker()->locked(); | 92 chromeos::ScreenLocker::default_screen_locker()->locked(); |
104 } | 93 } |
105 | 94 |
106 bool SessionStateDelegateChromeos::ShouldLockScreenAutomatically() const { | 95 bool SessionStateDelegateChromeos::ShouldLockScreenAutomatically() const { |
107 const user_manager::UserList logged_in_users = | 96 return SessionControllerClient::ShouldLockScreenAutomatically(); |
108 user_manager::UserManager::Get()->GetLoggedInUsers(); | |
109 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); | |
110 it != logged_in_users.end(); | |
111 ++it) { | |
112 user_manager::User* user = (*it); | |
113 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); | |
114 if (profile && | |
115 profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) { | |
116 return true; | |
117 } | |
118 } | |
119 return false; | |
120 } | 97 } |
121 | 98 |
122 void SessionStateDelegateChromeos::LockScreen() { | 99 void SessionStateDelegateChromeos::LockScreen() { |
123 if (!CanLockScreen()) | 100 return SessionControllerClient::DoLockScreen(); |
124 return; | |
125 | |
126 VLOG(1) << "Requesting screen lock from SessionStateDelegate"; | |
127 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | |
128 RequestLockScreen(); | |
129 } | 101 } |
130 | 102 |
131 void SessionStateDelegateChromeos::UnlockScreen() { | 103 void SessionStateDelegateChromeos::UnlockScreen() { |
132 // This is used only for testing thus far. | 104 // This is used only for testing thus far. |
133 NOTIMPLEMENTED(); | 105 NOTIMPLEMENTED(); |
134 } | 106 } |
135 | 107 |
136 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { | 108 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { |
137 bool has_login_manager = base::CommandLine::ForCurrentProcess()->HasSwitch( | 109 bool has_login_manager = base::CommandLine::ForCurrentProcess()->HasSwitch( |
138 chromeos::switches::kLoginManager); | 110 chromeos::switches::kLoginManager); |
(...skipping 22 matching lines...) Expand all Loading... |
161 gfx::ImageSkia SessionStateDelegateChromeos::GetAvatarImageForWindow( | 133 gfx::ImageSkia SessionStateDelegateChromeos::GetAvatarImageForWindow( |
162 ash::WmWindow* window) const { | 134 ash::WmWindow* window) const { |
163 content::BrowserContext* context = | 135 content::BrowserContext* context = |
164 ash::ShellContentState::GetInstance()->GetBrowserContextForWindow( | 136 ash::ShellContentState::GetInstance()->GetBrowserContextForWindow( |
165 ash::WmWindowAura::GetAuraWindow(window)); | 137 ash::WmWindowAura::GetAuraWindow(window)); |
166 return GetAvatarImageForContext(context); | 138 return GetAvatarImageForContext(context); |
167 } | 139 } |
168 | 140 |
169 void SessionStateDelegateChromeos::SwitchActiveUser( | 141 void SessionStateDelegateChromeos::SwitchActiveUser( |
170 const AccountId& account_id) { | 142 const AccountId& account_id) { |
171 // Disallow switching to an already active user since that might crash. | 143 SessionControllerClient::DoSwitchActiveUser(account_id); |
172 // Also check that we got a user id and not an email address. | |
173 DCHECK_EQ( | |
174 account_id.GetUserEmail(), | |
175 gaia::CanonicalizeEmail(gaia::SanitizeEmail(account_id.GetUserEmail()))); | |
176 if (account_id == | |
177 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId()) | |
178 return; | |
179 TryToSwitchUser(account_id); | |
180 } | 144 } |
181 | 145 |
182 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { | 146 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { |
183 // Make sure there is a user to switch to. | 147 SessionControllerClient::DoCycleActiveUser(cycle_user == CYCLE_TO_NEXT_USER); |
184 if (NumberOfLoggedInUsers() <= 1) | |
185 return; | |
186 | |
187 const user_manager::UserList& logged_in_users = | |
188 user_manager::UserManager::Get()->GetLoggedInUsers(); | |
189 | |
190 AccountId account_id = | |
191 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | |
192 | |
193 // Get an iterator positioned at the active user. | |
194 user_manager::UserList::const_iterator it; | |
195 for (it = logged_in_users.begin(); | |
196 it != logged_in_users.end(); ++it) { | |
197 if ((*it)->GetAccountId() == account_id) | |
198 break; | |
199 } | |
200 | |
201 // Active user not found. | |
202 if (it == logged_in_users.end()) | |
203 return; | |
204 | |
205 // Get the user's email to select, wrapping to the start/end of the list if | |
206 // necessary. | |
207 switch (cycle_user) { | |
208 case CYCLE_TO_NEXT_USER: | |
209 if (++it == logged_in_users.end()) | |
210 account_id = (*logged_in_users.begin())->GetAccountId(); | |
211 else | |
212 account_id = (*it)->GetAccountId(); | |
213 break; | |
214 case CYCLE_TO_PREVIOUS_USER: | |
215 if (it == logged_in_users.begin()) | |
216 it = logged_in_users.end(); | |
217 account_id = (*(--it))->GetAccountId(); | |
218 break; | |
219 } | |
220 | |
221 // Switch using the transformed |account_id|. | |
222 TryToSwitchUser(account_id); | |
223 } | 148 } |
224 | 149 |
225 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() | 150 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() |
226 const { | 151 const { |
227 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == | 152 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == |
228 chromeos::MultiProfileUserController::ALLOWED; | 153 chromeos::MultiProfileUserController::ALLOWED; |
229 } | 154 } |
230 | 155 |
231 void SessionStateDelegateChromeos::AddSessionStateObserver( | 156 void SessionStateDelegateChromeos::AddSessionStateObserver( |
232 ash::SessionStateObserver* observer) { | 157 ash::SessionStateObserver* observer) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 return; | 197 return; |
273 | 198 |
274 session_state_ = new_state; | 199 session_state_ = new_state; |
275 NotifySessionStateChanged(); | 200 NotifySessionStateChanged(); |
276 } | 201 } |
277 | 202 |
278 void SessionStateDelegateChromeos::NotifySessionStateChanged() { | 203 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
279 for (ash::SessionStateObserver& observer : session_state_observer_list_) | 204 for (ash::SessionStateObserver& observer : session_state_observer_list_) |
280 observer.SessionStateChanged(session_state_); | 205 observer.SessionStateChanged(session_state_); |
281 } | 206 } |
282 | |
283 void DoSwitchUser(const AccountId& account_id) { | |
284 user_manager::UserManager::Get()->SwitchActiveUser(account_id); | |
285 } | |
286 | |
287 void SessionStateDelegateChromeos::TryToSwitchUser( | |
288 const AccountId& account_id) { | |
289 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id)); | |
290 } | |
OLD | NEW |