Chromium Code Reviews| 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 ea93029b7155100b74a50381f5bb506d75f70eba..4db291164c776b27225973f9992bfb03172451af 100644 |
| --- a/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| +++ b/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| @@ -24,7 +24,12 @@ |
| #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| #include "chrome/common/pref_names.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_type.h" |
| +#include "policy/policy_constants.h" |
| #include "ui/wm/core/user_activity_detector.h" |
| namespace chromeos { |
| @@ -45,6 +50,9 @@ const char kKeyInitialAuthType[] = "initialAuthType"; |
| const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; |
| const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; |
| const char kKeyInitialLocales[] = "initialLocales"; |
| +const char kKeyInitialLocale[] = "initialLocale"; |
| +const char kKeyInitialMultipleRecommendedLocales[] = |
| + "initialMultipleRecommendedLocales"; |
| const char kKeyInitialKeyboardLayout[] = "initialKeyboardLayout"; |
| // Max number of users to show. |
| @@ -78,6 +86,7 @@ void UserSelectionScreen::FillUserDictionary( |
| bool is_owner, |
| bool is_signin_to_add, |
| ScreenlockBridge::LockHandler::AuthType auth_type, |
| + const std::vector<std::string>* public_session_recommended_locales, |
| base::DictionaryValue* user_dict) { |
| const std::string& user_id = user->email(); |
| const bool is_public_account = |
| @@ -117,13 +126,32 @@ void UserSelectionScreen::FillUserDictionary( |
| policy_connector->GetEnterpriseDomain()); |
| } |
| - // TODO(bartfab): Initialize |most_relevant_languages| and |locale| based on |
| - // policy. |
| - const std::string locale = g_browser_process->GetApplicationLocale(); |
| - std::vector<std::string> most_relevant_languages; |
| + std::vector<std::string> kEmptyRecommendedLocales; |
| + const std::vector<std::string>* recommended_locales = |
| + public_session_recommended_locales ? |
| + public_session_recommended_locales : &kEmptyRecommendedLocales; |
| + // Set |kKeyInitialLocales| to the list of available locales. This list |
|
Nikita (slow)
2014/07/30 11:22:59
nit: insert empty line before comment here and bel
bartfab (slow)
2014/08/05 17:16:23
Done.
|
| + // consists of the recommended locales, followed by all others. |
| user_dict->Set( |
| kKeyInitialLocales, |
| - GetUILanguageList(&most_relevant_languages, locale).release()); |
| + GetUILanguageList(recommended_locales, std::string()).release()); |
| + // Set |kKeyInitialLocale| to the initially selected locale. If the list of |
| + // recommended locales is not empty, select its first entry. Otherwise, |
| + // select the current UI locale. |
| + user_dict->SetString(kKeyInitialLocale, |
| + recommended_locales->empty() ? |
| + g_browser_process->GetApplicationLocale() : |
| + recommended_locales->front()); |
| + // Set |kKeyInitialMultipleRecommendedLocales| 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). |
| + user_dict->SetBoolean(kKeyInitialMultipleRecommendedLocales, |
| + recommended_locales->size() >= 2); |
| + // Set |kKeyInitialKeyboardLayout| to the current keyboard layout. This |
| + // value will be used temporarily only because the UI immediately requests a |
| + // list of keyboard layouts suitable for the currently selected locale. |
| user_dict->Set(kKeyInitialKeyboardLayout, |
| GetCurrentKeyboardLayout().release()); |
| } |
| @@ -236,6 +264,7 @@ void UserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { |
| return; |
| CheckForPublicSessionDisplayNameChange(broker); |
| + CheckForPublicSessionLocalePolicyChange(broker); |
| } |
| void UserSelectionScreen::OnDeviceLocalAccountsChanged() { |
| @@ -300,6 +329,7 @@ void UserSelectionScreen::SendUserList() { |
| user_auth_type_map_.clear(); |
| + const std::vector<std::string> kEmptyRecommendedLocales; |
| for (user_manager::UserList::const_iterator it = users_to_send.begin(); |
| it != users_to_send.end(); |
| ++it) { |
| @@ -316,8 +346,15 @@ void UserSelectionScreen::SendUserList() { |
| user_auth_type_map_[user_id] = initial_auth_type; |
| base::DictionaryValue* user_dict = new base::DictionaryValue(); |
| - FillUserDictionary( |
| - *it, is_owner, is_signin_to_add, initial_auth_type, user_dict); |
| + FillUserDictionary(*it, |
| + is_owner, |
| + is_signin_to_add, |
| + initial_auth_type, |
| + public_session_recommended_locales_.find(user_id) == |
|
Nikita (slow)
2014/07/30 11:22:59
nit: please extract public_session_recommended_loc
bartfab (slow)
2014/08/05 17:16:23
Done.
|
| + public_session_recommended_locales_.end() ? |
| + &kEmptyRecommendedLocales : |
| + &public_session_recommended_locales_[user_id], |
| + user_dict); |
| bool signed_in = (*it)->is_logged_in(); |
| // Single user check here is necessary because owner info might not be |
| // available when running into login screen on first boot. |
| @@ -354,6 +391,8 @@ void UserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
| policy::DeviceLocalAccountPolicyBroker* broker) { |
| const std::string& user_id = broker->user_id(); |
| const std::string& display_name = broker->GetDisplayName(); |
| + |
| + // If the display name has not changed, do nothing. |
| if (display_name == public_session_display_names_[user_id]) |
| return; |
| @@ -391,4 +430,81 @@ void UserSelectionScreen::SetPublicSessionDisplayName( |
| base::UTF16ToUTF8(user->GetDisplayName())); |
| } |
| +void UserSelectionScreen::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)) { |
| + new_recommended_locales.clear(); |
|
Nikita (slow)
2014/07/30 11:22:59
NOTREACHED()?
bartfab (slow)
2014/08/05 17:16:23
Done.
|
| + 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 UserSelectionScreen::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 |