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

Side by Side Diff: chrome/browser/ui/webui/options/manage_profile_handler.cc

Issue 11633041: Show a delete shortcut checkbox when editing a profile that has a shortcut. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options/manage_profile_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options/manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/options/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/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 16 matching lines...) Expand all
27 #include "content/public/browser/web_ui.h" 27 #include "content/public/browser/web_ui.h"
28 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
29 29
30 namespace options { 30 namespace options {
31 31
32 namespace { 32 namespace {
33 33
34 const char kCreateProfileIconGridName[] = "create-profile-icon-grid"; 34 const char kCreateProfileIconGridName[] = "create-profile-icon-grid";
35 const char kManageProfileIconGridName[] = "manage-profile-icon-grid"; 35 const char kManageProfileIconGridName[] = "manage-profile-icon-grid";
36 36
37 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path|
38 // and returns true on success.
39 bool GetProfilePathFromArgs(const ListValue* args,
40 FilePath* profile_file_path) {
41 const Value* file_path_value;
42 if (!args->Get(0, &file_path_value))
43 return false;
44 return base::GetValueAsFilePath(*file_path_value, profile_file_path);
45 }
46
37 } // namespace 47 } // namespace
38 48
39 ManageProfileHandler::ManageProfileHandler() { 49 ManageProfileHandler::ManageProfileHandler()
50 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
40 } 51 }
41 52
42 ManageProfileHandler::~ManageProfileHandler() { 53 ManageProfileHandler::~ManageProfileHandler() {
43 } 54 }
44 55
45 void ManageProfileHandler::GetLocalizedValues( 56 void ManageProfileHandler::GetLocalizedValues(
46 DictionaryValue* localized_strings) { 57 DictionaryValue* localized_strings) {
47 DCHECK(localized_strings); 58 DCHECK(localized_strings);
48 59
49 static OptionsStringResource resources[] = { 60 static OptionsStringResource resources[] = {
50 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL }, 61 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL },
51 { "manageProfilesDuplicateNameError", 62 { "manageProfilesDuplicateNameError",
52 IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR }, 63 IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR },
53 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL }, 64 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL },
54 { "manageProfilesManagedUserSettings", 65 { "manageProfilesManagedUserSettings",
55 IDS_PROFILES_MANAGE_MANAGED_USER_SETTINGS_BUTTON }, 66 IDS_PROFILES_MANAGE_MANAGED_USER_SETTINGS_BUTTON },
56 { "manageProfilesManagedLabel", IDS_PROFILES_CREATE_MANAGED_CHECKBOX }, 67 { "manageProfilesManagedLabel", IDS_PROFILES_CREATE_MANAGED_CHECKBOX },
57 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE }, 68 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE },
58 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL }, 69 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL },
59 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE }, 70 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE },
60 { "createProfileTitle", IDS_PROFILES_CREATE_TITLE }, 71 { "createProfileTitle", IDS_PROFILES_CREATE_TITLE },
61 { "createProfileInstructions", IDS_PROFILES_CREATE_INSTRUCTIONS }, 72 { "createProfileInstructions", IDS_PROFILES_CREATE_INSTRUCTIONS },
62 { "createProfileConfirm", IDS_PROFILES_CREATE_CONFIRM }, 73 { "createProfileConfirm", IDS_PROFILES_CREATE_CONFIRM },
63 { "createProfileShortcut", IDS_PROFILES_CREATE_SHORTCUT_CHKBOX }, 74 { "createProfileShortcut", IDS_PROFILES_CREATE_SHORTCUT_CHECKBOX },
75 { "removeProfileShortcut", IDS_PROFILES_REMOVE_SHORTCUT_CHECKBOX },
64 }; 76 };
65 77
66 RegisterStrings(localized_strings, resources, arraysize(resources)); 78 RegisterStrings(localized_strings, resources, arraysize(resources));
67 RegisterTitle(localized_strings, "manageProfile", 79 RegisterTitle(localized_strings, "manageProfile",
68 IDS_PROFILES_MANAGE_TITLE); 80 IDS_PROFILES_MANAGE_TITLE);
69 RegisterTitle(localized_strings, "createProfile", 81 RegisterTitle(localized_strings, "createProfile",
70 IDS_PROFILES_CREATE_TITLE); 82 IDS_PROFILES_CREATE_TITLE);
83
84 localized_strings->SetBoolean("profileShortcutsEnabled",
85 ProfileShortcutManager::IsFeatureEnabled());
71 } 86 }
72 87
73 void ManageProfileHandler::InitializeHandler() { 88 void ManageProfileHandler::InitializeHandler() {
74 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 89 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
75 content::NotificationService::AllSources()); 90 content::NotificationService::AllSources());
76 } 91 }
77 92
78 void ManageProfileHandler::InitializePage() { 93 void ManageProfileHandler::InitializePage() {
79 SendProfileNames(); 94 SendProfileNames();
80 } 95 }
81 96
82 void ManageProfileHandler::RegisterMessages() { 97 void ManageProfileHandler::RegisterMessages() {
83 web_ui()->RegisterMessageCallback("setProfileNameAndIcon", 98 web_ui()->RegisterMessageCallback("setProfileNameAndIcon",
84 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon, 99 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon,
85 base::Unretained(this))); 100 base::Unretained(this)));
86 web_ui()->RegisterMessageCallback("deleteProfile", 101 web_ui()->RegisterMessageCallback("deleteProfile",
87 base::Bind(&ManageProfileHandler::DeleteProfile, 102 base::Bind(&ManageProfileHandler::DeleteProfile,
88 base::Unretained(this))); 103 base::Unretained(this)));
89 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", 104 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons",
90 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, 105 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons,
91 base::Unretained(this))); 106 base::Unretained(this)));
92 web_ui()->RegisterMessageCallback("requestNewProfileDefaults", 107 web_ui()->RegisterMessageCallback("requestNewProfileDefaults",
93 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults, 108 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults,
94 base::Unretained(this))); 109 base::Unretained(this)));
110 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts",
111 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts,
112 base::Unretained(this)));
95 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", 113 web_ui()->RegisterMessageCallback("profileIconSelectionChanged",
96 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, 114 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged,
97 base::Unretained(this))); 115 base::Unretained(this)));
98 } 116 }
99 117
100 void ManageProfileHandler::Observe( 118 void ManageProfileHandler::Observe(
101 int type, 119 int type,
102 const content::NotificationSource& source, 120 const content::NotificationSource& source,
103 const content::NotificationDetails& details) { 121 const content::NotificationDetails& details) {
104 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { 122 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), 186 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)),
169 true); 187 true);
170 188
171 web_ui()->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames", 189 web_ui()->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames",
172 profile_name_dict); 190 profile_name_dict);
173 } 191 }
174 192
175 void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) { 193 void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) {
176 DCHECK(args); 194 DCHECK(args);
177 195
178 const Value* file_path_value;
179 FilePath profile_file_path; 196 FilePath profile_file_path;
180 if (!args->Get(0, &file_path_value) || 197 if (!GetProfilePathFromArgs(args, &profile_file_path))
181 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
182 return; 198 return;
183 199
184 ProfileInfoCache& cache = 200 ProfileInfoCache& cache =
185 g_browser_process->profile_manager()->GetProfileInfoCache(); 201 g_browser_process->profile_manager()->GetProfileInfoCache();
186 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 202 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
187 if (profile_index == std::string::npos) 203 if (profile_index == std::string::npos)
188 return; 204 return;
189 205
190 Profile* profile = 206 Profile* profile =
191 g_browser_process->profile_manager()->GetProfile(profile_file_path); 207 g_browser_process->profile_manager()->GetProfile(profile_file_path);
192 if (!profile) 208 if (!profile)
193 return; 209 return;
194 210
195 bool shortcut_checked; 211 std::string shortcut_mode;
196 if (!args->GetBoolean(3, &shortcut_checked)) 212 if (!args->GetString(3, &shortcut_mode))
197 return; 213 return;
198 if (shortcut_checked) { 214 if (!shortcut_mode.empty()) {
215 DCHECK(ProfileShortcutManager::IsFeatureEnabled());
199 ProfileShortcutManager* shortcut_manager = 216 ProfileShortcutManager* shortcut_manager =
200 g_browser_process->profile_manager()->profile_shortcut_manager(); 217 g_browser_process->profile_manager()->profile_shortcut_manager();
201 if (shortcut_manager) { 218 DCHECK(shortcut_manager);
202 shortcut_manager->CreateProfileShortcut( 219
203 cache.GetPathOfProfileAtIndex(profile_index)); 220 const FilePath profile_path = cache.GetPathOfProfileAtIndex(profile_index);
221 if (shortcut_mode == "create") {
222 shortcut_manager->CreateProfileShortcut(profile_path);
223 } else if (shortcut_mode == "remove") {
224 shortcut_manager->RemoveProfileShortcuts(profile_path);
225 } else {
226 NOTREACHED() << shortcut_mode;
204 } 227 }
205 } 228 }
206 229
207 string16 new_profile_name; 230 string16 new_profile_name;
208 if (!args->GetString(1, &new_profile_name)) 231 if (!args->GetString(1, &new_profile_name))
209 return; 232 return;
210 if (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index)) { 233 if (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index)) {
211 // Set the profile to use the GAIA name as the profile name. Note, this 234 // Set the profile to use the GAIA name as the profile name. Note, this
212 // is a little weird if the user typed their GAIA name manually but 235 // is a little weird if the user typed their GAIA name manually but
213 // it's not a big deal. 236 // it's not a big deal.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 288
266 void ManageProfileHandler::DeleteProfile(const ListValue* args) { 289 void ManageProfileHandler::DeleteProfile(const ListValue* args) {
267 DCHECK(args); 290 DCHECK(args);
268 // This handler could have been called in managed mode, for example because 291 // This handler could have been called in managed mode, for example because
269 // the user fiddled with the web inspector. Silently return in this case. 292 // the user fiddled with the web inspector. Silently return in this case.
270 if (!ProfileManager::IsMultipleProfilesEnabled()) 293 if (!ProfileManager::IsMultipleProfilesEnabled())
271 return; 294 return;
272 295
273 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); 296 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED);
274 297
275 const Value* file_path_value;
276 FilePath profile_file_path; 298 FilePath profile_file_path;
277 if (!args->Get(0, &file_path_value) || 299 if (!GetProfilePathFromArgs(args, &profile_file_path))
278 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
279 return; 300 return;
280 301
281 Browser* browser = 302 Browser* browser =
282 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); 303 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
283 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; 304 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE;
284 if (browser) 305 if (browser)
285 desktop_type = browser->host_desktop_type(); 306 desktop_type = browser->host_desktop_type();
286 307
287 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 308 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
288 profile_file_path, desktop_type); 309 profile_file_path, desktop_type);
289 } 310 }
290 311
291 void ManageProfileHandler::ProfileIconSelectionChanged( 312 void ManageProfileHandler::ProfileIconSelectionChanged(
292 const base::ListValue* args) { 313 const base::ListValue* args) {
293 DCHECK(args); 314 DCHECK(args);
294 315
295 const Value* file_path_value; 316 FilePath profile_file_path;
296 FilePath file_path; 317 if (!GetProfilePathFromArgs(args, &profile_file_path))
297 if (!args->Get(0, &file_path_value) ||
298 !base::GetValueAsFilePath(*file_path_value, &file_path)) {
299 return; 318 return;
300 }
301 319
302 // Currently this only supports editing the current profile's info. 320 // Currently this only supports editing the current profile's info.
303 if (file_path != Profile::FromWebUI(web_ui())->GetPath()) 321 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath())
304 return; 322 return;
305 323
306 std::string icon_url; 324 std::string icon_url;
307 if (!args->GetString(1, &icon_url)) 325 if (!args->GetString(1, &icon_url))
308 return; 326 return;
309 327
310 if (icon_url != gaia_picture_url_) 328 if (icon_url != gaia_picture_url_)
311 return; 329 return;
312 330
313 // If the selection is the GAIA picture then also show the GAIA name in the 331 // If the selection is the GAIA picture then also show the GAIA name in the
314 // text field. 332 // text field.
315 ProfileInfoCache& cache = 333 ProfileInfoCache& cache =
316 g_browser_process->profile_manager()->GetProfileInfoCache(); 334 g_browser_process->profile_manager()->GetProfileInfoCache();
317 size_t i = cache.GetIndexOfProfileWithPath(file_path); 335 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
318 if (i == std::string::npos) 336 if (profile_index == std::string::npos)
319 return; 337 return;
320 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); 338 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(profile_index);
321 if (gaia_name.empty()) 339 if (gaia_name.empty())
322 return; 340 return;
323 341
324 StringValue gaia_name_value(gaia_name); 342 StringValue gaia_name_value(gaia_name);
325 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", 343 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName",
326 gaia_name_value); 344 gaia_name_value);
327 } 345 }
328 346
347 void ManageProfileHandler::RequestHasProfileShortcuts(const ListValue* args) {
348 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
349 DCHECK(ProfileShortcutManager::IsFeatureEnabled());
350
351 FilePath profile_file_path;
352 if (!GetProfilePathFromArgs(args, &profile_file_path))
353 return;
354
355 const ProfileInfoCache& cache =
356 g_browser_process->profile_manager()->GetProfileInfoCache();
357 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
358 if (profile_index == std::string::npos)
359 return;
360
361 const FilePath profile_path = cache.GetPathOfProfileAtIndex(profile_index);
362 ProfileShortcutManager* shortcut_manager =
363 g_browser_process->profile_manager()->profile_shortcut_manager();
364 shortcut_manager->HasProfileShortcuts(
365 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts,
366 weak_factory_.GetWeakPtr()));
367 }
368
369 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) {
370 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
371
372 const base::FundamentalValue has_shortcuts_value(has_shortcuts);
373 web_ui()->CallJavascriptFunction(
374 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value);
375 }
376
329 } // namespace options 377 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/manage_profile_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698