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