| 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 "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/lock/screen_locker.h" | 12 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 14 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 20 #include "chromeos/chromeos_switches.h" | 19 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 22 #include "chromeos/dbus/session_manager_client.h" | 21 #include "chromeos/dbus/session_manager_client.h" |
| 23 #include "chromeos/login/login_state.h" | 22 #include "chromeos/login/login_state.h" |
| 24 #include "components/user_manager/user.h" | 23 #include "components/user_manager/user.h" |
| 24 #include "components/user_manager/user_manager.h" |
| 25 #include "google_apis/gaia/gaia_auth_util.h" | 25 #include "google_apis/gaia/gaia_auth_util.h" |
| 26 | 26 |
| 27 SessionStateDelegateChromeos::SessionStateDelegateChromeos() | 27 SessionStateDelegateChromeos::SessionStateDelegateChromeos() |
| 28 : session_state_(SESSION_STATE_LOGIN_PRIMARY) { | 28 : session_state_(SESSION_STATE_LOGIN_PRIMARY) { |
| 29 chromeos::UserManager::Get()->AddSessionStateObserver(this); | 29 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
| 30 chromeos::UserAddingScreen::Get()->AddObserver(this); | 30 chromeos::UserAddingScreen::Get()->AddObserver(this); |
| 31 | 31 |
| 32 // LoginState is not initialized in unit_tests. | 32 // LoginState is not initialized in unit_tests. |
| 33 if (chromeos::LoginState::IsInitialized()) { | 33 if (chromeos::LoginState::IsInitialized()) { |
| 34 chromeos::LoginState::Get()->AddObserver(this); | 34 chromeos::LoginState::Get()->AddObserver(this); |
| 35 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? | 35 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? |
| 36 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); | 36 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { | 40 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { |
| 41 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | 41 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
| 42 chromeos::UserAddingScreen::Get()->RemoveObserver(this); | 42 chromeos::UserAddingScreen::Get()->RemoveObserver(this); |
| 43 | 43 |
| 44 // LoginState is not initialized in unit_tests. | 44 // LoginState is not initialized in unit_tests. |
| 45 if (chromeos::LoginState::IsInitialized()) | 45 if (chromeos::LoginState::IsInitialized()) |
| 46 chromeos::LoginState::Get()->RemoveObserver(this); | 46 chromeos::LoginState::Get()->RemoveObserver(this); |
| 47 } | 47 } |
| 48 | 48 |
| 49 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( | 49 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( |
| 50 ash::MultiProfileIndex index) { | 50 ash::MultiProfileIndex index) { |
| 51 DCHECK_LT(index, NumberOfLoggedInUsers()); | 51 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 52 user_manager::User* user = | 52 user_manager::User* user = |
| 53 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; | 53 user_manager::UserManager::Get()->GetLRULoggedInUsers()[index]; |
| 54 DCHECK(user); | 54 DCHECK(user); |
| 55 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 55 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
| 56 } | 56 } |
| 57 | 57 |
| 58 content::BrowserContext* | 58 content::BrowserContext* |
| 59 SessionStateDelegateChromeos::GetBrowserContextForWindow( | 59 SessionStateDelegateChromeos::GetBrowserContextForWindow( |
| 60 aura::Window* window) { | 60 aura::Window* window) { |
| 61 const std::string& user_id = | 61 const std::string& user_id = |
| 62 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); | 62 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); |
| 63 const user_manager::User* user = | 63 const user_manager::User* user = |
| 64 chromeos::UserManager::Get()->FindUser(user_id); | 64 user_manager::UserManager::Get()->FindUser(user_id); |
| 65 DCHECK(user); | 65 DCHECK(user); |
| 66 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 66 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
| 67 } | 67 } |
| 68 | 68 |
| 69 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { | 69 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { |
| 70 // We limit list of logged in users to 10 due to memory constraints. | 70 // We limit list of logged in users to 10 due to memory constraints. |
| 71 // Note that 10 seems excessive, but we want to test how many users are | 71 // Note that 10 seems excessive, but we want to test how many users are |
| 72 // actually added to a session. | 72 // actually added to a session. |
| 73 // TODO(nkostylev): Adjust this limitation based on device capabilites. | 73 // TODO(nkostylev): Adjust this limitation based on device capabilites. |
| 74 // http://crbug.com/230865 | 74 // http://crbug.com/230865 |
| 75 return 10; | 75 return 10; |
| 76 } | 76 } |
| 77 | 77 |
| 78 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { | 78 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { |
| 79 return chromeos::UserManager::Get()->GetLoggedInUsers().size(); | 79 return user_manager::UserManager::Get()->GetLoggedInUsers().size(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { | 82 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { |
| 83 return chromeos::UserManager::Get()->IsSessionStarted(); | 83 return user_manager::UserManager::Get()->IsSessionStarted(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool SessionStateDelegateChromeos::CanLockScreen() const { | 86 bool SessionStateDelegateChromeos::CanLockScreen() const { |
| 87 const user_manager::UserList unlock_users = | 87 const user_manager::UserList unlock_users = |
| 88 chromeos::UserManager::Get()->GetUnlockUsers(); | 88 user_manager::UserManager::Get()->GetUnlockUsers(); |
| 89 return !unlock_users.empty(); | 89 return !unlock_users.empty(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool SessionStateDelegateChromeos::IsScreenLocked() const { | 92 bool SessionStateDelegateChromeos::IsScreenLocked() const { |
| 93 return chromeos::ScreenLocker::default_screen_locker() && | 93 return chromeos::ScreenLocker::default_screen_locker() && |
| 94 chromeos::ScreenLocker::default_screen_locker()->locked(); | 94 chromeos::ScreenLocker::default_screen_locker()->locked(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const { | 97 bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const { |
| 98 const user_manager::UserList logged_in_users = | 98 const user_manager::UserList logged_in_users = |
| 99 chromeos::UserManager::Get()->GetLoggedInUsers(); | 99 user_manager::UserManager::Get()->GetLoggedInUsers(); |
| 100 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); | 100 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); |
| 101 it != logged_in_users.end(); | 101 it != logged_in_users.end(); |
| 102 ++it) { | 102 ++it) { |
| 103 user_manager::User* user = (*it); | 103 user_manager::User* user = (*it); |
| 104 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 104 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
| 105 if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) | 105 if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 131 } | 131 } |
| 132 | 132 |
| 133 ash::SessionStateDelegate::SessionState | 133 ash::SessionStateDelegate::SessionState |
| 134 SessionStateDelegateChromeos::GetSessionState() const { | 134 SessionStateDelegateChromeos::GetSessionState() const { |
| 135 return session_state_; | 135 return session_state_; |
| 136 } | 136 } |
| 137 | 137 |
| 138 const user_manager::UserInfo* SessionStateDelegateChromeos::GetUserInfo( | 138 const user_manager::UserInfo* SessionStateDelegateChromeos::GetUserInfo( |
| 139 ash::MultiProfileIndex index) const { | 139 ash::MultiProfileIndex index) const { |
| 140 DCHECK_LT(index, NumberOfLoggedInUsers()); | 140 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 141 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; | 141 return user_manager::UserManager::Get()->GetLRULoggedInUsers()[index]; |
| 142 } | 142 } |
| 143 | 143 |
| 144 const user_manager::UserInfo* SessionStateDelegateChromeos::GetUserInfo( | 144 const user_manager::UserInfo* SessionStateDelegateChromeos::GetUserInfo( |
| 145 content::BrowserContext* context) const { | 145 content::BrowserContext* context) const { |
| 146 DCHECK(context); | 146 DCHECK(context); |
| 147 return chromeos::ProfileHelper::Get()->GetUserByProfile( | 147 return chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 148 Profile::FromBrowserContext(context)); | 148 Profile::FromBrowserContext(context)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool SessionStateDelegateChromeos::ShouldShowAvatar( | 151 bool SessionStateDelegateChromeos::ShouldShowAvatar( |
| 152 aura::Window* window) const { | 152 aura::Window* window) const { |
| 153 return chrome::MultiUserWindowManager::GetInstance()-> | 153 return chrome::MultiUserWindowManager::GetInstance()-> |
| 154 ShouldShowAvatar(window); | 154 ShouldShowAvatar(window); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void SessionStateDelegateChromeos::SwitchActiveUser( | 157 void SessionStateDelegateChromeos::SwitchActiveUser( |
| 158 const std::string& user_id) { | 158 const std::string& user_id) { |
| 159 // Disallow switching to an already active user since that might crash. | 159 // Disallow switching to an already active user since that might crash. |
| 160 // Also check that we got a user id and not an email address. | 160 // Also check that we got a user id and not an email address. |
| 161 DCHECK_EQ(user_id, | 161 DCHECK_EQ(user_id, |
| 162 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); | 162 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); |
| 163 if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) | 163 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) |
| 164 return; | 164 return; |
| 165 chromeos::UserManager::Get()->SwitchActiveUser(user_id); | 165 user_manager::UserManager::Get()->SwitchActiveUser(user_id); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { | 168 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { |
| 169 // Make sure there is a user to switch to. | 169 // Make sure there is a user to switch to. |
| 170 if (NumberOfLoggedInUsers() <= 1) | 170 if (NumberOfLoggedInUsers() <= 1) |
| 171 return; | 171 return; |
| 172 | 172 |
| 173 const user_manager::UserList& logged_in_users = | 173 const user_manager::UserList& logged_in_users = |
| 174 chromeos::UserManager::Get()->GetLoggedInUsers(); | 174 user_manager::UserManager::Get()->GetLoggedInUsers(); |
| 175 | 175 |
| 176 std::string user_id = chromeos::UserManager::Get()->GetActiveUser()->email(); | 176 std::string user_id = |
| 177 user_manager::UserManager::Get()->GetActiveUser()->email(); |
| 177 | 178 |
| 178 // Get an iterator positioned at the active user. | 179 // Get an iterator positioned at the active user. |
| 179 user_manager::UserList::const_iterator it; | 180 user_manager::UserList::const_iterator it; |
| 180 for (it = logged_in_users.begin(); | 181 for (it = logged_in_users.begin(); |
| 181 it != logged_in_users.end(); ++it) { | 182 it != logged_in_users.end(); ++it) { |
| 182 if ((*it)->email() == user_id) | 183 if ((*it)->email() == user_id) |
| 183 break; | 184 break; |
| 184 } | 185 } |
| 185 | 186 |
| 186 // Active user not found. | 187 // Active user not found. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 197 user_id = (*it)->email(); | 198 user_id = (*it)->email(); |
| 198 break; | 199 break; |
| 199 case CYCLE_TO_PREVIOUS_USER: | 200 case CYCLE_TO_PREVIOUS_USER: |
| 200 if (it == logged_in_users.begin()) | 201 if (it == logged_in_users.begin()) |
| 201 it = logged_in_users.end(); | 202 it = logged_in_users.end(); |
| 202 user_id = (*(--it))->email(); | 203 user_id = (*(--it))->email(); |
| 203 break; | 204 break; |
| 204 } | 205 } |
| 205 | 206 |
| 206 // Switch using the transformed |user_id|. | 207 // Switch using the transformed |user_id|. |
| 207 chromeos::UserManager::Get()->SwitchActiveUser(user_id); | 208 user_manager::UserManager::Get()->SwitchActiveUser(user_id); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void SessionStateDelegateChromeos::AddSessionStateObserver( | 211 void SessionStateDelegateChromeos::AddSessionStateObserver( |
| 211 ash::SessionStateObserver* observer) { | 212 ash::SessionStateObserver* observer) { |
| 212 session_state_observer_list_.AddObserver(observer); | 213 session_state_observer_list_.AddObserver(observer); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void SessionStateDelegateChromeos::RemoveSessionStateObserver( | 216 void SessionStateDelegateChromeos::RemoveSessionStateObserver( |
| 216 ash::SessionStateObserver* observer) { | 217 ash::SessionStateObserver* observer) { |
| 217 session_state_observer_list_.RemoveObserver(observer); | 218 session_state_observer_list_.RemoveObserver(observer); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 252 |
| 252 session_state_ = new_state; | 253 session_state_ = new_state; |
| 253 NotifySessionStateChanged(); | 254 NotifySessionStateChanged(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void SessionStateDelegateChromeos::NotifySessionStateChanged() { | 257 void SessionStateDelegateChromeos::NotifySessionStateChanged() { |
| 257 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 258 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
| 258 session_state_observer_list_, | 259 session_state_observer_list_, |
| 259 SessionStateChanged(session_state_)); | 260 SessionStateChanged(session_state_)); |
| 260 } | 261 } |
| OLD | NEW |