| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (new_recommended_locales.empty()) { | 129 if (new_recommended_locales.empty()) { |
| 130 // There are no recommended locales. | 130 // There are no recommended locales. |
| 131 PublicSessionRecommendedLocaleMap::iterator it = | 131 PublicSessionRecommendedLocaleMap::iterator it = |
| 132 public_session_recommended_locales_.find(user_id); | 132 public_session_recommended_locales_.find(user_id); |
| 133 if (it != public_session_recommended_locales_.end()) { | 133 if (it != public_session_recommended_locales_.end()) { |
| 134 // If there previously were recommended locales, remove them from | 134 // If there previously were recommended locales, remove them from |
| 135 // |public_session_recommended_locales_| and notify the UI. | 135 // |public_session_recommended_locales_| and notify the UI. |
| 136 public_session_recommended_locales_.erase(it); | 136 public_session_recommended_locales_.erase(it); |
| 137 SetPublicSessionLocales(user_id, &new_recommended_locales); | 137 SetPublicSessionLocales(user_id, new_recommended_locales); |
| 138 } | 138 } |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 | 141 |
| 142 // There are recommended locales. | 142 // There are recommended locales. |
| 143 std::vector<std::string>& recommended_locales = | 143 std::vector<std::string>& recommended_locales = |
| 144 public_session_recommended_locales_[user_id]; | 144 public_session_recommended_locales_[user_id]; |
| 145 if (new_recommended_locales != recommended_locales) { | 145 if (new_recommended_locales != recommended_locales) { |
| 146 // If the list of recommended locales has changed, update | 146 // If the list of recommended locales has changed, update |
| 147 // |public_session_recommended_locales_| and notify the UI. | 147 // |public_session_recommended_locales_| and notify the UI. |
| 148 recommended_locales = new_recommended_locales; | 148 recommended_locales = new_recommended_locales; |
| 149 SetPublicSessionLocales(user_id, &new_recommended_locales); | 149 SetPublicSessionLocales(user_id, new_recommended_locales); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( | 153 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
| 154 const std::string& user_id) { | 154 const std::string& user_id) { |
| 155 const user_manager::User* user = | 155 const user_manager::User* user = |
| 156 user_manager::UserManager::Get()->FindUser(user_id); | 156 user_manager::UserManager::Get()->FindUser(user_id); |
| 157 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 157 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
| 158 return; | 158 return; |
| 159 | 159 |
| 160 handler_->SetPublicSessionDisplayName( | 160 handler_->SetPublicSessionDisplayName( |
| 161 user_id, | 161 user_id, |
| 162 base::UTF16ToUTF8(user->GetDisplayName())); | 162 base::UTF16ToUTF8(user->GetDisplayName())); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ChromeUserSelectionScreen::SetPublicSessionLocales( | 165 void ChromeUserSelectionScreen::SetPublicSessionLocales( |
| 166 const std::string& user_id, | 166 const std::string& user_id, |
| 167 const std::vector<std::string>* recommended_locales) { | 167 const std::vector<std::string>& recommended_locales) { |
| 168 if (!handler_initialized_) | 168 if (!handler_initialized_) |
| 169 return; | 169 return; |
| 170 | 170 |
| 171 // Construct the list of available locales. This list consists of the | 171 // Construct the list of available locales. This list consists of the |
| 172 // recommended locales, followed by all others. | 172 // recommended locales, followed by all others. |
| 173 scoped_ptr<base::ListValue> locales = | 173 scoped_ptr<base::ListValue> available_locales = |
| 174 GetUILanguageList(recommended_locales, std::string()); | 174 GetUILanguageList(&recommended_locales, std::string()); |
| 175 | 175 |
| 176 // Set the initially selected locale. If the list of recommended locales is | 176 // Set the initially selected locale to the first recommended locale that is |
| 177 // not empty, select its first entry. Otherwise, select the current UI locale. | 177 // actually available or the current UI locale if none of them are available. |
| 178 const std::string& default_locale = recommended_locales->empty() ? | 178 const std::string default_locale = FindMostRelevantLocale( |
| 179 g_browser_process->GetApplicationLocale() : recommended_locales->front(); | 179 recommended_locales, |
| 180 *available_locales.get(), |
| 181 g_browser_process->GetApplicationLocale()); |
| 180 | 182 |
| 181 // Set a flag to indicate whether the list of recommended locales contains at | 183 // Set a flag to indicate whether the list of recommended locales contains at |
| 182 // least two entries. This is used to decide whether the public session pod | 184 // least two entries. This is used to decide whether the public session pod |
| 183 // expands to its basic form (for zero or one recommended locales) or the | 185 // expands to its basic form (for zero or one recommended locales) or the |
| 184 // advanced form (two or more recommended locales). | 186 // advanced form (two or more recommended locales). |
| 185 const bool two_or_more_recommended_locales = recommended_locales->size() >= 2; | 187 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; |
| 186 | 188 |
| 187 // Notify the UI. | 189 // Notify the UI. |
| 188 handler_->SetPublicSessionLocales(user_id, | 190 handler_->SetPublicSessionLocales(user_id, |
| 189 locales.Pass(), | 191 available_locales.Pass(), |
| 190 default_locale, | 192 default_locale, |
| 191 two_or_more_recommended_locales); | 193 two_or_more_recommended_locales); |
| 192 } | 194 } |
| 193 | 195 |
| 194 } // namespace chromeos | 196 } // namespace chromeos |
| OLD | NEW |