| 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/chrome_user_selection_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 CheckForPublicSessionLocalePolicyChange(broker); | 70 CheckForPublicSessionLocalePolicyChange(broker); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { | 73 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { |
| 74 // Nothing to do here. When the list of device-local accounts changes, the | 74 // Nothing to do here. When the list of device-local accounts changes, the |
| 75 // entire UI is reloaded. | 75 // entire UI is reloaded. |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( | 78 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
| 79 policy::DeviceLocalAccountPolicyBroker* broker) { | 79 policy::DeviceLocalAccountPolicyBroker* broker) { |
| 80 const std::string& user_id = broker->user_id(); | 80 const AccountId& account_id(GetAccountIdOfKnownUser(broker->user_id())); |
| 81 const std::string& display_name = broker->GetDisplayName(); | 81 const std::string& display_name = broker->GetDisplayName(); |
| 82 if (display_name == public_session_display_names_[user_id]) | 82 if (display_name == public_session_display_names_[account_id]) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 public_session_display_names_[user_id] = display_name; | 85 public_session_display_names_[account_id] = display_name; |
| 86 | 86 |
| 87 if (!handler_initialized_) | 87 if (!handler_initialized_) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 if (!display_name.empty()) { | 90 if (!display_name.empty()) { |
| 91 // If a new display name was set by policy, notify the UI about it. | 91 // If a new display name was set by policy, notify the UI about it. |
| 92 view_->SetPublicSessionDisplayName(user_id, display_name); | 92 view_->SetPublicSessionDisplayName(account_id, display_name); |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // When no display name is set by policy, the |User|, owned by |UserManager|, | 96 // When no display name is set by policy, the |User|, owned by |UserManager|, |
| 97 // decides what display name to use. However, the order in which |UserManager| | 97 // decides what display name to use. However, the order in which |UserManager| |
| 98 // and |this| are informed of the display name change is undefined. Post a | 98 // and |this| are informed of the display name change is undefined. Post a |
| 99 // task that will update the UI after the UserManager is guaranteed to have | 99 // task that will update the UI after the UserManager is guaranteed to have |
| 100 // been informed of the change. | 100 // been informed of the change. |
| 101 base::MessageLoop::current()->PostTask( | 101 base::MessageLoop::current()->PostTask( |
| 102 FROM_HERE, | 102 FROM_HERE, |
| 103 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, | 103 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, |
| 104 weak_factory_.GetWeakPtr(), | 104 weak_factory_.GetWeakPtr(), account_id)); |
| 105 user_id)); | |
| 106 } | 105 } |
| 107 | 106 |
| 108 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( | 107 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( |
| 109 policy::DeviceLocalAccountPolicyBroker* broker) { | 108 policy::DeviceLocalAccountPolicyBroker* broker) { |
| 110 const std::string& user_id = broker->user_id(); | 109 const AccountId account_id(GetAccountIdOfKnownUser(broker->user_id())); |
| 111 const policy::PolicyMap::Entry* entry = | 110 const policy::PolicyMap::Entry* entry = |
| 112 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); | 111 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); |
| 113 | 112 |
| 114 // Parse the list of recommended locales set by policy. | 113 // Parse the list of recommended locales set by policy. |
| 115 std::vector<std::string> new_recommended_locales; | 114 std::vector<std::string> new_recommended_locales; |
| 116 base::ListValue const* list = NULL; | 115 base::ListValue const* list = NULL; |
| 117 if (entry && | 116 if (entry && |
| 118 entry->level == policy::POLICY_LEVEL_RECOMMENDED && | 117 entry->level == policy::POLICY_LEVEL_RECOMMENDED && |
| 119 entry->value && | 118 entry->value && |
| 120 entry->value->GetAsList(&list)) { | 119 entry->value->GetAsList(&list)) { |
| 121 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); | 120 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); |
| 122 ++it) { | 121 ++it) { |
| 123 std::string locale; | 122 std::string locale; |
| 124 if (!(*it)->GetAsString(&locale)) { | 123 if (!(*it)->GetAsString(&locale)) { |
| 125 NOTREACHED(); | 124 NOTREACHED(); |
| 126 new_recommended_locales.clear(); | 125 new_recommended_locales.clear(); |
| 127 break; | 126 break; |
| 128 } | 127 } |
| 129 new_recommended_locales.push_back(locale); | 128 new_recommended_locales.push_back(locale); |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 std::vector<std::string>& recommended_locales = | 132 std::vector<std::string>& recommended_locales = |
| 134 public_session_recommended_locales_[user_id]; | 133 public_session_recommended_locales_[account_id]; |
| 135 | 134 |
| 136 if (new_recommended_locales != recommended_locales) | 135 if (new_recommended_locales != recommended_locales) |
| 137 SetPublicSessionLocales(user_id, new_recommended_locales); | 136 SetPublicSessionLocales(account_id, new_recommended_locales); |
| 138 | 137 |
| 139 if (new_recommended_locales.empty()) | 138 if (new_recommended_locales.empty()) |
| 140 public_session_recommended_locales_.erase(user_id); | 139 public_session_recommended_locales_.erase(account_id); |
| 141 else | 140 else |
| 142 recommended_locales = new_recommended_locales; | 141 recommended_locales = new_recommended_locales; |
| 143 } | 142 } |
| 144 | 143 |
| 145 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( | 144 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
| 146 const std::string& user_id) { | 145 const AccountId& account_id) { |
| 147 const user_manager::User* user = user_manager::UserManager::Get()->FindUser( | 146 const user_manager::User* user = |
| 148 AccountId::FromUserEmail(user_id)); | 147 user_manager::UserManager::Get()->FindUser(account_id); |
| 149 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 148 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
| 150 return; | 149 return; |
| 151 | 150 |
| 152 view_->SetPublicSessionDisplayName(user_id, | 151 view_->SetPublicSessionDisplayName(account_id, |
| 153 base::UTF16ToUTF8(user->GetDisplayName())); | 152 base::UTF16ToUTF8(user->GetDisplayName())); |
| 154 } | 153 } |
| 155 | 154 |
| 156 void ChromeUserSelectionScreen::SetPublicSessionLocales( | 155 void ChromeUserSelectionScreen::SetPublicSessionLocales( |
| 157 const std::string& user_id, | 156 const AccountId& account_id, |
| 158 const std::vector<std::string>& recommended_locales) { | 157 const std::vector<std::string>& recommended_locales) { |
| 159 if (!handler_initialized_) | 158 if (!handler_initialized_) |
| 160 return; | 159 return; |
| 161 | 160 |
| 162 // Construct the list of available locales. This list consists of the | 161 // Construct the list of available locales. This list consists of the |
| 163 // recommended locales, followed by all others. | 162 // recommended locales, followed by all others. |
| 164 scoped_ptr<base::ListValue> available_locales = | 163 scoped_ptr<base::ListValue> available_locales = |
| 165 GetUILanguageList(&recommended_locales, std::string()); | 164 GetUILanguageList(&recommended_locales, std::string()); |
| 166 | 165 |
| 167 // Set the initially selected locale to the first recommended locale that is | 166 // Set the initially selected locale to the first recommended locale that is |
| 168 // actually available or the current UI locale if none of them are available. | 167 // actually available or the current UI locale if none of them are available. |
| 169 const std::string default_locale = FindMostRelevantLocale( | 168 const std::string default_locale = FindMostRelevantLocale( |
| 170 recommended_locales, | 169 recommended_locales, |
| 171 *available_locales.get(), | 170 *available_locales.get(), |
| 172 g_browser_process->GetApplicationLocale()); | 171 g_browser_process->GetApplicationLocale()); |
| 173 | 172 |
| 174 // Set a flag to indicate whether the list of recommended locales contains at | 173 // Set a flag to indicate whether the list of recommended locales contains at |
| 175 // least two entries. This is used to decide whether the public session pod | 174 // least two entries. This is used to decide whether the public session pod |
| 176 // expands to its basic form (for zero or one recommended locales) or the | 175 // expands to its basic form (for zero or one recommended locales) or the |
| 177 // advanced form (two or more recommended locales). | 176 // advanced form (two or more recommended locales). |
| 178 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; | 177 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; |
| 179 | 178 |
| 180 // Notify the UI. | 179 // Notify the UI. |
| 181 view_->SetPublicSessionLocales(user_id, available_locales.Pass(), | 180 view_->SetPublicSessionLocales(account_id, available_locales.Pass(), |
| 182 default_locale, | 181 default_locale, |
| 183 two_or_more_recommended_locales); | 182 two_or_more_recommended_locales); |
| 184 } | 183 } |
| 185 | 184 |
| 186 } // namespace chromeos | 185 } // namespace chromeos |
| OLD | NEW |