| OLD | NEW |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 base::Unretained(this))); | 65 base::Unretained(this))); |
| 66 web_ui()->RegisterMessageCallback( | 66 web_ui()->RegisterMessageCallback( |
| 67 "removeProfileShortcut", | 67 "removeProfileShortcut", |
| 68 base::Bind(&ManageProfileHandler::HandleRemoveProfileShortcut, | 68 base::Bind(&ManageProfileHandler::HandleRemoveProfileShortcut, |
| 69 base::Unretained(this))); | 69 base::Unretained(this))); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ManageProfileHandler::OnProfileAvatarChanged( | 72 void ManageProfileHandler::OnProfileAvatarChanged( |
| 73 const base::FilePath& profile_path) { | 73 const base::FilePath& profile_path) { |
| 74 // This is necessary to send the potentially updated GAIA photo. | 74 // This is necessary to send the potentially updated GAIA photo. |
| 75 SendAvailableIcons(); | 75 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", |
| 76 base::StringValue("available-icons-changed"), |
| 77 *GetAvailableIcons()); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void ManageProfileHandler::HandleGetAvailableIcons( | 80 void ManageProfileHandler::HandleGetAvailableIcons( |
| 79 const base::ListValue* args) { | 81 const base::ListValue* args) { |
| 80 // This is also used as a signal that the page has loaded and is ready to | 82 // This is also used as a signal that the page has loaded and is ready to |
| 81 // observe profile avatar changes. | 83 // observe profile avatar changes. |
| 82 if (!observer_.IsObservingSources()) { | 84 if (!observer_.IsObservingSources()) { |
| 83 observer_.Add( | 85 observer_.Add( |
| 84 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); | 86 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); |
| 85 } | 87 } |
| 86 | 88 |
| 87 profiles::UpdateGaiaProfileInfoIfNeeded(profile_); | 89 profiles::UpdateGaiaProfileInfoIfNeeded(profile_); |
| 88 | 90 |
| 89 SendAvailableIcons(); | 91 CHECK_EQ(1U, args->GetSize()); |
| 92 const base::Value* callback_id; |
| 93 CHECK(args->Get(0, &callback_id)); |
| 94 ResolveJavascriptCallback(*callback_id, *GetAvailableIcons()); |
| 90 } | 95 } |
| 91 | 96 |
| 92 void ManageProfileHandler::SendAvailableIcons() { | 97 scoped_ptr<base::ListValue> ManageProfileHandler::GetAvailableIcons() { |
| 93 base::ListValue image_url_list; | 98 scoped_ptr<base::ListValue> image_url_list(new base::ListValue()); |
| 94 | 99 |
| 95 // First add the GAIA picture if it is available. | 100 // First add the GAIA picture if it is available. |
| 96 ProfileAttributesEntry* entry; | 101 ProfileAttributesEntry* entry; |
| 97 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). | 102 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 98 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { | 103 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { |
| 99 const gfx::Image* icon = entry->GetGAIAPicture(); | 104 const gfx::Image* icon = entry->GetGAIAPicture(); |
| 100 if (icon) { | 105 if (icon) { |
| 101 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); | 106 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); |
| 102 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); | 107 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); |
| 103 image_url_list.AppendString(gaia_picture_url_); | 108 image_url_list->AppendString(gaia_picture_url_); |
| 104 } | 109 } |
| 105 } | 110 } |
| 106 | 111 |
| 107 // Next add the default avatar icons and names. | 112 // Next add the default avatar icons and names. |
| 108 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { | 113 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { |
| 109 std::string url = profiles::GetDefaultAvatarIconUrl(i); | 114 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
| 110 image_url_list.AppendString(url); | 115 image_url_list->AppendString(url); |
| 111 } | 116 } |
| 112 | 117 |
| 113 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 118 return image_url_list; |
| 114 base::StringValue("available-icons-changed"), | |
| 115 image_url_list); | |
| 116 } | 119 } |
| 117 | 120 |
| 118 void ManageProfileHandler::HandleSetProfileIconAndName( | 121 void ManageProfileHandler::HandleSetProfileIconAndName( |
| 119 const base::ListValue* args) { | 122 const base::ListValue* args) { |
| 120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 121 DCHECK(args); | 124 DCHECK(args); |
| 122 DCHECK_EQ(2u, args->GetSize()); | 125 DCHECK_EQ(2u, args->GetSize()); |
| 123 | 126 |
| 124 std::string icon_url; | 127 std::string icon_url; |
| 125 CHECK(args->GetString(0, &icon_url)); | 128 CHECK(args->GetString(0, &icon_url)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 g_browser_process->profile_manager()->profile_shortcut_manager(); | 218 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 216 DCHECK(shortcut_manager); | 219 DCHECK(shortcut_manager); |
| 217 | 220 |
| 218 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); | 221 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); |
| 219 | 222 |
| 220 // Update the UI buttons. | 223 // Update the UI buttons. |
| 221 OnHasProfileShortcuts(false); | 224 OnHasProfileShortcuts(false); |
| 222 } | 225 } |
| 223 | 226 |
| 224 } // namespace settings | 227 } // namespace settings |
| OLD | NEW |