| 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 "ash/system/chromeos/multi_user/user_switch_util.h" | 9 #include "ash/system/chromeos/multi_user/user_switch_util.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 DCHECK_LT(index, NumberOfLoggedInUsers()); | 56 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 57 user_manager::User* user = | 57 user_manager::User* user = |
| 58 user_manager::UserManager::Get()->GetLRULoggedInUsers()[index]; | 58 user_manager::UserManager::Get()->GetLRULoggedInUsers()[index]; |
| 59 CHECK(user); | 59 CHECK(user); |
| 60 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 60 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
| 61 } | 61 } |
| 62 | 62 |
| 63 content::BrowserContext* | 63 content::BrowserContext* |
| 64 SessionStateDelegateChromeos::GetBrowserContextForWindow( | 64 SessionStateDelegateChromeos::GetBrowserContextForWindow( |
| 65 aura::Window* window) { | 65 aura::Window* window) { |
| 66 const std::string& user_id = | 66 const user_manager::UserID& user_id = |
| 67 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); | 67 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); |
| 68 return user_id.empty() ? NULL | 68 return user_id.empty() ? NULL |
| 69 : multi_user_util::GetProfileFromUserID(user_id); | 69 : multi_user_util::GetProfileFromUserID(user_id); |
| 70 } | 70 } |
| 71 | 71 |
| 72 content::BrowserContext* | 72 content::BrowserContext* |
| 73 SessionStateDelegateChromeos::GetUserPresentingBrowserContextForWindow( | 73 SessionStateDelegateChromeos::GetUserPresentingBrowserContextForWindow( |
| 74 aura::Window* window) { | 74 aura::Window* window) { |
| 75 const std::string& user_id = | 75 const user_manager::UserID& user_id = |
| 76 chrome::MultiUserWindowManager::GetInstance()->GetUserPresentingWindow( | 76 chrome::MultiUserWindowManager::GetInstance()->GetUserPresentingWindow( |
| 77 window); | 77 window); |
| 78 return user_id.empty() ? NULL | 78 return user_id.empty() ? NULL |
| 79 : multi_user_util::GetProfileFromUserID(user_id); | 79 : multi_user_util::GetProfileFromUserID(user_id); |
| 80 } | 80 } |
| 81 | 81 |
| 82 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { | 82 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { |
| 83 // We limit list of logged in users to 10 due to memory constraints. | 83 // We limit list of logged in users to 10 due to memory constraints. |
| 84 // Note that 10 seems excessive, but we want to test how many users are | 84 // Note that 10 seems excessive, but we want to test how many users are |
| 85 // actually added to a session. | 85 // actually added to a session. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 Profile::FromBrowserContext(context)); | 174 Profile::FromBrowserContext(context)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 bool SessionStateDelegateChromeos::ShouldShowAvatar( | 177 bool SessionStateDelegateChromeos::ShouldShowAvatar( |
| 178 aura::Window* window) const { | 178 aura::Window* window) const { |
| 179 return chrome::MultiUserWindowManager::GetInstance()-> | 179 return chrome::MultiUserWindowManager::GetInstance()-> |
| 180 ShouldShowAvatar(window); | 180 ShouldShowAvatar(window); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SessionStateDelegateChromeos::SwitchActiveUser( | 183 void SessionStateDelegateChromeos::SwitchActiveUser( |
| 184 const std::string& user_id) { | 184 const user_manager::UserID& user_id) { |
| 185 // Disallow switching to an already active user since that might crash. | 185 // Disallow switching to an already active user since that might crash. |
| 186 // Also check that we got a user id and not an email address. | 186 // Also check that we got a user id and not an email address. |
| 187 DCHECK_EQ(user_id, | 187 DCHECK_EQ(user_id.GetUserEmail(), |
| 188 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); | 188 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id.GetUserEmail()))
); |
| 189 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) | 189 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->GetUserID()) |
| 190 return; | 190 return; |
| 191 TryToSwitchUser(user_id); | 191 TryToSwitchUser(user_id); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { | 194 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { |
| 195 // Make sure there is a user to switch to. | 195 // Make sure there is a user to switch to. |
| 196 if (NumberOfLoggedInUsers() <= 1) | 196 if (NumberOfLoggedInUsers() <= 1) |
| 197 return; | 197 return; |
| 198 | 198 |
| 199 const user_manager::UserList& logged_in_users = | 199 const user_manager::UserList& logged_in_users = |
| 200 user_manager::UserManager::Get()->GetLoggedInUsers(); | 200 user_manager::UserManager::Get()->GetLoggedInUsers(); |
| 201 | 201 |
| 202 std::string user_id = | 202 user_manager::UserID user_id = |
| 203 user_manager::UserManager::Get()->GetActiveUser()->email(); | 203 user_manager::UserManager::Get()->GetActiveUser()->GetUserID(); |
| 204 | 204 |
| 205 // Get an iterator positioned at the active user. | 205 // Get an iterator positioned at the active user. |
| 206 user_manager::UserList::const_iterator it; | 206 user_manager::UserList::const_iterator it; |
| 207 for (it = logged_in_users.begin(); | 207 for (it = logged_in_users.begin(); |
| 208 it != logged_in_users.end(); ++it) { | 208 it != logged_in_users.end(); ++it) { |
| 209 if ((*it)->email() == user_id) | 209 if ((*it)->GetUserID() == user_id) |
| 210 break; | 210 break; |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Active user not found. | 213 // Active user not found. |
| 214 if (it == logged_in_users.end()) | 214 if (it == logged_in_users.end()) |
| 215 return; | 215 return; |
| 216 | 216 |
| 217 // Get the user's email to select, wrapping to the start/end of the list if | 217 // Get the user's email to select, wrapping to the start/end of the list if |
| 218 // necessary. | 218 // necessary. |
| 219 switch (cycle_user) { | 219 switch (cycle_user) { |
| 220 case CYCLE_TO_NEXT_USER: | 220 case CYCLE_TO_NEXT_USER: |
| 221 if (++it == logged_in_users.end()) | 221 if (++it == logged_in_users.end()) |
| 222 user_id = (*logged_in_users.begin())->email(); | 222 user_id = (*logged_in_users.begin())->GetUserID(); |
| 223 else | 223 else |
| 224 user_id = (*it)->email(); | 224 user_id = (*it)->GetUserID(); |
| 225 break; | 225 break; |
| 226 case CYCLE_TO_PREVIOUS_USER: | 226 case CYCLE_TO_PREVIOUS_USER: |
| 227 if (it == logged_in_users.begin()) | 227 if (it == logged_in_users.begin()) |
| 228 it = logged_in_users.end(); | 228 it = logged_in_users.end(); |
| 229 user_id = (*(--it))->email(); | 229 user_id = (*(--it))->GetUserID(); |
| 230 break; | 230 break; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Switch using the transformed |user_id|. | 233 // Switch using the transformed |user_id|. |
| 234 TryToSwitchUser(user_id); | 234 TryToSwitchUser(user_id); |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() | 237 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() |
| 238 const { | 238 const { |
| 239 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == | 239 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == |
| (...skipping 12 matching lines...) Expand all Loading... |
| 252 | 252 |
| 253 void SessionStateDelegateChromeos::LoggedInStateChanged() { | 253 void SessionStateDelegateChromeos::LoggedInStateChanged() { |
| 254 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? | 254 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? |
| 255 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); | 255 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void SessionStateDelegateChromeos::ActiveUserChanged( | 258 void SessionStateDelegateChromeos::ActiveUserChanged( |
| 259 const user_manager::User* active_user) { | 259 const user_manager::User* active_user) { |
| 260 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 260 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 261 session_state_observer_list_, | 261 session_state_observer_list_, |
| 262 ActiveUserChanged(active_user->email())); | 262 ActiveUserChanged(active_user->GetUserID())); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void SessionStateDelegateChromeos::UserAddedToSession( | 265 void SessionStateDelegateChromeos::UserAddedToSession( |
| 266 const user_manager::User* added_user) { | 266 const user_manager::User* added_user) { |
| 267 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 267 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 268 session_state_observer_list_, | 268 session_state_observer_list_, |
| 269 UserAddedToSession(added_user->email())); | 269 UserAddedToSession(added_user->GetUserID())); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void SessionStateDelegateChromeos::OnUserAddingStarted() { | 272 void SessionStateDelegateChromeos::OnUserAddingStarted() { |
| 273 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); | 273 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void SessionStateDelegateChromeos::OnUserAddingFinished() { | 276 void SessionStateDelegateChromeos::OnUserAddingFinished() { |
| 277 SetSessionState(SESSION_STATE_ACTIVE, false); | 277 SetSessionState(SESSION_STATE_ACTIVE, false); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, | 280 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, |
| 281 bool force) { | 281 bool force) { |
| 282 if (session_state_ == new_state && !force) | 282 if (session_state_ == new_state && !force) |
| 283 return; | 283 return; |
| 284 | 284 |
| 285 session_state_ = new_state; | 285 session_state_ = new_state; |
| 286 NotifySessionStateChanged(); | 286 NotifySessionStateChanged(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void SessionStateDelegateChromeos::NotifySessionStateChanged() { | 289 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
| 290 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 290 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 291 session_state_observer_list_, | 291 session_state_observer_list_, |
| 292 SessionStateChanged(session_state_)); | 292 SessionStateChanged(session_state_)); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void DoSwitchUser(const std::string& user_id) { | 295 void DoSwitchUser(const user_manager::UserID& user_id) { |
| 296 user_manager::UserManager::Get()->SwitchActiveUser(user_id); | 296 user_manager::UserManager::Get()->SwitchActiveUser(user_id); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void SessionStateDelegateChromeos::TryToSwitchUser( | 299 void SessionStateDelegateChromeos::TryToSwitchUser( |
| 300 const std::string& user_id) { | 300 const user_manager::UserID& user_id) { |
| 301 ash::TrySwitchingActiveUser(base::Bind(&DoSwitchUser, user_id)); | 301 ash::TrySwitchingActiveUser(base::Bind(&DoSwitchUser, user_id)); |
| 302 } | 302 } |
| OLD | NEW |