Index: chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc |
diff --git a/chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc b/chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc |
index 1a81b41d14ffce525b2a9a2a2ff988c102b16417..15187a46410a49760a25c6ac5263650ca4852a8e 100644 |
--- a/chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc |
+++ b/chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc |
@@ -6,15 +6,24 @@ |
#include "base/bind.h" |
#include "base/location.h" |
+#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.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/users/user_manager.h" |
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
+#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
+#include "components/policy/core/common/cloud/cloud_policy_core.h" |
+#include "components/policy/core/common/cloud/cloud_policy_store.h" |
+#include "components/policy/core/common/policy_map.h" |
+#include "components/policy/core/common/policy_types.h" |
#include "components/user_manager/user.h" |
#include "components/user_manager/user_type.h" |
+#include "policy/policy_constants.h" |
namespace chromeos { |
@@ -54,6 +63,7 @@ void ChromeUserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { |
return; |
CheckForPublicSessionDisplayNameChange(broker); |
+ CheckForPublicSessionLocalePolicyChange(broker); |
} |
void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { |
@@ -91,6 +101,55 @@ void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
user_id)); |
} |
+void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( |
+ policy::DeviceLocalAccountPolicyBroker* broker) { |
+ const std::string& user_id = broker->user_id(); |
+ const policy::PolicyMap::Entry* entry = |
+ broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); |
+ |
+ // Parse the list of recommended locales set by policy. |
+ std::vector<std::string> new_recommended_locales; |
+ base::ListValue const* list = NULL; |
+ if (entry && |
+ entry->level == policy::POLICY_LEVEL_RECOMMENDED && |
+ entry->value && |
+ entry->value->GetAsList(&list)) { |
+ for (base::ListValue::const_iterator it = list->begin(); it != list->end(); |
+ ++it) { |
+ std::string locale; |
+ if (!(*it)->GetAsString(&locale)) { |
+ NOTREACHED(); |
+ new_recommended_locales.clear(); |
+ break; |
+ } |
+ new_recommended_locales.push_back(locale); |
+ } |
+ } |
+ |
+ if (new_recommended_locales.empty()) { |
+ // There are no recommended locales. |
+ PublicSessionRecommendedLocaleMap::iterator it = |
+ public_session_recommended_locales_.find(user_id); |
+ if (it != public_session_recommended_locales_.end()) { |
+ // If there previously were recommended locales, remove them from |
+ // |public_session_recommended_locales_| and notify the UI. |
+ public_session_recommended_locales_.erase(it); |
+ SetPublicSessionLocales(user_id, &new_recommended_locales); |
+ } |
+ return; |
+ } |
+ |
+ // There are recommended locales. |
+ std::vector<std::string>& recommended_locales = |
+ public_session_recommended_locales_[user_id]; |
+ if (new_recommended_locales != recommended_locales) { |
+ // If the list of recommended locales has changed, update |
+ // |public_session_recommended_locales_| and notify the UI. |
+ recommended_locales = new_recommended_locales; |
+ SetPublicSessionLocales(user_id, &new_recommended_locales); |
+ } |
+} |
+ |
void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
const std::string& user_id) { |
const user_manager::User* user = UserManager::Get()->FindUser(user_id); |
@@ -102,4 +161,33 @@ void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
base::UTF16ToUTF8(user->GetDisplayName())); |
} |
+void ChromeUserSelectionScreen::SetPublicSessionLocales( |
+ const std::string& user_id, |
+ const std::vector<std::string>* recommended_locales) { |
+ if (!handler_initialized_) |
+ return; |
+ |
+ // Construct the list of available locales. This list consists of the |
+ // recommended locales, followed by all others. |
+ scoped_ptr<base::ListValue> locales = |
+ GetUILanguageList(recommended_locales, std::string()); |
+ |
+ // Set the initially selected locale. If the list of recommended locales is |
+ // not empty, select its first entry. Otherwise, select the current UI locale. |
+ const std::string& default_locale = recommended_locales->empty() ? |
+ g_browser_process->GetApplicationLocale() : recommended_locales->front(); |
+ |
+ // Set a flag to indicate whether the list of recommended locales contains at |
+ // least two entries. This is used to decide whether the public session pod |
+ // expands to its basic form (for zero or one recommended locales) or the |
+ // advanced form (two or more recommended locales). |
+ const bool two_or_more_recommended_locales = recommended_locales->size() >= 2; |
+ |
+ // Notify the UI. |
+ handler_->SetPublicSessionLocales(user_id, |
+ locales.Pass(), |
+ default_locale, |
+ two_or_more_recommended_locales); |
+} |
+ |
} // namespace chromeos |