| 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" |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 11 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 15 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 16 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 17 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 21 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 160 } |
| 158 | 161 |
| 159 void SessionStateDelegateChromeos::SwitchActiveUser( | 162 void SessionStateDelegateChromeos::SwitchActiveUser( |
| 160 const std::string& user_id) { | 163 const std::string& user_id) { |
| 161 // Disallow switching to an already active user since that might crash. | 164 // Disallow switching to an already active user since that might crash. |
| 162 // Also check that we got a user id and not an email address. | 165 // Also check that we got a user id and not an email address. |
| 163 DCHECK_EQ(user_id, | 166 DCHECK_EQ(user_id, |
| 164 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); | 167 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); |
| 165 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) | 168 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) |
| 166 return; | 169 return; |
| 167 user_manager::UserManager::Get()->SwitchActiveUser(user_id); | 170 TryToSwitchUser(user_id); |
| 168 } | 171 } |
| 169 | 172 |
| 170 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { | 173 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { |
| 171 // Make sure there is a user to switch to. | 174 // Make sure there is a user to switch to. |
| 172 if (NumberOfLoggedInUsers() <= 1) | 175 if (NumberOfLoggedInUsers() <= 1) |
| 173 return; | 176 return; |
| 174 | 177 |
| 175 const user_manager::UserList& logged_in_users = | 178 const user_manager::UserList& logged_in_users = |
| 176 user_manager::UserManager::Get()->GetLoggedInUsers(); | 179 user_manager::UserManager::Get()->GetLoggedInUsers(); |
| 177 | 180 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 200 user_id = (*it)->email(); | 203 user_id = (*it)->email(); |
| 201 break; | 204 break; |
| 202 case CYCLE_TO_PREVIOUS_USER: | 205 case CYCLE_TO_PREVIOUS_USER: |
| 203 if (it == logged_in_users.begin()) | 206 if (it == logged_in_users.begin()) |
| 204 it = logged_in_users.end(); | 207 it = logged_in_users.end(); |
| 205 user_id = (*(--it))->email(); | 208 user_id = (*(--it))->email(); |
| 206 break; | 209 break; |
| 207 } | 210 } |
| 208 | 211 |
| 209 // Switch using the transformed |user_id|. | 212 // Switch using the transformed |user_id|. |
| 210 user_manager::UserManager::Get()->SwitchActiveUser(user_id); | 213 TryToSwitchUser(user_id); |
| 211 } | 214 } |
| 212 | 215 |
| 213 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() | 216 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() |
| 214 const { | 217 const { |
| 215 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == | 218 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == |
| 216 chromeos::MultiProfileUserController::ALLOWED; | 219 chromeos::MultiProfileUserController::ALLOWED; |
| 217 } | 220 } |
| 218 | 221 |
| 219 void SessionStateDelegateChromeos::AddSessionStateObserver( | 222 void SessionStateDelegateChromeos::AddSessionStateObserver( |
| 220 ash::SessionStateObserver* observer) { | 223 ash::SessionStateObserver* observer) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 263 |
| 261 session_state_ = new_state; | 264 session_state_ = new_state; |
| 262 NotifySessionStateChanged(); | 265 NotifySessionStateChanged(); |
| 263 } | 266 } |
| 264 | 267 |
| 265 void SessionStateDelegateChromeos::NotifySessionStateChanged() { | 268 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
| 266 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 269 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 267 session_state_observer_list_, | 270 session_state_observer_list_, |
| 268 SessionStateChanged(session_state_)); | 271 SessionStateChanged(session_state_)); |
| 269 } | 272 } |
| 273 |
| 274 void DoSwitchUser(const std::string& user_id) { |
| 275 user_manager::UserManager::Get()->SwitchActiveUser(user_id); |
| 276 } |
| 277 |
| 278 void SessionStateDelegateChromeos::TryToSwitchUser( |
| 279 const std::string& user_id) { |
| 280 ash::TrySwitchingActiveUser(base::Bind(&DoSwitchUser, user_id)); |
| 281 } |
| OLD | NEW |