| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/screens/user_selection_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/user_selection_screen.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 UserSelectionScreen::~UserSelectionScreen() { | 49 UserSelectionScreen::~UserSelectionScreen() { |
| 50 wm::UserActivityDetector* activity_detector = | 50 wm::UserActivityDetector* activity_detector = |
| 51 ash::Shell::GetInstance()->user_activity_detector(); | 51 ash::Shell::GetInstance()->user_activity_detector(); |
| 52 if (activity_detector->HasObserver(this)) | 52 if (activity_detector->HasObserver(this)) |
| 53 activity_detector->RemoveObserver(this); | 53 activity_detector->RemoveObserver(this); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 void UserSelectionScreen::FillUserDictionary( | 57 void UserSelectionScreen::FillUserDictionary( |
| 58 User* user, | 58 user_manager::User* user, |
| 59 bool is_owner, | 59 bool is_owner, |
| 60 bool is_signin_to_add, | 60 bool is_signin_to_add, |
| 61 ScreenlockBridge::LockHandler::AuthType auth_type, | 61 ScreenlockBridge::LockHandler::AuthType auth_type, |
| 62 base::DictionaryValue* user_dict) { | 62 base::DictionaryValue* user_dict) { |
| 63 const std::string& user_id = user->email(); | 63 const std::string& user_id = user->email(); |
| 64 const bool is_public_account = | 64 const bool is_public_account = |
| 65 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 65 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; |
| 66 const bool is_supervised_user = | 66 const bool is_supervised_user = |
| 67 user->GetType() == user_manager::USER_TYPE_SUPERVISED; | 67 user->GetType() == user_manager::USER_TYPE_SUPERVISED; |
| 68 | 68 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 94 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 94 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 95 | 95 |
| 96 if (policy_connector->IsEnterpriseManaged()) { | 96 if (policy_connector->IsEnterpriseManaged()) { |
| 97 user_dict->SetString(kKeyEnterpriseDomain, | 97 user_dict->SetString(kKeyEnterpriseDomain, |
| 98 policy_connector->GetEnterpriseDomain()); | 98 policy_connector->GetEnterpriseDomain()); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 bool UserSelectionScreen::ShouldForceOnlineSignIn(const User* user) { | 104 bool UserSelectionScreen::ShouldForceOnlineSignIn( |
| 105 const user_manager::User* user) { |
| 105 // Public sessions are always allowed to log in offline. | 106 // Public sessions are always allowed to log in offline. |
| 106 // Supervised user are allowed to log in offline if their OAuth token status | 107 // Supervised user are allowed to log in offline if their OAuth token status |
| 107 // is unknown or valid. | 108 // is unknown or valid. |
| 108 // For all other users, force online sign in if: | 109 // For all other users, force online sign in if: |
| 109 // * The flag to force online sign-in is set for the user. | 110 // * The flag to force online sign-in is set for the user. |
| 110 // * The user's OAuth token is invalid. | 111 // * The user's OAuth token is invalid. |
| 111 // * The user's OAuth token status is unknown (except supervised users, | 112 // * The user's OAuth token status is unknown (except supervised users, |
| 112 // see above). | 113 // see above). |
| 113 if (user->is_logged_in()) | 114 if (user->is_logged_in()) |
| 114 return false; | 115 return false; |
| 115 | 116 |
| 116 const User::OAuthTokenStatus token_status = user->oauth_token_status(); | 117 const user_manager::User::OAuthTokenStatus token_status = |
| 118 user->oauth_token_status(); |
| 117 const bool is_supervised_user = | 119 const bool is_supervised_user = |
| 118 user->GetType() == user_manager::USER_TYPE_SUPERVISED; | 120 user->GetType() == user_manager::USER_TYPE_SUPERVISED; |
| 119 const bool is_public_session = | 121 const bool is_public_session = |
| 120 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 122 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; |
| 121 | 123 |
| 122 if (is_supervised_user && | 124 if (is_supervised_user && |
| 123 token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN) { | 125 token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN) { |
| 124 return false; | 126 return false; |
| 125 } | 127 } |
| 126 | 128 |
| 127 if (is_public_session) | 129 if (is_public_session) |
| 128 return false; | 130 return false; |
| 129 | 131 |
| 130 return user->force_online_signin() || | 132 return user->force_online_signin() || |
| 131 (token_status == User::OAUTH2_TOKEN_STATUS_INVALID) || | 133 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) || |
| 132 (token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN); | 134 (token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); |
| 133 } | 135 } |
| 134 | 136 |
| 135 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { | 137 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { |
| 136 handler_ = handler; | 138 handler_ = handler; |
| 137 } | 139 } |
| 138 | 140 |
| 139 void UserSelectionScreen::Init(const UserList& users, bool show_guest) { | 141 void UserSelectionScreen::Init(const user_manager::UserList& users, |
| 142 bool show_guest) { |
| 140 users_ = users; | 143 users_ = users; |
| 141 show_guest_ = show_guest; | 144 show_guest_ = show_guest; |
| 142 | 145 |
| 143 wm::UserActivityDetector* activity_detector = | 146 wm::UserActivityDetector* activity_detector = |
| 144 ash::Shell::GetInstance()->user_activity_detector(); | 147 ash::Shell::GetInstance()->user_activity_detector(); |
| 145 if (!activity_detector->HasObserver(this)) | 148 if (!activity_detector->HasObserver(this)) |
| 146 activity_detector->AddObserver(this); | 149 activity_detector->AddObserver(this); |
| 147 } | 150 } |
| 148 | 151 |
| 149 void UserSelectionScreen::OnBeforeUserRemoved(const std::string& username) { | 152 void UserSelectionScreen::OnBeforeUserRemoved(const std::string& username) { |
| 150 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | 153 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); |
| 154 ++it) { |
| 151 if ((*it)->email() == username) { | 155 if ((*it)->email() == username) { |
| 152 users_.erase(it); | 156 users_.erase(it); |
| 153 break; | 157 break; |
| 154 } | 158 } |
| 155 } | 159 } |
| 156 } | 160 } |
| 157 | 161 |
| 158 void UserSelectionScreen::OnUserRemoved(const std::string& username) { | 162 void UserSelectionScreen::OnUserRemoved(const std::string& username) { |
| 159 if (!handler_) | 163 if (!handler_) |
| 160 return; | 164 return; |
| 161 | 165 |
| 162 handler_->OnUserRemoved(username); | 166 handler_->OnUserRemoved(username); |
| 163 } | 167 } |
| 164 | 168 |
| 165 void UserSelectionScreen::OnUserImageChanged(const User& user) { | 169 void UserSelectionScreen::OnUserImageChanged(const user_manager::User& user) { |
| 166 if (!handler_) | 170 if (!handler_) |
| 167 return; | 171 return; |
| 168 handler_->OnUserImageChanged(user); | 172 handler_->OnUserImageChanged(user); |
| 169 // TODO(antrim) : updateUserImage(user.email()) | 173 // TODO(antrim) : updateUserImage(user.email()) |
| 170 } | 174 } |
| 171 | 175 |
| 172 const UserList& UserSelectionScreen::GetUsers() const { | 176 const user_manager::UserList& UserSelectionScreen::GetUsers() const { |
| 173 return users_; | 177 return users_; |
| 174 } | 178 } |
| 175 | 179 |
| 176 void UserSelectionScreen::OnPasswordClearTimerExpired() { | 180 void UserSelectionScreen::OnPasswordClearTimerExpired() { |
| 177 if (handler_) | 181 if (handler_) |
| 178 handler_->ClearUserPodPassword(); | 182 handler_->ClearUserPodPassword(); |
| 179 } | 183 } |
| 180 | 184 |
| 181 void UserSelectionScreen::OnUserActivity(const ui::Event* event) { | 185 void UserSelectionScreen::OnUserActivity(const ui::Event* event) { |
| 182 if (!password_clear_timer_.IsRunning()) { | 186 if (!password_clear_timer_.IsRunning()) { |
| 183 password_clear_timer_.Start( | 187 password_clear_timer_.Start( |
| 184 FROM_HERE, | 188 FROM_HERE, |
| 185 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), | 189 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), |
| 186 this, | 190 this, |
| 187 &UserSelectionScreen::OnPasswordClearTimerExpired); | 191 &UserSelectionScreen::OnPasswordClearTimerExpired); |
| 188 } | 192 } |
| 189 password_clear_timer_.Reset(); | 193 password_clear_timer_.Reset(); |
| 190 } | 194 } |
| 191 | 195 |
| 192 // static | 196 // static |
| 193 const UserList UserSelectionScreen::PrepareUserListForSending( | 197 const user_manager::UserList UserSelectionScreen::PrepareUserListForSending( |
| 194 const UserList& users, | 198 const user_manager::UserList& users, |
| 195 std::string owner, | 199 std::string owner, |
| 196 bool is_signin_to_add) { | 200 bool is_signin_to_add) { |
| 197 | 201 user_manager::UserList users_to_send; |
| 198 UserList users_to_send; | |
| 199 bool has_owner = owner.size() > 0; | 202 bool has_owner = owner.size() > 0; |
| 200 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; | 203 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; |
| 201 size_t non_owner_count = 0; | 204 size_t non_owner_count = 0; |
| 202 | 205 |
| 203 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 206 for (user_manager::UserList::const_iterator it = users.begin(); |
| 207 it != users.end(); |
| 208 ++it) { |
| 204 const std::string& user_id = (*it)->email(); | 209 const std::string& user_id = (*it)->email(); |
| 205 bool is_owner = (user_id == owner); | 210 bool is_owner = (user_id == owner); |
| 206 bool is_public_account = | 211 bool is_public_account = |
| 207 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); | 212 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); |
| 208 | 213 |
| 209 if ((is_public_account && !is_signin_to_add) || is_owner || | 214 if ((is_public_account && !is_signin_to_add) || is_owner || |
| 210 (!is_public_account && non_owner_count < max_non_owner_users)) { | 215 (!is_public_account && non_owner_count < max_non_owner_users)) { |
| 211 | 216 |
| 212 if (!is_owner) | 217 if (!is_owner) |
| 213 ++non_owner_count; | 218 ++non_owner_count; |
| 214 if (is_owner && users_to_send.size() > kMaxUsers) { | 219 if (is_owner && users_to_send.size() > kMaxUsers) { |
| 215 // Owner is always in the list. | 220 // Owner is always in the list. |
| 216 users_to_send.insert(users_to_send.begin() + (kMaxUsers - 1), *it); | 221 users_to_send.insert(users_to_send.begin() + (kMaxUsers - 1), *it); |
| 217 while (users_to_send.size() > kMaxUsers) | 222 while (users_to_send.size() > kMaxUsers) |
| 218 users_to_send.erase(users_to_send.begin() + kMaxUsers); | 223 users_to_send.erase(users_to_send.begin() + kMaxUsers); |
| 219 } else if (users_to_send.size() < kMaxUsers) { | 224 } else if (users_to_send.size() < kMaxUsers) { |
| 220 users_to_send.push_back(*it); | 225 users_to_send.push_back(*it); |
| 221 } | 226 } |
| 222 } | 227 } |
| 223 } | 228 } |
| 224 return users_to_send; | 229 return users_to_send; |
| 225 } | 230 } |
| 226 | 231 |
| 227 void UserSelectionScreen::SendUserList() { | 232 void UserSelectionScreen::SendUserList() { |
| 228 base::ListValue users_list; | 233 base::ListValue users_list; |
| 229 const UserList& users = GetUsers(); | 234 const user_manager::UserList& users = GetUsers(); |
| 230 | 235 |
| 231 // TODO(nkostylev): Move to a separate method in UserManager. | 236 // TODO(nkostylev): Move to a separate method in UserManager. |
| 232 // http://crbug.com/230852 | 237 // http://crbug.com/230852 |
| 233 bool single_user = users.size() == 1; | 238 bool single_user = users.size() == 1; |
| 234 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && | 239 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && |
| 235 UserManager::Get()->IsUserLoggedIn(); | 240 UserManager::Get()->IsUserLoggedIn(); |
| 236 std::string owner; | 241 std::string owner; |
| 237 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); | 242 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); |
| 238 | 243 |
| 239 policy::BrowserPolicyConnectorChromeOS* connector = | 244 policy::BrowserPolicyConnectorChromeOS* connector = |
| 240 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 245 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 241 bool is_enterprise_managed = connector->IsEnterpriseManaged(); | 246 bool is_enterprise_managed = connector->IsEnterpriseManaged(); |
| 242 | 247 |
| 243 const UserList users_to_send = PrepareUserListForSending(users, | 248 const user_manager::UserList users_to_send = |
| 244 owner, | 249 PrepareUserListForSending(users, owner, is_signin_to_add); |
| 245 is_signin_to_add); | |
| 246 | 250 |
| 247 user_auth_type_map_.clear(); | 251 user_auth_type_map_.clear(); |
| 248 | 252 |
| 249 for (UserList::const_iterator it = users_to_send.begin(); | 253 for (user_manager::UserList::const_iterator it = users_to_send.begin(); |
| 250 it != users_to_send.end(); | 254 it != users_to_send.end(); |
| 251 ++it) { | 255 ++it) { |
| 252 const std::string& user_id = (*it)->email(); | 256 const std::string& user_id = (*it)->email(); |
| 253 bool is_owner = (user_id == owner); | 257 bool is_owner = (user_id == owner); |
| 254 const bool is_public_account = | 258 const bool is_public_account = |
| 255 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); | 259 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); |
| 256 const ScreenlockBridge::LockHandler::AuthType initial_auth_type = | 260 const ScreenlockBridge::LockHandler::AuthType initial_auth_type = |
| 257 is_public_account | 261 is_public_account |
| 258 ? ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK | 262 ? ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK |
| 259 : (ShouldForceOnlineSignIn(*it) | 263 : (ShouldForceOnlineSignIn(*it) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 289 } | 293 } |
| 290 | 294 |
| 291 ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( | 295 ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( |
| 292 const std::string& username) const { | 296 const std::string& username) const { |
| 293 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) | 297 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) |
| 294 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | 298 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; |
| 295 return user_auth_type_map_.find(username)->second; | 299 return user_auth_type_map_.find(username)->second; |
| 296 } | 300 } |
| 297 | 301 |
| 298 } // namespace chromeos | 302 } // namespace chromeos |
| OLD | NEW |