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