| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 base::string16 new_profile_name; | 167 base::string16 new_profile_name; |
| 168 CHECK(args->GetString(1, &new_profile_name)); | 168 CHECK(args->GetString(1, &new_profile_name)); |
| 169 | 169 |
| 170 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); | 170 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); |
| 171 CHECK(!new_profile_name.empty()); | 171 CHECK(!new_profile_name.empty()); |
| 172 profiles::UpdateProfileName(profile_, new_profile_name); | 172 profiles::UpdateProfileName(profile_, new_profile_name); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void ManageProfileHandler::HandleRequestHasProfileShortcuts( | 175 void ManageProfileHandler::HandleRequestHasProfileShortcuts( |
| 176 const base::ListValue* args) { | 176 const base::ListValue* args) { |
| 177 AllowJavascript(); |
| 177 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 178 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 179 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 179 | 180 |
| 181 CHECK_EQ(1U, args->GetSize()); |
| 182 const base::Value* callback_id; |
| 183 CHECK(args->Get(0, &callback_id)); |
| 184 |
| 180 ProfileAttributesStorage& storage = | 185 ProfileAttributesStorage& storage = |
| 181 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 186 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 182 ProfileAttributesEntry* entry; | 187 ProfileAttributesEntry* entry; |
| 183 if (!storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) | 188 if (!storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) |
| 184 return; | 189 return; |
| 185 | 190 |
| 186 // Don't show the add/remove desktop shortcut button in the single user case. | 191 // Don't show the add/remove desktop shortcut button in the single user case. |
| 187 if (storage.GetNumberOfProfiles() <= 1u) | 192 if (storage.GetNumberOfProfiles() <= 1u) |
| 188 return; | 193 return; |
| 189 | 194 |
| 190 ProfileShortcutManager* shortcut_manager = | 195 ProfileShortcutManager* shortcut_manager = |
| 191 g_browser_process->profile_manager()->profile_shortcut_manager(); | 196 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 197 DCHECK(shortcut_manager); |
| 192 shortcut_manager->HasProfileShortcuts( | 198 shortcut_manager->HasProfileShortcuts( |
| 193 profile_->GetPath(), | 199 profile_->GetPath(), |
| 194 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, | 200 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, |
| 195 weak_factory_.GetWeakPtr())); | 201 weak_factory_.GetWeakPtr(), callback_id)); |
| 196 } | 202 } |
| 197 | 203 |
| 198 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 204 void ManageProfileHandler::OnHasProfileShortcuts( |
| 205 const base::Value* callback_id, bool has_shortcuts) { |
| 199 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 206 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 200 | 207 ResolveJavascriptCallback(*callback_id, |
| 201 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 208 base::FundamentalValue(has_shortcuts)); |
| 202 CallJavascriptFunction("settings.SyncPrivateApi.receiveHasProfileShortcuts", | |
| 203 has_shortcuts_value); | |
| 204 } | 209 } |
| 205 | 210 |
| 206 void ManageProfileHandler::HandleAddProfileShortcut( | 211 void ManageProfileHandler::HandleAddProfileShortcut( |
| 207 const base::ListValue* args) { | 212 const base::ListValue* args) { |
| 208 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 213 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 209 ProfileShortcutManager* shortcut_manager = | 214 ProfileShortcutManager* shortcut_manager = |
| 210 g_browser_process->profile_manager()->profile_shortcut_manager(); | 215 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 211 DCHECK(shortcut_manager); | 216 DCHECK(shortcut_manager); |
| 212 | 217 |
| 213 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); | 218 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); |
| 214 | |
| 215 // Update the UI buttons. | |
| 216 OnHasProfileShortcuts(true); | |
| 217 } | 219 } |
| 218 | 220 |
| 219 void ManageProfileHandler::HandleRemoveProfileShortcut( | 221 void ManageProfileHandler::HandleRemoveProfileShortcut( |
| 220 const base::ListValue* args) { | 222 const base::ListValue* args) { |
| 221 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 223 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 222 ProfileShortcutManager* shortcut_manager = | 224 ProfileShortcutManager* shortcut_manager = |
| 223 g_browser_process->profile_manager()->profile_shortcut_manager(); | 225 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 224 DCHECK(shortcut_manager); | 226 DCHECK(shortcut_manager); |
| 225 | 227 |
| 226 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); | 228 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); |
| 227 | |
| 228 // Update the UI buttons. | |
| 229 OnHasProfileShortcuts(false); | |
| 230 } | 229 } |
| 231 | 230 |
| 232 } // namespace settings | 231 } // namespace settings |
| OLD | NEW |