Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/value_conversions.h" | 11 #include "base/value_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/gaia_info_update_service.h" | 15 #include "chrome/browser/profiles/gaia_info_update_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
| 18 #include "chrome/browser/profiles/profile_info_util.h" | 18 #include "chrome/browser/profiles/profile_info_util.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
| 21 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 21 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 22 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
| 23 #include "chrome/browser/ui/webui/web_ui_util.h" | 23 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 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 #if defined(ENABLE_SETTINGS_APP) | |
| 31 #include "chrome/browser/ui/app_list/app_list_util.h" | |
| 32 #include "content/public/browser/web_contents.h" | |
| 33 #endif | |
| 34 | |
| 30 namespace options { | 35 namespace options { |
| 31 | 36 |
| 32 namespace { | 37 namespace { |
| 33 | 38 |
| 34 const char kCreateProfileIconGridName[] = "create-profile-icon-grid"; | 39 const char kCreateProfileIconGridName[] = "create-profile-icon-grid"; |
| 35 const char kManageProfileIconGridName[] = "manage-profile-icon-grid"; | 40 const char kManageProfileIconGridName[] = "manage-profile-icon-grid"; |
| 36 | 41 |
| 37 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path| | 42 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path| |
| 38 // and returns true on success. | 43 // and returns true on success. |
| 39 bool GetProfilePathFromArgs(const ListValue* args, | 44 bool GetProfilePathFromArgs(const ListValue* args, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 base::Unretained(this))); | 111 base::Unretained(this))); |
| 107 web_ui()->RegisterMessageCallback("requestNewProfileDefaults", | 112 web_ui()->RegisterMessageCallback("requestNewProfileDefaults", |
| 108 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults, | 113 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults, |
| 109 base::Unretained(this))); | 114 base::Unretained(this))); |
| 110 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", | 115 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", |
| 111 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, | 116 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, |
| 112 base::Unretained(this))); | 117 base::Unretained(this))); |
| 113 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", | 118 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", |
| 114 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, | 119 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, |
| 115 base::Unretained(this))); | 120 base::Unretained(this))); |
| 121 #if defined(ENABLE_SETTINGS_APP) | |
| 122 web_ui()->RegisterMessageCallback("profilesAppListSwitch", | |
| 123 base::Bind(&ManageProfileHandler::ProfilesAppListSwitch, | |
| 124 base::Unretained(this))); | |
| 125 #endif | |
| 116 } | 126 } |
| 117 | 127 |
| 118 void ManageProfileHandler::Observe( | 128 void ManageProfileHandler::Observe( |
| 119 int type, | 129 int type, |
| 120 const content::NotificationSource& source, | 130 const content::NotificationSource& source, |
| 121 const content::NotificationDetails& details) { | 131 const content::NotificationDetails& details) { |
| 122 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { | 132 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { |
| 123 SendProfileNames(); | 133 SendProfileNames(); |
| 124 base::StringValue value(kManageProfileIconGridName); | 134 base::StringValue value(kManageProfileIconGridName); |
| 125 SendProfileIcons(value); | 135 SendProfileIcons(value); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 Browser* browser = | 312 Browser* browser = |
| 303 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 313 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 304 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | 314 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 305 if (browser) | 315 if (browser) |
| 306 desktop_type = browser->host_desktop_type(); | 316 desktop_type = browser->host_desktop_type(); |
| 307 | 317 |
| 308 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 318 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
| 309 profile_file_path, desktop_type); | 319 profile_file_path, desktop_type); |
| 310 } | 320 } |
| 311 | 321 |
| 322 void ManageProfileHandler::ProfilesAppListSwitch(const ListValue* args) { | |
| 323 #if !defined(ENABLE_SETTINGS_APP) | |
| 324 return; | |
|
Evan Stade
2013/01/23 00:16:21
no need for this return
why is this function defi
koz (OOO until 15th September)
2013/01/23 02:58:58
Done.
| |
| 325 #else | |
| 326 DCHECK(args); | |
| 327 if (!ProfileManager::IsMultipleProfilesEnabled()) | |
| 328 return; | |
| 329 | |
| 330 const Value* file_path_value; | |
| 331 FilePath profile_file_path; | |
| 332 if (!args->Get(0, &file_path_value) || | |
| 333 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) | |
| 334 return; | |
| 335 | |
| 336 chrome::SetAppListProfile(profile_file_path); | |
| 337 // Close the settings app, since it will now be for the wrong profile. | |
| 338 web_ui()->GetWebContents()->Close(); | |
| 339 #endif // else !defined(ENABLE_SETTINGS_APP) | |
| 340 } | |
| 341 | |
| 312 void ManageProfileHandler::ProfileIconSelectionChanged( | 342 void ManageProfileHandler::ProfileIconSelectionChanged( |
| 313 const base::ListValue* args) { | 343 const base::ListValue* args) { |
| 314 DCHECK(args); | 344 DCHECK(args); |
| 315 | 345 |
| 316 FilePath profile_file_path; | 346 FilePath profile_file_path; |
| 317 if (!GetProfilePathFromArgs(args, &profile_file_path)) | 347 if (!GetProfilePathFromArgs(args, &profile_file_path)) |
| 318 return; | 348 return; |
| 319 | 349 |
| 320 // Currently this only supports editing the current profile's info. | 350 // Currently this only supports editing the current profile's info. |
| 321 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath()) | 351 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath()) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 | 398 |
| 369 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 399 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { |
| 370 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 400 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 371 | 401 |
| 372 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 402 const base::FundamentalValue has_shortcuts_value(has_shortcuts); |
| 373 web_ui()->CallJavascriptFunction( | 403 web_ui()->CallJavascriptFunction( |
| 374 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); | 404 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); |
| 375 } | 405 } |
| 376 | 406 |
| 377 } // namespace options | 407 } // namespace options |
| OLD | NEW |