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/bind.h" |
| 11 #include "base/location.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/browser_process_platform_part.h" |
13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 19 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 20 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 21 #include "chrome/browser/chromeos/login/users/user_manager.h" |
15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
16 #include "chrome/browser/signin/screenlock_bridge.h" | 23 #include "chrome/browser/signin/screenlock_bridge.h" |
17 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" | 24 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
18 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 25 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
19 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
20 #include "components/user_manager/user_type.h" | 27 #include "components/user_manager/user_type.h" |
21 #include "ui/wm/core/user_activity_detector.h" | 28 #include "ui/wm/core/user_activity_detector.h" |
22 | 29 |
23 namespace chromeos { | 30 namespace chromeos { |
24 | 31 |
(...skipping 16 matching lines...) Expand all Loading... |
41 const char kKeyInitialKeyboardLayout[] = "initialKeyboardLayout"; | 48 const char kKeyInitialKeyboardLayout[] = "initialKeyboardLayout"; |
42 | 49 |
43 // Max number of users to show. | 50 // Max number of users to show. |
44 // Please keep synced with one in signin_userlist_unittest.cc. | 51 // Please keep synced with one in signin_userlist_unittest.cc. |
45 const size_t kMaxUsers = 18; | 52 const size_t kMaxUsers = 18; |
46 | 53 |
47 const int kPasswordClearTimeoutSec = 60; | 54 const int kPasswordClearTimeoutSec = 60; |
48 | 55 |
49 } // namespace | 56 } // namespace |
50 | 57 |
51 UserSelectionScreen::UserSelectionScreen() : handler_(NULL) { | 58 UserSelectionScreen::UserSelectionScreen() |
| 59 : handler_(NULL), |
| 60 handler_initialized_(false), |
| 61 weak_factory_(this) { |
| 62 device_local_account_policy_service_ = g_browser_process->platform_part()-> |
| 63 browser_policy_connector_chromeos()->GetDeviceLocalAccountPolicyService(); |
| 64 device_local_account_policy_service_->AddObserver(this); |
52 } | 65 } |
53 | 66 |
54 UserSelectionScreen::~UserSelectionScreen() { | 67 UserSelectionScreen::~UserSelectionScreen() { |
| 68 device_local_account_policy_service_->RemoveObserver(this); |
55 wm::UserActivityDetector* activity_detector = | 69 wm::UserActivityDetector* activity_detector = |
56 ash::Shell::GetInstance()->user_activity_detector(); | 70 ash::Shell::GetInstance()->user_activity_detector(); |
57 if (activity_detector->HasObserver(this)) | 71 if (activity_detector->HasObserver(this)) |
58 activity_detector->RemoveObserver(this); | 72 activity_detector->RemoveObserver(this); |
59 } | 73 } |
60 | 74 |
61 // static | 75 // static |
62 void UserSelectionScreen::FillUserDictionary( | 76 void UserSelectionScreen::FillUserDictionary( |
63 user_manager::User* user, | 77 user_manager::User* user, |
64 bool is_owner, | 78 bool is_owner, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 169 |
156 void UserSelectionScreen::Init(const user_manager::UserList& users, | 170 void UserSelectionScreen::Init(const user_manager::UserList& users, |
157 bool show_guest) { | 171 bool show_guest) { |
158 users_ = users; | 172 users_ = users; |
159 show_guest_ = show_guest; | 173 show_guest_ = show_guest; |
160 | 174 |
161 wm::UserActivityDetector* activity_detector = | 175 wm::UserActivityDetector* activity_detector = |
162 ash::Shell::GetInstance()->user_activity_detector(); | 176 ash::Shell::GetInstance()->user_activity_detector(); |
163 if (!activity_detector->HasObserver(this)) | 177 if (!activity_detector->HasObserver(this)) |
164 activity_detector->AddObserver(this); | 178 activity_detector->AddObserver(this); |
| 179 |
| 180 // Retrieve the current policy for |users_|. |
| 181 for (user_manager::UserList::const_iterator it = users_.begin(); |
| 182 it != users_.end(); ++it) { |
| 183 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
| 184 OnPolicyUpdated((*it)->GetUserID()); |
| 185 } |
165 } | 186 } |
166 | 187 |
167 void UserSelectionScreen::OnBeforeUserRemoved(const std::string& username) { | 188 void UserSelectionScreen::OnBeforeUserRemoved(const std::string& username) { |
168 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); | 189 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); |
169 ++it) { | 190 ++it) { |
170 if ((*it)->email() == username) { | 191 if ((*it)->email() == username) { |
171 users_.erase(it); | 192 users_.erase(it); |
172 break; | 193 break; |
173 } | 194 } |
174 } | 195 } |
(...skipping 26 matching lines...) Expand all Loading... |
201 if (!password_clear_timer_.IsRunning()) { | 222 if (!password_clear_timer_.IsRunning()) { |
202 password_clear_timer_.Start( | 223 password_clear_timer_.Start( |
203 FROM_HERE, | 224 FROM_HERE, |
204 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), | 225 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), |
205 this, | 226 this, |
206 &UserSelectionScreen::OnPasswordClearTimerExpired); | 227 &UserSelectionScreen::OnPasswordClearTimerExpired); |
207 } | 228 } |
208 password_clear_timer_.Reset(); | 229 password_clear_timer_.Reset(); |
209 } | 230 } |
210 | 231 |
| 232 void UserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { |
| 233 policy::DeviceLocalAccountPolicyBroker* broker = |
| 234 device_local_account_policy_service_->GetBrokerForUser(user_id); |
| 235 if (!broker) |
| 236 return; |
| 237 |
| 238 CheckForPublicSessionDisplayNameChange(broker); |
| 239 } |
| 240 |
| 241 void UserSelectionScreen::OnDeviceLocalAccountsChanged() { |
| 242 // Nothing to do here. When the list of device-local accounts changes, the |
| 243 // entire UI is reloaded. |
| 244 } |
| 245 |
211 // static | 246 // static |
212 const user_manager::UserList UserSelectionScreen::PrepareUserListForSending( | 247 const user_manager::UserList UserSelectionScreen::PrepareUserListForSending( |
213 const user_manager::UserList& users, | 248 const user_manager::UserList& users, |
214 std::string owner, | 249 std::string owner, |
215 bool is_signin_to_add) { | 250 bool is_signin_to_add) { |
216 user_manager::UserList users_to_send; | 251 user_manager::UserList users_to_send; |
217 bool has_owner = owner.size() > 0; | 252 bool has_owner = owner.size() > 0; |
218 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; | 253 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; |
219 size_t non_owner_count = 0; | 254 size_t non_owner_count = 0; |
220 | 255 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // available when running into login screen on first boot. | 323 // available when running into login screen on first boot. |
289 // See http://crosbug.com/12723 | 324 // See http://crosbug.com/12723 |
290 bool can_remove_user = | 325 bool can_remove_user = |
291 ((!single_user || is_enterprise_managed) && !user_id.empty() && | 326 ((!single_user || is_enterprise_managed) && !user_id.empty() && |
292 !is_owner && !is_public_account && !signed_in && !is_signin_to_add); | 327 !is_owner && !is_public_account && !signed_in && !is_signin_to_add); |
293 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); | 328 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); |
294 users_list.Append(user_dict); | 329 users_list.Append(user_dict); |
295 } | 330 } |
296 | 331 |
297 handler_->LoadUsers(users_list, show_guest_); | 332 handler_->LoadUsers(users_list, show_guest_); |
| 333 handler_initialized_ = true; |
298 } | 334 } |
299 | 335 |
300 void UserSelectionScreen::HandleGetUsers() { | 336 void UserSelectionScreen::HandleGetUsers() { |
301 SendUserList(); | 337 SendUserList(); |
302 } | 338 } |
303 | 339 |
304 void UserSelectionScreen::SetAuthType( | 340 void UserSelectionScreen::SetAuthType( |
305 const std::string& username, | 341 const std::string& username, |
306 ScreenlockBridge::LockHandler::AuthType auth_type) { | 342 ScreenlockBridge::LockHandler::AuthType auth_type) { |
307 user_auth_type_map_[username] = auth_type; | 343 user_auth_type_map_[username] = auth_type; |
308 } | 344 } |
309 | 345 |
310 ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( | 346 ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( |
311 const std::string& username) const { | 347 const std::string& username) const { |
312 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) | 348 if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) |
313 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | 349 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; |
314 return user_auth_type_map_.find(username)->second; | 350 return user_auth_type_map_.find(username)->second; |
315 } | 351 } |
316 | 352 |
| 353 void UserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
| 354 policy::DeviceLocalAccountPolicyBroker* broker) { |
| 355 const std::string& user_id = broker->user_id(); |
| 356 const std::string& display_name = broker->GetDisplayName(); |
| 357 if (display_name == public_session_display_names_[user_id]) |
| 358 return; |
| 359 |
| 360 public_session_display_names_[user_id] = display_name; |
| 361 |
| 362 if (!handler_initialized_) |
| 363 return; |
| 364 |
| 365 if (!display_name.empty()) { |
| 366 // If a new display name was set by policy, notify the UI about it. |
| 367 handler_->SetPublicSessionDisplayName(user_id, display_name); |
| 368 return; |
| 369 } |
| 370 |
| 371 // When no display name is set by policy, the |User|, owned by |UserManager|, |
| 372 // decides what display name to use. However, the order in which |UserManager| |
| 373 // and |this| are informed of the display name change is undefined. Post a |
| 374 // task that will update the UI after the UserManager is guaranteed to have |
| 375 // been informed of the change. |
| 376 base::MessageLoop::current()->PostTask( |
| 377 FROM_HERE, |
| 378 base::Bind(&UserSelectionScreen::SetPublicSessionDisplayName, |
| 379 weak_factory_.GetWeakPtr(), |
| 380 user_id)); |
| 381 } |
| 382 |
| 383 void UserSelectionScreen::SetPublicSessionDisplayName( |
| 384 const std::string& user_id) { |
| 385 const user_manager::User* user = UserManager::Get()->FindUser(user_id); |
| 386 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
| 387 return; |
| 388 |
| 389 handler_->SetPublicSessionDisplayName( |
| 390 user_id, |
| 391 base::UTF16ToUTF8(user->GetDisplayName())); |
| 392 } |
| 393 |
317 } // namespace chromeos | 394 } // namespace chromeos |
OLD | NEW |