| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const char kKeyEnterpriseDomain[] = "enterpriseDomain"; | 35 const char kKeyEnterpriseDomain[] = "enterpriseDomain"; |
| 36 const char kKeyPublicAccount[] = "publicAccount"; | 36 const char kKeyPublicAccount[] = "publicAccount"; |
| 37 const char kKeySupervisedUser[] = "supervisedUser"; | 37 const char kKeySupervisedUser[] = "supervisedUser"; |
| 38 const char kKeySignedIn[] = "signedIn"; | 38 const char kKeySignedIn[] = "signedIn"; |
| 39 const char kKeyCanRemove[] = "canRemove"; | 39 const char kKeyCanRemove[] = "canRemove"; |
| 40 const char kKeyIsOwner[] = "isOwner"; | 40 const char kKeyIsOwner[] = "isOwner"; |
| 41 const char kKeyInitialAuthType[] = "initialAuthType"; | 41 const char kKeyInitialAuthType[] = "initialAuthType"; |
| 42 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; | 42 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; |
| 43 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; | 43 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; |
| 44 const char kKeyInitialLocales[] = "initialLocales"; | 44 const char kKeyInitialLocales[] = "initialLocales"; |
| 45 const char kKeyInitialLocale[] = "initialLocale"; |
| 46 const char kKeyInitialMultipleRecommendedLocales[] = |
| 47 "initialMultipleRecommendedLocales"; |
| 45 const char kKeyInitialKeyboardLayout[] = "initialKeyboardLayout"; | 48 const char kKeyInitialKeyboardLayout[] = "initialKeyboardLayout"; |
| 46 | 49 |
| 47 // Max number of users to show. | 50 // Max number of users to show. |
| 48 // Please keep synced with one in signin_userlist_unittest.cc. | 51 // Please keep synced with one in signin_userlist_unittest.cc. |
| 49 const size_t kMaxUsers = 18; | 52 const size_t kMaxUsers = 18; |
| 50 | 53 |
| 51 const int kPasswordClearTimeoutSec = 60; | 54 const int kPasswordClearTimeoutSec = 60; |
| 52 | 55 |
| 56 void AddPublicSessionDetailsToUserDictionaryEntry( |
| 57 base::DictionaryValue* user_dict, |
| 58 const std::vector<std::string>* public_session_recommended_locales) { |
| 59 policy::BrowserPolicyConnectorChromeOS* policy_connector = |
| 60 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 61 |
| 62 if (policy_connector->IsEnterpriseManaged()) { |
| 63 user_dict->SetString(kKeyEnterpriseDomain, |
| 64 policy_connector->GetEnterpriseDomain()); |
| 65 } |
| 66 |
| 67 std::vector<std::string> kEmptyRecommendedLocales; |
| 68 const std::vector<std::string>* recommended_locales = |
| 69 public_session_recommended_locales ? |
| 70 public_session_recommended_locales : &kEmptyRecommendedLocales; |
| 71 |
| 72 // Set |kKeyInitialLocales| to the list of available locales. This list |
| 73 // consists of the recommended locales, followed by all others. |
| 74 user_dict->Set( |
| 75 kKeyInitialLocales, |
| 76 GetUILanguageList(recommended_locales, std::string()).release()); |
| 77 |
| 78 // Set |kKeyInitialLocale| to the initially selected locale. If the list of |
| 79 // recommended locales is not empty, select its first entry. Otherwise, |
| 80 // select the current UI locale. |
| 81 user_dict->SetString(kKeyInitialLocale, |
| 82 recommended_locales->empty() ? |
| 83 g_browser_process->GetApplicationLocale() : |
| 84 recommended_locales->front()); |
| 85 |
| 86 // Set |kKeyInitialMultipleRecommendedLocales| to indicate whether the list |
| 87 // of recommended locales contains at least two entries. This is used to |
| 88 // decide whether the public session pod expands to its basic form (for zero |
| 89 // or one recommended locales) or the advanced form (two or more recommended |
| 90 // locales). |
| 91 user_dict->SetBoolean(kKeyInitialMultipleRecommendedLocales, |
| 92 recommended_locales->size() >= 2); |
| 93 |
| 94 // Set |kKeyInitialKeyboardLayout| to the current keyboard layout. This |
| 95 // value will be used temporarily only because the UI immediately requests a |
| 96 // list of keyboard layouts suitable for the currently selected locale. |
| 97 user_dict->Set(kKeyInitialKeyboardLayout, |
| 98 GetCurrentKeyboardLayout().release()); |
| 99 } |
| 100 |
| 53 } // namespace | 101 } // namespace |
| 54 | 102 |
| 55 UserSelectionScreen::UserSelectionScreen() : handler_(NULL) { | 103 UserSelectionScreen::UserSelectionScreen() : handler_(NULL) { |
| 56 } | 104 } |
| 57 | 105 |
| 58 UserSelectionScreen::~UserSelectionScreen() { | 106 UserSelectionScreen::~UserSelectionScreen() { |
| 59 wm::UserActivityDetector* activity_detector = | 107 wm::UserActivityDetector* activity_detector = |
| 60 ash::Shell::GetInstance()->user_activity_detector(); | 108 ash::Shell::GetInstance()->user_activity_detector(); |
| 61 if (activity_detector->HasObserver(this)) | 109 if (activity_detector->HasObserver(this)) |
| 62 activity_detector->RemoveObserver(this); | 110 activity_detector->RemoveObserver(this); |
| 63 } | 111 } |
| 64 | 112 |
| 65 // static | 113 // static |
| 66 void UserSelectionScreen::FillUserDictionary( | 114 void UserSelectionScreen::FillUserDictionary( |
| 67 user_manager::User* user, | 115 user_manager::User* user, |
| 68 bool is_owner, | 116 bool is_owner, |
| 69 bool is_signin_to_add, | 117 bool is_signin_to_add, |
| 70 ScreenlockBridge::LockHandler::AuthType auth_type, | 118 ScreenlockBridge::LockHandler::AuthType auth_type, |
| 119 const std::vector<std::string>* public_session_recommended_locales, |
| 71 base::DictionaryValue* user_dict) { | 120 base::DictionaryValue* user_dict) { |
| 72 const std::string& user_id = user->email(); | 121 const std::string& user_id = user->email(); |
| 73 const bool is_public_account = | 122 const bool is_public_session = |
| 74 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 123 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; |
| 75 const bool is_supervised_user = | 124 const bool is_supervised_user = |
| 76 user->GetType() == user_manager::USER_TYPE_SUPERVISED; | 125 user->GetType() == user_manager::USER_TYPE_SUPERVISED; |
| 77 | 126 |
| 78 user_dict->SetString(kKeyUsername, user_id); | 127 user_dict->SetString(kKeyUsername, user_id); |
| 79 user_dict->SetString(kKeyEmailAddress, user->display_email()); | 128 user_dict->SetString(kKeyEmailAddress, user->display_email()); |
| 80 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); | 129 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); |
| 81 user_dict->SetBoolean(kKeyPublicAccount, is_public_account); | 130 user_dict->SetBoolean(kKeyPublicAccount, is_public_session); |
| 82 user_dict->SetBoolean(kKeySupervisedUser, is_supervised_user); | 131 user_dict->SetBoolean(kKeySupervisedUser, is_supervised_user); |
| 83 user_dict->SetInteger(kKeyInitialAuthType, auth_type); | 132 user_dict->SetInteger(kKeyInitialAuthType, auth_type); |
| 84 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); | 133 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); |
| 85 user_dict->SetBoolean(kKeyIsOwner, is_owner); | 134 user_dict->SetBoolean(kKeyIsOwner, is_owner); |
| 86 | 135 |
| 87 // Fill in multi-profiles related fields. | 136 // Fill in multi-profiles related fields. |
| 88 if (is_signin_to_add) { | 137 if (is_signin_to_add) { |
| 89 MultiProfileUserController* multi_profile_user_controller = | 138 MultiProfileUserController* multi_profile_user_controller = |
| 90 UserManager::Get()->GetMultiProfileUserController(); | 139 UserManager::Get()->GetMultiProfileUserController(); |
| 91 MultiProfileUserController::UserAllowedInSessionReason isUserAllowedReason; | 140 MultiProfileUserController::UserAllowedInSessionReason isUserAllowedReason; |
| 92 bool isUserAllowed = multi_profile_user_controller->IsUserAllowedInSession( | 141 bool isUserAllowed = multi_profile_user_controller->IsUserAllowedInSession( |
| 93 user_id, &isUserAllowedReason); | 142 user_id, &isUserAllowedReason); |
| 94 user_dict->SetBoolean(kKeyMultiProfilesAllowed, isUserAllowed); | 143 user_dict->SetBoolean(kKeyMultiProfilesAllowed, isUserAllowed); |
| 95 | 144 |
| 96 std::string behavior; | 145 std::string behavior; |
| 97 switch (isUserAllowedReason) { | 146 switch (isUserAllowedReason) { |
| 98 case MultiProfileUserController::NOT_ALLOWED_OWNER_AS_SECONDARY: | 147 case MultiProfileUserController::NOT_ALLOWED_OWNER_AS_SECONDARY: |
| 99 behavior = MultiProfileUserController::kBehaviorOwnerPrimaryOnly; | 148 behavior = MultiProfileUserController::kBehaviorOwnerPrimaryOnly; |
| 100 break; | 149 break; |
| 101 default: | 150 default: |
| 102 behavior = multi_profile_user_controller->GetCachedValue(user_id); | 151 behavior = multi_profile_user_controller->GetCachedValue(user_id); |
| 103 } | 152 } |
| 104 user_dict->SetString(kKeyMultiProfilesPolicy, behavior); | 153 user_dict->SetString(kKeyMultiProfilesPolicy, behavior); |
| 105 } else { | 154 } else { |
| 106 user_dict->SetBoolean(kKeyMultiProfilesAllowed, true); | 155 user_dict->SetBoolean(kKeyMultiProfilesAllowed, true); |
| 107 } | 156 } |
| 108 | 157 |
| 109 if (is_public_account) { | 158 if (is_public_session) { |
| 110 policy::BrowserPolicyConnectorChromeOS* policy_connector = | 159 AddPublicSessionDetailsToUserDictionaryEntry( |
| 111 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 160 user_dict, |
| 112 | 161 public_session_recommended_locales); |
| 113 if (policy_connector->IsEnterpriseManaged()) { | |
| 114 user_dict->SetString(kKeyEnterpriseDomain, | |
| 115 policy_connector->GetEnterpriseDomain()); | |
| 116 } | |
| 117 | |
| 118 // TODO(bartfab): Initialize |most_relevant_languages| and |locale| based on | |
| 119 // policy. | |
| 120 const std::string locale = g_browser_process->GetApplicationLocale(); | |
| 121 std::vector<std::string> most_relevant_languages; | |
| 122 user_dict->Set( | |
| 123 kKeyInitialLocales, | |
| 124 GetUILanguageList(&most_relevant_languages, locale).release()); | |
| 125 user_dict->Set(kKeyInitialKeyboardLayout, | |
| 126 GetCurrentKeyboardLayout().release()); | |
| 127 } | 162 } |
| 128 } | 163 } |
| 129 | 164 |
| 130 // static | 165 // static |
| 131 bool UserSelectionScreen::ShouldForceOnlineSignIn( | 166 bool UserSelectionScreen::ShouldForceOnlineSignIn( |
| 132 const user_manager::User* user) { | 167 const user_manager::User* user) { |
| 133 // Public sessions are always allowed to log in offline. | 168 // Public sessions are always allowed to log in offline. |
| 134 // Supervised user are allowed to log in offline if their OAuth token status | 169 // Supervised user are allowed to log in offline if their OAuth token status |
| 135 // is unknown or valid. | 170 // is unknown or valid. |
| 136 // For all other users, force online sign in if: | 171 // For all other users, force online sign in if: |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 305 |
| 271 policy::BrowserPolicyConnectorChromeOS* connector = | 306 policy::BrowserPolicyConnectorChromeOS* connector = |
| 272 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 307 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 273 bool is_enterprise_managed = connector->IsEnterpriseManaged(); | 308 bool is_enterprise_managed = connector->IsEnterpriseManaged(); |
| 274 | 309 |
| 275 const user_manager::UserList users_to_send = | 310 const user_manager::UserList users_to_send = |
| 276 PrepareUserListForSending(users, owner, is_signin_to_add); | 311 PrepareUserListForSending(users, owner, is_signin_to_add); |
| 277 | 312 |
| 278 user_auth_type_map_.clear(); | 313 user_auth_type_map_.clear(); |
| 279 | 314 |
| 315 const std::vector<std::string> kEmptyRecommendedLocales; |
| 280 for (user_manager::UserList::const_iterator it = users_to_send.begin(); | 316 for (user_manager::UserList::const_iterator it = users_to_send.begin(); |
| 281 it != users_to_send.end(); | 317 it != users_to_send.end(); |
| 282 ++it) { | 318 ++it) { |
| 283 const std::string& user_id = (*it)->email(); | 319 const std::string& user_id = (*it)->email(); |
| 284 bool is_owner = (user_id == owner); | 320 bool is_owner = (user_id == owner); |
| 285 const bool is_public_account = | 321 const bool is_public_account = |
| 286 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); | 322 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); |
| 287 const ScreenlockBridge::LockHandler::AuthType initial_auth_type = | 323 const ScreenlockBridge::LockHandler::AuthType initial_auth_type = |
| 288 is_public_account | 324 is_public_account |
| 289 ? ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK | 325 ? ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK |
| 290 : (ShouldForceOnlineSignIn(*it) | 326 : (ShouldForceOnlineSignIn(*it) |
| 291 ? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN | 327 ? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN |
| 292 : ScreenlockBridge::LockHandler::OFFLINE_PASSWORD); | 328 : ScreenlockBridge::LockHandler::OFFLINE_PASSWORD); |
| 293 user_auth_type_map_[user_id] = initial_auth_type; | 329 user_auth_type_map_[user_id] = initial_auth_type; |
| 294 | 330 |
| 295 base::DictionaryValue* user_dict = new base::DictionaryValue(); | 331 base::DictionaryValue* user_dict = new base::DictionaryValue(); |
| 296 FillUserDictionary( | 332 const std::vector<std::string>* public_session_recommended_locales = |
| 297 *it, is_owner, is_signin_to_add, initial_auth_type, user_dict); | 333 public_session_recommended_locales_.find(user_id) == |
| 334 public_session_recommended_locales_.end() ? |
| 335 &kEmptyRecommendedLocales : |
| 336 &public_session_recommended_locales_[user_id]; |
| 337 FillUserDictionary(*it, |
| 338 is_owner, |
| 339 is_signin_to_add, |
| 340 initial_auth_type, |
| 341 public_session_recommended_locales, |
| 342 user_dict); |
| 298 bool signed_in = (*it)->is_logged_in(); | 343 bool signed_in = (*it)->is_logged_in(); |
| 299 // Single user check here is necessary because owner info might not be | 344 // Single user check here is necessary because owner info might not be |
| 300 // available when running into login screen on first boot. | 345 // available when running into login screen on first boot. |
| 301 // See http://crosbug.com/12723 | 346 // See http://crosbug.com/12723 |
| 302 bool can_remove_user = | 347 bool can_remove_user = |
| 303 ((!single_user || is_enterprise_managed) && !user_id.empty() && | 348 ((!single_user || is_enterprise_managed) && !user_id.empty() && |
| 304 !is_owner && !is_public_account && !signed_in && !is_signin_to_add); | 349 !is_owner && !is_public_account && !signed_in && !is_signin_to_add); |
| 305 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); | 350 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); |
| 306 users_list.Append(user_dict); | 351 users_list.Append(user_dict); |
| 307 } | 352 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 320 } | 365 } |
| 321 | 366 |
| 322 ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( | 367 ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( |
| 323 const std::string& username) const { | 368 const std::string& username) const { |
| 324 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) | 369 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) |
| 325 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | 370 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; |
| 326 return user_auth_type_map_.find(username)->second; | 371 return user_auth_type_map_.find(username)->second; |
| 327 } | 372 } |
| 328 | 373 |
| 329 } // namespace chromeos | 374 } // namespace chromeos |
| OLD | NEW |