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

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

Issue 2066093003: Refactor fetching profile avatar icons and labels repeated md-settings & md-user-manager (C++) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@avatar-selector-refactor
Patch Set: rebase Created 4 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings_manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 profiles::UpdateGaiaProfileInfoIfNeeded(profile_); 94 profiles::UpdateGaiaProfileInfoIfNeeded(profile_);
95 95
96 CHECK_EQ(1U, args->GetSize()); 96 CHECK_EQ(1U, args->GetSize());
97 const base::Value* callback_id; 97 const base::Value* callback_id;
98 CHECK(args->Get(0, &callback_id)); 98 CHECK(args->Get(0, &callback_id));
99 ResolveJavascriptCallback(*callback_id, *GetAvailableIcons()); 99 ResolveJavascriptCallback(*callback_id, *GetAvailableIcons());
100 } 100 }
101 101
102 std::unique_ptr<base::ListValue> ManageProfileHandler::GetAvailableIcons() { 102 std::unique_ptr<base::ListValue> ManageProfileHandler::GetAvailableIcons() {
103 std::unique_ptr<base::ListValue> image_url_list(new base::ListValue()); 103 std::unique_ptr<base::ListValue> image_url_list(
104 profiles::GetDefaultProfileAvatarIconsAndLabels());
104 105
105 // First add the GAIA picture if it is available. 106 // Add the GAIA picture to the beginning of the list if it is available.
106 ProfileAttributesEntry* entry; 107 ProfileAttributesEntry* entry;
107 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). 108 if (g_browser_process->profile_manager()->GetProfileAttributesStorage().
108 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { 109 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
109 const gfx::Image* icon = entry->GetGAIAPicture(); 110 const gfx::Image* icon = entry->GetGAIAPicture();
110 if (icon) { 111 if (icon) {
111 std::unique_ptr<base::DictionaryValue> gaia_picture_info( 112 base::DictionaryValue* gaia_picture_info = new base::DictionaryValue();
112 new base::DictionaryValue());
113 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); 113 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true);
114 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); 114 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap());
115 gaia_picture_info->SetString("url", gaia_picture_url_); 115 gaia_picture_info->SetString("url", gaia_picture_url_);
116 gaia_picture_info->SetString( 116 gaia_picture_info->SetString(
117 "label", 117 "label",
118 l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_PICTURE_PROFILE_PHOTO)); 118 l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_PICTURE_PROFILE_PHOTO));
119 image_url_list->Append(std::move(gaia_picture_info)); 119 image_url_list->Insert(0, gaia_picture_info);
120 } 120 }
121 } 121 }
122 122
123 // Next add the default avatar icons and names.
124 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
125 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() &&
126 i != placeholder_avatar_index;
127 i++) {
128 std::unique_ptr<base::DictionaryValue> avatar_info(
129 new base::DictionaryValue());
130 avatar_info->SetString("url", profiles::GetDefaultAvatarIconUrl(i));
131 avatar_info->SetString(
132 "label", l10n_util::GetStringUTF16(
133 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i)));
134 image_url_list->Append(std::move(avatar_info));
135 }
136
137 return image_url_list; 123 return image_url_list;
138 } 124 }
139 125
140 void ManageProfileHandler::HandleSetProfileIconAndName( 126 void ManageProfileHandler::HandleSetProfileIconAndName(
141 const base::ListValue* args) { 127 const base::ListValue* args) {
142 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
143 DCHECK(args); 129 DCHECK(args);
144 DCHECK_EQ(2u, args->GetSize()); 130 DCHECK_EQ(2u, args->GetSize());
145 131
146 std::string icon_url; 132 std::string icon_url;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 g_browser_process->profile_manager()->profile_shortcut_manager(); 222 g_browser_process->profile_manager()->profile_shortcut_manager();
237 DCHECK(shortcut_manager); 223 DCHECK(shortcut_manager);
238 224
239 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); 225 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath());
240 226
241 // Update the UI buttons. 227 // Update the UI buttons.
242 OnHasProfileShortcuts(false); 228 OnHasProfileShortcuts(false);
243 } 229 }
244 230
245 } // namespace settings 231 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_avatar_icon_util.cc ('k') | chrome/browser/ui/webui/signin/signin_create_profile_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698