Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc

Issue 483523005: Default to current UI locale when recommended locales are invalid (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/screens/user_selection_screen.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
dzhioev (left Google) 2014/08/20 17:00:24 Nothing will change if you drop this if-block comp
bartfab (slow) 2014/08/20 18:40:05 The update sent to the UI is the same as in the ne
dzhioev (left Google) 2014/08/20 19:26:35 Yes, but nothing will change, if you allow empty e
bartfab (slow) 2014/08/21 12:14:41 I simplified this block a lot now. It is a tad les
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) {
dzhioev (left Google) 2014/08/20 17:00:24 This method is never called with |recommended_loca
bartfab (slow) 2014/08/20 18:40:05 Done.
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/screens/user_selection_screen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698