Index: chrome/browser/chromeos/login/screens/user_selection_screen.cc |
diff --git a/chrome/browser/chromeos/login/screens/user_selection_screen.cc b/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
index f24e8709d702db7a1850696c183e4159ae1c710b..ea93029b7155100b74a50381f5bb506d75f70eba 100644 |
--- a/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
+++ b/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
@@ -7,11 +7,18 @@ |
#include <vector> |
#include "ash/shell.h" |
+#include "base/bind.h" |
+#include "base/location.h" |
#include "base/logging.h" |
+#include "base/message_loop/message_loop.h" |
#include "base/prefs/pref_service.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/browser_process_platform_part.h" |
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
+#include "chrome/browser/chromeos/login/users/user_manager.h" |
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
#include "chrome/browser/signin/screenlock_bridge.h" |
#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
@@ -48,10 +55,17 @@ const int kPasswordClearTimeoutSec = 60; |
} // namespace |
-UserSelectionScreen::UserSelectionScreen() : handler_(NULL) { |
+UserSelectionScreen::UserSelectionScreen() |
+ : handler_(NULL), |
+ handler_initialized_(false), |
+ weak_factory_(this) { |
+ device_local_account_policy_service_ = g_browser_process->platform_part()-> |
+ browser_policy_connector_chromeos()->GetDeviceLocalAccountPolicyService(); |
+ device_local_account_policy_service_->AddObserver(this); |
} |
UserSelectionScreen::~UserSelectionScreen() { |
+ device_local_account_policy_service_->RemoveObserver(this); |
wm::UserActivityDetector* activity_detector = |
ash::Shell::GetInstance()->user_activity_detector(); |
if (activity_detector->HasObserver(this)) |
@@ -162,6 +176,13 @@ void UserSelectionScreen::Init(const user_manager::UserList& users, |
ash::Shell::GetInstance()->user_activity_detector(); |
if (!activity_detector->HasObserver(this)) |
activity_detector->AddObserver(this); |
+ |
+ // Retrieve the current policy for |users_|. |
+ for (user_manager::UserList::const_iterator it = users_.begin(); |
+ it != users_.end(); ++it) { |
+ if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
+ OnPolicyUpdated((*it)->GetUserID()); |
+ } |
} |
void UserSelectionScreen::OnBeforeUserRemoved(const std::string& username) { |
@@ -208,6 +229,20 @@ void UserSelectionScreen::OnUserActivity(const ui::Event* event) { |
password_clear_timer_.Reset(); |
} |
+void UserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { |
+ policy::DeviceLocalAccountPolicyBroker* broker = |
+ device_local_account_policy_service_->GetBrokerForUser(user_id); |
+ if (!broker) |
+ return; |
+ |
+ CheckForPublicSessionDisplayNameChange(broker); |
+} |
+ |
+void UserSelectionScreen::OnDeviceLocalAccountsChanged() { |
+ // Nothing to do here. When the list of device-local accounts changes, the |
+ // entire UI is reloaded. |
+} |
+ |
// static |
const user_manager::UserList UserSelectionScreen::PrepareUserListForSending( |
const user_manager::UserList& users, |
@@ -295,6 +330,7 @@ void UserSelectionScreen::SendUserList() { |
} |
handler_->LoadUsers(users_list, show_guest_); |
+ handler_initialized_ = true; |
} |
void UserSelectionScreen::HandleGetUsers() { |
@@ -314,4 +350,45 @@ ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType( |
return user_auth_type_map_.find(username)->second; |
} |
+void UserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
+ policy::DeviceLocalAccountPolicyBroker* broker) { |
+ const std::string& user_id = broker->user_id(); |
+ const std::string& display_name = broker->GetDisplayName(); |
+ if (display_name == public_session_display_names_[user_id]) |
+ return; |
+ |
+ public_session_display_names_[user_id] = display_name; |
+ |
+ if (!handler_initialized_) |
+ return; |
+ |
+ if (!display_name.empty()) { |
+ // If a new display name was set by policy, notify the UI about it. |
+ handler_->SetPublicSessionDisplayName(user_id, display_name); |
+ return; |
+ } |
+ |
+ // When no display name is set by policy, the |User|, owned by |UserManager|, |
+ // decides what display name to use. However, the order in which |UserManager| |
+ // and |this| are informed of the display name change is undefined. Post a |
+ // task that will update the UI after the UserManager is guaranteed to have |
+ // been informed of the change. |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&UserSelectionScreen::SetPublicSessionDisplayName, |
+ weak_factory_.GetWeakPtr(), |
+ user_id)); |
+} |
+ |
+void UserSelectionScreen::SetPublicSessionDisplayName( |
+ const std::string& user_id) { |
+ const user_manager::User* user = UserManager::Get()->FindUser(user_id); |
+ if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
+ return; |
+ |
+ handler_->SetPublicSessionDisplayName( |
+ user_id, |
+ base::UTF16ToUTF8(user->GetDisplayName())); |
+} |
+ |
} // namespace chromeos |