| 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_state_observer.h" | 8 #include "ash/session_state_observer.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/chromeos/login/screen_locker.h" | 12 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 13 #include "chrome/browser/chromeos/login/user.h" | 13 #include "chrome/browser/chromeos/login/user.h" |
| 14 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 14 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #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" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 22 #include "chromeos/dbus/session_manager_client.h" | 22 #include "chromeos/dbus/session_manager_client.h" |
| 23 #include "chromeos/login/login_state.h" |
| 23 #include "google_apis/gaia/gaia_auth_util.h" | 24 #include "google_apis/gaia/gaia_auth_util.h" |
| 24 | 25 |
| 25 SessionStateDelegateChromeos::SessionStateDelegateChromeos() { | 26 SessionStateDelegateChromeos::SessionStateDelegateChromeos() |
| 27 : session_state_(SESSION_STATE_LOGIN_PRIMARY), |
| 28 initialized_(false) { |
| 29 chromeos::LoginState::Get()->AddObserver(this); |
| 26 chromeos::UserManager::Get()->AddSessionStateObserver(this); | 30 chromeos::UserManager::Get()->AddSessionStateObserver(this); |
| 31 chromeos::UserAddingScreen::Get()->AddObserver(this); |
| 32 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? |
| 33 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); |
| 27 } | 34 } |
| 28 | 35 |
| 29 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { | 36 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { |
| 37 chromeos::LoginState::Get()->RemoveObserver(this); |
| 38 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); |
| 39 chromeos::UserAddingScreen::Get()->RemoveObserver(this); |
| 30 } | 40 } |
| 31 | 41 |
| 32 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( | 42 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( |
| 33 ash::MultiProfileIndex index) { | 43 ash::MultiProfileIndex index) { |
| 34 DCHECK_LT(index, NumberOfLoggedInUsers()); | 44 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 35 chromeos::User* user = | 45 chromeos::User* user = |
| 36 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; | 46 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; |
| 37 DCHECK(user); | 47 DCHECK(user); |
| 38 return chromeos::UserManager::Get()->GetProfileByUser(user); | 48 return chromeos::UserManager::Get()->GetProfileByUser(user); |
| 39 } | 49 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 114 } |
| 105 | 115 |
| 106 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { | 116 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { |
| 107 bool has_login_manager = CommandLine::ForCurrentProcess()->HasSwitch( | 117 bool has_login_manager = CommandLine::ForCurrentProcess()->HasSwitch( |
| 108 chromeos::switches::kLoginManager); | 118 chromeos::switches::kLoginManager); |
| 109 return (has_login_manager && !IsActiveUserSessionStarted()) || | 119 return (has_login_manager && !IsActiveUserSessionStarted()) || |
| 110 IsScreenLocked() || | 120 IsScreenLocked() || |
| 111 chromeos::UserAddingScreen::Get()->IsRunning(); | 121 chromeos::UserAddingScreen::Get()->IsRunning(); |
| 112 } | 122 } |
| 113 | 123 |
| 124 ash::SessionStateDelegate::SessionState |
| 125 SessionStateDelegateChromeos::GetSessionState() const { |
| 126 DCHECK(initialized_); |
| 127 return session_state_; |
| 128 } |
| 129 |
| 114 const base::string16 SessionStateDelegateChromeos::GetUserDisplayName( | 130 const base::string16 SessionStateDelegateChromeos::GetUserDisplayName( |
| 115 ash::MultiProfileIndex index) const { | 131 ash::MultiProfileIndex index) const { |
| 116 DCHECK_LT(index, NumberOfLoggedInUsers()); | 132 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 117 return chromeos::UserManager::Get()-> | 133 return chromeos::UserManager::Get()-> |
| 118 GetLRULoggedInUsers()[index]->display_name(); | 134 GetLRULoggedInUsers()[index]->display_name(); |
| 119 } | 135 } |
| 120 | 136 |
| 121 const std::string SessionStateDelegateChromeos::GetUserEmail( | 137 const std::string SessionStateDelegateChromeos::GetUserEmail( |
| 122 ash::MultiProfileIndex index) const { | 138 ash::MultiProfileIndex index) const { |
| 123 DCHECK_LT(index, NumberOfLoggedInUsers()); | 139 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 void SessionStateDelegateChromeos::AddSessionStateObserver( | 217 void SessionStateDelegateChromeos::AddSessionStateObserver( |
| 202 ash::SessionStateObserver* observer) { | 218 ash::SessionStateObserver* observer) { |
| 203 session_state_observer_list_.AddObserver(observer); | 219 session_state_observer_list_.AddObserver(observer); |
| 204 } | 220 } |
| 205 | 221 |
| 206 void SessionStateDelegateChromeos::RemoveSessionStateObserver( | 222 void SessionStateDelegateChromeos::RemoveSessionStateObserver( |
| 207 ash::SessionStateObserver* observer) { | 223 ash::SessionStateObserver* observer) { |
| 208 session_state_observer_list_.RemoveObserver(observer); | 224 session_state_observer_list_.RemoveObserver(observer); |
| 209 } | 225 } |
| 210 | 226 |
| 227 void SessionStateDelegateChromeos::LoggedInStateChanged() { |
| 228 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? |
| 229 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); |
| 230 } |
| 231 |
| 211 void SessionStateDelegateChromeos::ActiveUserChanged( | 232 void SessionStateDelegateChromeos::ActiveUserChanged( |
| 212 const chromeos::User* active_user) { | 233 const chromeos::User* active_user) { |
| 213 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 234 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 214 session_state_observer_list_, | 235 session_state_observer_list_, |
| 215 ActiveUserChanged(active_user->email())); | 236 ActiveUserChanged(active_user->email())); |
| 216 } | 237 } |
| 217 | 238 |
| 218 void SessionStateDelegateChromeos::UserAddedToSession( | 239 void SessionStateDelegateChromeos::UserAddedToSession( |
| 219 const chromeos::User* added_user) { | 240 const chromeos::User* added_user) { |
| 220 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 241 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 221 session_state_observer_list_, | 242 session_state_observer_list_, |
| 222 UserAddedToSession(added_user->email())); | 243 UserAddedToSession(added_user->email())); |
| 223 } | 244 } |
| 245 |
| 246 void SessionStateDelegateChromeos::OnUserAddingStarted() { |
| 247 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); |
| 248 } |
| 249 |
| 250 void SessionStateDelegateChromeos::OnUserAddingFinished() { |
| 251 SetSessionState(SESSION_STATE_ACTIVE, false); |
| 252 } |
| 253 |
| 254 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, |
| 255 bool force) { |
| 256 if (session_state_ == new_state && !force) |
| 257 return; |
| 258 |
| 259 initialized_ = true; |
| 260 session_state_ = new_state; |
| 261 NotifySessionStateChanged(); |
| 262 } |
| 263 |
| 264 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
| 265 DCHECK(initialized_); |
| 266 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 267 session_state_observer_list_, |
| 268 SessionStateChanged(session_state_)); |
| 269 } |
| OLD | NEW |