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