Chromium Code Reviews| 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/shell.h" | |
|
James Cook
2014/08/20 23:33:53
Do you need this include?
Mr4D (OOO till 08-26)
2014/08/21 00:05:03
Done.
| |
| 10 #include "ash/system/chromeos/multi_user/try_switching_user.h" | |
|
James Cook
2014/08/20 23:33:53
This filename is a little weird. How about somethi
Mr4D (OOO till 08-26)
2014/08/21 00:05:03
I have found some similarly named cc/h files. But
| |
| 11 #include "base/bind.h" | |
| 12 #include "base/callback.h" | |
| 9 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 14 #include "base/logging.h" |
| 11 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 16 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 17 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 18 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 22 #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 } | 161 } |
| 158 | 162 |
| 159 void SessionStateDelegateChromeos::SwitchActiveUser( | 163 void SessionStateDelegateChromeos::SwitchActiveUser( |
| 160 const std::string& user_id) { | 164 const std::string& user_id) { |
| 161 // Disallow switching to an already active user since that might crash. | 165 // 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. | 166 // Also check that we got a user id and not an email address. |
| 163 DCHECK_EQ(user_id, | 167 DCHECK_EQ(user_id, |
| 164 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); | 168 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); |
| 165 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) | 169 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) |
| 166 return; | 170 return; |
| 167 user_manager::UserManager::Get()->SwitchActiveUser(user_id); | 171 TryToSwitchUser(user_id); |
| 168 } | 172 } |
| 169 | 173 |
| 170 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { | 174 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { |
| 171 // Make sure there is a user to switch to. | 175 // Make sure there is a user to switch to. |
| 172 if (NumberOfLoggedInUsers() <= 1) | 176 if (NumberOfLoggedInUsers() <= 1) |
| 173 return; | 177 return; |
| 174 | 178 |
| 175 const user_manager::UserList& logged_in_users = | 179 const user_manager::UserList& logged_in_users = |
| 176 user_manager::UserManager::Get()->GetLoggedInUsers(); | 180 user_manager::UserManager::Get()->GetLoggedInUsers(); |
| 177 | 181 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 200 user_id = (*it)->email(); | 204 user_id = (*it)->email(); |
| 201 break; | 205 break; |
| 202 case CYCLE_TO_PREVIOUS_USER: | 206 case CYCLE_TO_PREVIOUS_USER: |
| 203 if (it == logged_in_users.begin()) | 207 if (it == logged_in_users.begin()) |
| 204 it = logged_in_users.end(); | 208 it = logged_in_users.end(); |
| 205 user_id = (*(--it))->email(); | 209 user_id = (*(--it))->email(); |
| 206 break; | 210 break; |
| 207 } | 211 } |
| 208 | 212 |
| 209 // Switch using the transformed |user_id|. | 213 // Switch using the transformed |user_id|. |
| 210 user_manager::UserManager::Get()->SwitchActiveUser(user_id); | 214 TryToSwitchUser(user_id); |
| 211 } | 215 } |
| 212 | 216 |
| 213 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() | 217 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() |
| 214 const { | 218 const { |
| 215 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == | 219 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == |
| 216 chromeos::MultiProfileUserController::ALLOWED; | 220 chromeos::MultiProfileUserController::ALLOWED; |
| 217 } | 221 } |
| 218 | 222 |
| 219 void SessionStateDelegateChromeos::AddSessionStateObserver( | 223 void SessionStateDelegateChromeos::AddSessionStateObserver( |
| 220 ash::SessionStateObserver* observer) { | 224 ash::SessionStateObserver* observer) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 | 264 |
| 261 session_state_ = new_state; | 265 session_state_ = new_state; |
| 262 NotifySessionStateChanged(); | 266 NotifySessionStateChanged(); |
| 263 } | 267 } |
| 264 | 268 |
| 265 void SessionStateDelegateChromeos::NotifySessionStateChanged() { | 269 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
| 266 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 270 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 267 session_state_observer_list_, | 271 session_state_observer_list_, |
| 268 SessionStateChanged(session_state_)); | 272 SessionStateChanged(session_state_)); |
| 269 } | 273 } |
| 274 | |
| 275 void DoSwitchUser(const std::string& user_id) { | |
| 276 user_manager::UserManager::Get()->SwitchActiveUser(user_id); | |
| 277 } | |
| 278 | |
| 279 void SessionStateDelegateChromeos::TryToSwitchUser( | |
| 280 const std::string& user_id) { | |
| 281 base::Callback<void()> switch_user = base::Bind(&DoSwitchUser, user_id); | |
| 282 ash::TrySwitchingActiveUser(switch_user); | |
|
James Cook
2014/08/20 23:33:53
nit: You could just put the base::Bind() call here
Mr4D (OOO till 08-26)
2014/08/21 00:05:03
Done.
| |
| 283 } | |
| OLD | NEW |