| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 web_ui()->RegisterMessageCallback( | 62 web_ui()->RegisterMessageCallback( |
| 63 "addProfileShortcut", | 63 "addProfileShortcut", |
| 64 base::Bind(&ManageProfileHandler::HandleAddProfileShortcut, | 64 base::Bind(&ManageProfileHandler::HandleAddProfileShortcut, |
| 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::OnJavascriptAllowed() { |
| 73 observer_.Add( |
| 74 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); |
| 75 } |
| 76 |
| 77 void ManageProfileHandler::OnJavascriptDisallowed() { |
| 78 observer_.RemoveAll(); |
| 79 } |
| 80 |
| 72 void ManageProfileHandler::OnProfileAvatarChanged( | 81 void ManageProfileHandler::OnProfileAvatarChanged( |
| 73 const base::FilePath& profile_path) { | 82 const base::FilePath& profile_path) { |
| 74 // This is necessary to send the potentially updated GAIA photo. | 83 // This is necessary to send the potentially updated GAIA photo. |
| 75 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 84 CallJavascriptFunction("cr.webUIListenerCallback", |
| 76 base::StringValue("available-icons-changed"), | 85 base::StringValue("available-icons-changed"), |
| 77 *GetAvailableIcons()); | 86 *GetAvailableIcons()); |
| 78 } | 87 } |
| 79 | 88 |
| 80 void ManageProfileHandler::HandleGetAvailableIcons( | 89 void ManageProfileHandler::HandleGetAvailableIcons( |
| 81 const base::ListValue* args) { | 90 const base::ListValue* args) { |
| 82 // This is also used as a signal that the page has loaded and is ready to | 91 AllowJavascript(); |
| 83 // observe profile avatar changes. | |
| 84 if (!observer_.IsObservingSources()) { | |
| 85 observer_.Add( | |
| 86 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); | |
| 87 } | |
| 88 | 92 |
| 89 profiles::UpdateGaiaProfileInfoIfNeeded(profile_); | 93 profiles::UpdateGaiaProfileInfoIfNeeded(profile_); |
| 90 | 94 |
| 91 CHECK_EQ(1U, args->GetSize()); | 95 CHECK_EQ(1U, args->GetSize()); |
| 92 const base::Value* callback_id; | 96 const base::Value* callback_id; |
| 93 CHECK(args->Get(0, &callback_id)); | 97 CHECK(args->Get(0, &callback_id)); |
| 94 ResolveJavascriptCallback(*callback_id, *GetAvailableIcons()); | 98 ResolveJavascriptCallback(*callback_id, *GetAvailableIcons()); |
| 95 } | 99 } |
| 96 | 100 |
| 97 std::unique_ptr<base::ListValue> ManageProfileHandler::GetAvailableIcons() { | 101 std::unique_ptr<base::ListValue> ManageProfileHandler::GetAvailableIcons() { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 shortcut_manager->HasProfileShortcuts( | 190 shortcut_manager->HasProfileShortcuts( |
| 187 profile_->GetPath(), | 191 profile_->GetPath(), |
| 188 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, | 192 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, |
| 189 weak_factory_.GetWeakPtr())); | 193 weak_factory_.GetWeakPtr())); |
| 190 } | 194 } |
| 191 | 195 |
| 192 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 196 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { |
| 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 197 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 194 | 198 |
| 195 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 199 const base::FundamentalValue has_shortcuts_value(has_shortcuts); |
| 196 web_ui()->CallJavascriptFunction( | 200 CallJavascriptFunction("settings.SyncPrivateApi.receiveHasProfileShortcuts", |
| 197 "settings.SyncPrivateApi.receiveHasProfileShortcuts", | 201 has_shortcuts_value); |
| 198 has_shortcuts_value); | |
| 199 } | 202 } |
| 200 | 203 |
| 201 void ManageProfileHandler::HandleAddProfileShortcut( | 204 void ManageProfileHandler::HandleAddProfileShortcut( |
| 202 const base::ListValue* args) { | 205 const base::ListValue* args) { |
| 203 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 206 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 204 ProfileShortcutManager* shortcut_manager = | 207 ProfileShortcutManager* shortcut_manager = |
| 205 g_browser_process->profile_manager()->profile_shortcut_manager(); | 208 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 206 DCHECK(shortcut_manager); | 209 DCHECK(shortcut_manager); |
| 207 | 210 |
| 208 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); | 211 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); |
| 209 | 212 |
| 210 // Update the UI buttons. | 213 // Update the UI buttons. |
| 211 OnHasProfileShortcuts(true); | 214 OnHasProfileShortcuts(true); |
| 212 } | 215 } |
| 213 | 216 |
| 214 void ManageProfileHandler::HandleRemoveProfileShortcut( | 217 void ManageProfileHandler::HandleRemoveProfileShortcut( |
| 215 const base::ListValue* args) { | 218 const base::ListValue* args) { |
| 216 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 219 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 217 ProfileShortcutManager* shortcut_manager = | 220 ProfileShortcutManager* shortcut_manager = |
| 218 g_browser_process->profile_manager()->profile_shortcut_manager(); | 221 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 219 DCHECK(shortcut_manager); | 222 DCHECK(shortcut_manager); |
| 220 | 223 |
| 221 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); | 224 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); |
| 222 | 225 |
| 223 // Update the UI buttons. | 226 // Update the UI buttons. |
| 224 OnHasProfileShortcuts(false); | 227 OnHasProfileShortcuts(false); |
| 225 } | 228 } |
| 226 | 229 |
| 227 } // namespace settings | 230 } // namespace settings |
| OLD | NEW |