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

Side by Side Diff: chrome/browser/ui/webui/settings/profile_info_handler.cc

Issue 2671813003: MD Settings: Cros Users: Use display name for non gaia accounts (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ui/webui/settings/profile_info_handler.h" 5 #include "chrome/browser/ui/webui/settings/profile_info_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_attributes_entry.h" 12 #include "chrome/browser/profiles/profile_attributes_entry.h"
12 #include "chrome/browser/ui/user_manager.h" 13 #include "chrome/browser/ui/user_manager.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "ui/base/webui/web_ui_util.h" 15 #include "ui/base/webui/web_ui_util.h"
15 16
16 #if defined(OS_CHROMEOS) 17 #if defined(OS_CHROMEOS)
17 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" 20 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
20 #include "components/signin/core/account_id/account_id.h" 21 #include "components/signin/core/account_id/account_id.h"
21 #include "components/user_manager/user_manager.h" 22 #include "components/user_manager/user_manager.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #else 24 #else
24 #include "base/strings/utf_string_conversions.h"
25 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 25 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
26 #include "chrome/browser/profiles/profile_statistics.h" 26 #include "chrome/browser/profiles/profile_statistics.h"
27 #include "chrome/browser/profiles/profile_statistics_factory.h" 27 #include "chrome/browser/profiles/profile_statistics_factory.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
29 #endif 29 #endif
30 30
31 namespace settings { 31 namespace settings {
32 32
33 // static 33 // static
34 const char ProfileInfoHandler::kProfileInfoChangedEventName[] = 34 const char ProfileInfoHandler::kProfileInfoChangedEventName[] =
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 base::FundamentalValue(IsProfileManagingSupervisedUsers())); 182 base::FundamentalValue(IsProfileManagingSupervisedUsers()));
183 } 183 }
184 184
185 std::unique_ptr<base::DictionaryValue> 185 std::unique_ptr<base::DictionaryValue>
186 ProfileInfoHandler::GetAccountNameAndIcon() const { 186 ProfileInfoHandler::GetAccountNameAndIcon() const {
187 std::string name; 187 std::string name;
188 std::string icon_url; 188 std::string icon_url;
189 189
190 #if defined(OS_CHROMEOS) 190 #if defined(OS_CHROMEOS)
191 name = profile_->GetProfileUserName(); 191 name = profile_->GetProfileUserName();
192 std::string user_email;
192 if (name.empty()) { 193 if (name.empty()) {
194 // User is not associated with a gaia account, use the display name.
193 const user_manager::User* user = 195 const user_manager::User* user =
194 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 196 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
195 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST)) 197 // Note: We don't show the User section in Guest mode.
196 name = user->GetAccountId().GetUserEmail(); 198 DCHECK(user && (user->GetType() != user_manager::USER_TYPE_GUEST));
199 name = base::UTF16ToUTF8(user->GetDisplayName());
200 user_email = user->GetAccountId().GetUserEmail();
201 } else {
202 name = gaia::SanitizeEmail(gaia::CanonicalizeEmail(name));
203 user_email = name;
197 } 204 }
198 if (!name.empty())
199 name = gaia::SanitizeEmail(gaia::CanonicalizeEmail(name));
200 205
201 // Get image as data URL instead of using chrome://userimage source to avoid 206 // Get image as data URL instead of using chrome://userimage source to avoid
202 // issues with caching. 207 // issues with caching.
203 const AccountId account_id(AccountId::FromUserEmail(name)); 208 const AccountId account_id(AccountId::FromUserEmail(user_email));
204 scoped_refptr<base::RefCountedMemory> image = 209 scoped_refptr<base::RefCountedMemory> image =
205 chromeos::options::UserImageSource::GetUserImage(account_id); 210 chromeos::options::UserImageSource::GetUserImage(account_id);
206 icon_url = webui::GetPngDataUrl(image->front(), image->size()); 211 icon_url = webui::GetPngDataUrl(image->front(), image->size());
207 #else // !defined(OS_CHROMEOS) 212 #else // !defined(OS_CHROMEOS)
208 ProfileAttributesEntry* entry; 213 ProfileAttributesEntry* entry;
209 if (g_browser_process->profile_manager() 214 if (g_browser_process->profile_manager()
210 ->GetProfileAttributesStorage() 215 ->GetProfileAttributesStorage()
211 .GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { 216 .GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
212 name = base::UTF16ToUTF8(entry->GetName()); 217 name = base::UTF16ToUTF8(entry->GetName());
213 218
(...skipping 11 matching lines...) Expand all
225 response->SetString("name", name); 230 response->SetString("name", name);
226 response->SetString("iconUrl", icon_url); 231 response->SetString("iconUrl", icon_url);
227 return base::WrapUnique(response); 232 return base::WrapUnique(response);
228 } 233 }
229 234
230 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { 235 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const {
231 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); 236 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty();
232 } 237 }
233 238
234 } // namespace settings 239 } // namespace settings
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698