| 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 25 matching lines...) Expand all Loading... |
| 36 #include "components/signin/core/common/profile_management_switches.h" | 36 #include "components/signin/core/common/profile_management_switches.h" |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
| 40 #include "google_apis/gaia/gaia_auth_util.h" | 40 #include "google_apis/gaia/gaia_auth_util.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/base/webui/web_ui_util.h" | 42 #include "ui/base/webui/web_ui_util.h" |
| 43 | 43 |
| 44 namespace settings { | 44 namespace settings { |
| 45 | 45 |
| 46 namespace { |
| 47 |
| 48 const char kProfileShortcutSettingHidden[] = "profileShortcutSettingHidden"; |
| 49 const char kProfileShortcutFound[] = "profileShortcutFound"; |
| 50 const char kProfileShortcutNotFound[] = "profileShortcutNotFound"; |
| 51 |
| 52 } // namespace |
| 53 |
| 46 ManageProfileHandler::ManageProfileHandler(Profile* profile) | 54 ManageProfileHandler::ManageProfileHandler(Profile* profile) |
| 47 : profile_(profile), observer_(this), weak_factory_(this) {} | 55 : profile_(profile), observer_(this), weak_factory_(this) {} |
| 48 | 56 |
| 49 ManageProfileHandler::~ManageProfileHandler() {} | 57 ManageProfileHandler::~ManageProfileHandler() {} |
| 50 | 58 |
| 51 void ManageProfileHandler::RegisterMessages() { | 59 void ManageProfileHandler::RegisterMessages() { |
| 52 web_ui()->RegisterMessageCallback( | 60 web_ui()->RegisterMessageCallback( |
| 53 "getAvailableIcons", | 61 "getAvailableIcons", |
| 54 base::Bind(&ManageProfileHandler::HandleGetAvailableIcons, | 62 base::Bind(&ManageProfileHandler::HandleGetAvailableIcons, |
| 55 base::Unretained(this))); | 63 base::Unretained(this))); |
| 56 web_ui()->RegisterMessageCallback( | 64 web_ui()->RegisterMessageCallback( |
| 57 "setProfileIconAndName", | 65 "setProfileIconAndName", |
| 58 base::Bind(&ManageProfileHandler::HandleSetProfileIconAndName, | 66 base::Bind(&ManageProfileHandler::HandleSetProfileIconAndName, |
| 59 base::Unretained(this))); | 67 base::Unretained(this))); |
| 60 web_ui()->RegisterMessageCallback( | 68 web_ui()->RegisterMessageCallback( |
| 61 "requestHasProfileShortcuts", | 69 "requestProfileShortcutStatus", |
| 62 base::Bind(&ManageProfileHandler::HandleRequestHasProfileShortcuts, | 70 base::Bind(&ManageProfileHandler::HandleRequestProfileShortcutStatus, |
| 63 base::Unretained(this))); | 71 base::Unretained(this))); |
| 64 web_ui()->RegisterMessageCallback( | 72 web_ui()->RegisterMessageCallback( |
| 65 "addProfileShortcut", | 73 "addProfileShortcut", |
| 66 base::Bind(&ManageProfileHandler::HandleAddProfileShortcut, | 74 base::Bind(&ManageProfileHandler::HandleAddProfileShortcut, |
| 67 base::Unretained(this))); | 75 base::Unretained(this))); |
| 68 web_ui()->RegisterMessageCallback( | 76 web_ui()->RegisterMessageCallback( |
| 69 "removeProfileShortcut", | 77 "removeProfileShortcut", |
| 70 base::Bind(&ManageProfileHandler::HandleRemoveProfileShortcut, | 78 base::Bind(&ManageProfileHandler::HandleRemoveProfileShortcut, |
| 71 base::Unretained(this))); | 79 base::Unretained(this))); |
| 72 } | 80 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return; | 173 return; |
| 166 | 174 |
| 167 base::string16 new_profile_name; | 175 base::string16 new_profile_name; |
| 168 CHECK(args->GetString(1, &new_profile_name)); | 176 CHECK(args->GetString(1, &new_profile_name)); |
| 169 | 177 |
| 170 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); | 178 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); |
| 171 CHECK(!new_profile_name.empty()); | 179 CHECK(!new_profile_name.empty()); |
| 172 profiles::UpdateProfileName(profile_, new_profile_name); | 180 profiles::UpdateProfileName(profile_, new_profile_name); |
| 173 } | 181 } |
| 174 | 182 |
| 175 void ManageProfileHandler::HandleRequestHasProfileShortcuts( | 183 void ManageProfileHandler::HandleRequestProfileShortcutStatus( |
| 176 const base::ListValue* args) { | 184 const base::ListValue* args) { |
| 177 AllowJavascript(); | 185 AllowJavascript(); |
| 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 186 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 179 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 187 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 180 | 188 |
| 181 CHECK_EQ(1U, args->GetSize()); | 189 CHECK_EQ(1U, args->GetSize()); |
| 182 std::string callback_id; | 190 std::string callback_id; |
| 183 CHECK(args->GetString(0, &callback_id)); | 191 CHECK(args->GetString(0, &callback_id)); |
| 184 | 192 |
| 193 // Don't show the add/remove desktop shortcut button in the single user case. |
| 185 ProfileAttributesStorage& storage = | 194 ProfileAttributesStorage& storage = |
| 186 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 195 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 187 ProfileAttributesEntry* entry; | 196 if (storage.GetNumberOfProfiles() <= 1u) { |
| 188 if (!storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) | 197 ResolveJavascriptCallback(base::StringValue(callback_id), |
| 198 base::StringValue(kProfileShortcutSettingHidden)); |
| 189 return; | 199 return; |
| 190 | 200 } |
| 191 // Don't show the add/remove desktop shortcut button in the single user case. | |
| 192 if (storage.GetNumberOfProfiles() <= 1u) | |
| 193 return; | |
| 194 | 201 |
| 195 ProfileShortcutManager* shortcut_manager = | 202 ProfileShortcutManager* shortcut_manager = |
| 196 g_browser_process->profile_manager()->profile_shortcut_manager(); | 203 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 197 DCHECK(shortcut_manager); | 204 DCHECK(shortcut_manager); |
| 198 shortcut_manager->HasProfileShortcuts( | 205 shortcut_manager->HasProfileShortcuts( |
| 199 profile_->GetPath(), | 206 profile_->GetPath(), |
| 200 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, | 207 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, |
| 201 weak_factory_.GetWeakPtr(), callback_id)); | 208 weak_factory_.GetWeakPtr(), callback_id)); |
| 202 } | 209 } |
| 203 | 210 |
| 204 void ManageProfileHandler::OnHasProfileShortcuts( | 211 void ManageProfileHandler::OnHasProfileShortcuts( |
| 205 const std::string& callback_id, bool has_shortcuts) { | 212 const std::string& callback_id, bool has_shortcuts) { |
| 206 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 207 ResolveJavascriptCallback(base::StringValue(callback_id), | 214 ResolveJavascriptCallback( |
| 208 base::FundamentalValue(has_shortcuts)); | 215 base::StringValue(callback_id), |
| 216 base::StringValue(has_shortcuts ? kProfileShortcutFound |
| 217 : kProfileShortcutNotFound)); |
| 209 } | 218 } |
| 210 | 219 |
| 211 void ManageProfileHandler::HandleAddProfileShortcut( | 220 void ManageProfileHandler::HandleAddProfileShortcut( |
| 212 const base::ListValue* args) { | 221 const base::ListValue* args) { |
| 213 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 222 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 214 ProfileShortcutManager* shortcut_manager = | 223 ProfileShortcutManager* shortcut_manager = |
| 215 g_browser_process->profile_manager()->profile_shortcut_manager(); | 224 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 216 DCHECK(shortcut_manager); | 225 DCHECK(shortcut_manager); |
| 217 | 226 |
| 218 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); | 227 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); |
| 219 } | 228 } |
| 220 | 229 |
| 221 void ManageProfileHandler::HandleRemoveProfileShortcut( | 230 void ManageProfileHandler::HandleRemoveProfileShortcut( |
| 222 const base::ListValue* args) { | 231 const base::ListValue* args) { |
| 223 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 232 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 224 ProfileShortcutManager* shortcut_manager = | 233 ProfileShortcutManager* shortcut_manager = |
| 225 g_browser_process->profile_manager()->profile_shortcut_manager(); | 234 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 226 DCHECK(shortcut_manager); | 235 DCHECK(shortcut_manager); |
| 227 | 236 |
| 228 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); | 237 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); |
| 229 } | 238 } |
| 230 | 239 |
| 231 } // namespace settings | 240 } // namespace settings |
| OLD | NEW |