From 0bb1ba364e8999fffa93bae96d8a4f46da40e383 Mon Sep 17 00:00:00 2001 From: Monica Dinculescu Date: Wed, 4 Feb 2015 19:50:06 -0500 Subject: [PATCH] [Merge] Don't allow profile deletion in Metro mode. Bad things happen if you delete the profile that started the Metro process (at best, you crash), since relaunching Metro with a new user is not supported. Hiding the button selectively depending on the profile selected is a bit weird, so in Metro mode, hide it for all profiles. BUG=448352 TBR=noms@chromium.org Review URL: https://codereview.chromium.org/863063002 Cr-Commit-Position: refs/heads/master@{#313449} (cherry picked from commit 9a4fcc927bf745d6aab08440e22344b393246492) Conflicts: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc Review URL: https://codereview.chromium.org/887203003 Cr-Commit-Position: refs/branch-heads/2272@{#215} Cr-Branched-From: 827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4-refs/heads/master@{#310958} --- .../browser/resources/options/browser_options.js | 5 +++-- .../options/browser_options_profile_list.js | 7 +++++++ .../ui/webui/options/browser_options_handler.cc | 12 ++++++++++++ .../webui/signin/user_manager_screen_handler.cc | 16 +++++++++++----- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index 2dbfc5d0d5b7b..cb1f3521a07da 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -350,6 +350,8 @@ cr.define('options', function() { }; if (loadTimeData.getBoolean('profileIsSupervised')) { $('profiles-create').disabled = true; + } + if (!loadTimeData.getBoolean('allowProfileDeletion')) { $('profiles-delete').disabled = true; $('profiles-list').canDeleteItems = false; } @@ -1406,14 +1408,13 @@ cr.define('options', function() { var selectedProfile = profilesList.selectedItem; var hasSelection = selectedProfile != null; var hasSingleProfile = profilesList.dataModel.length == 1; - var isSupervised = loadTimeData.getBoolean('profileIsSupervised'); $('profiles-manage').disabled = !hasSelection || !selectedProfile.isCurrentProfile; if (hasSelection && !selectedProfile.isCurrentProfile) $('profiles-manage').title = loadTimeData.getString('currentUserOnly'); else $('profiles-manage').title = ''; - $('profiles-delete').disabled = isSupervised || + $('profiles-delete').disabled = !profilesList.canDeleteItems || (!hasSelection && !hasSingleProfile); if (OptionsPage.isSettingsApp()) { $('profiles-app-list-switch').disabled = !hasSelection || diff --git a/chrome/browser/resources/options/browser_options_profile_list.js b/chrome/browser/resources/options/browser_options_profile_list.js index ec3c1fa41337b..da4fcc3615a3a 100644 --- a/chrome/browser/resources/options/browser_options_profile_list.js +++ b/chrome/browser/resources/options/browser_options_profile_list.js @@ -122,6 +122,13 @@ cr.define('options.browser_options', function() { this.canDeleteItems_ = value; }, + /** + * @type {boolean} whether the items in this list are deletable. + */ + get canDeleteItems() { + return this.canDeleteItems_; + }, + /** * If false, items in this list will not be deletable. * @private diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index a7b366fc75c6f..df880ede78e24 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -145,6 +145,10 @@ #include "chrome/browser/local_discovery/privet_notifications.h" #endif +#if defined(USE_ASH) +#include "ash/shell.h" +#endif + using base::UserMetricsAction; using content::BrowserContext; using content::BrowserThread; @@ -615,6 +619,14 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) { if (ShouldShowMultiProfilesUserList()) values->Set("profilesInfo", GetProfilesInfoList().release()); + // Profile deletion is not allowed for supervised users, or any users + // using Metro mode. + bool allow_deletion = !Profile::FromWebUI(web_ui())->IsSupervised(); +#if defined(USE_ASH) + allow_deletion = allow_deletion && !ash::Shell::HasInstance(); +#endif + values->SetBoolean("allowProfileDeletion", allow_deletion); + values->SetBoolean("profileIsGuest", Profile::FromWebUI(web_ui())->IsOffTheRecord()); diff --git a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc index 85d878fe07ef2..3cb0f63894f3f 100644 --- a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc +++ b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc @@ -45,6 +45,10 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_util.h" +#if defined(USE_ASH) +#include "ash/shell.h" +#endif + namespace { // User dictionary keys. const char kKeyUsername[] = "username"; @@ -642,12 +646,14 @@ void UserManagerScreenHandler::SendUserList() { web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); const ProfileInfoCache& info_cache = g_browser_process->profile_manager()->GetProfileInfoCache(); - user_auth_type_map_.clear(); - // If the active user is a supervised user, then they may not perform - // certain actions (i.e. delete another user). - bool active_user_is_supervised = Profile::FromWebUI(web_ui())->IsSupervised(); + // Profile deletion is not allowed in Metro mode. + bool can_remove = true; +#if defined(USE_ASH) + can_remove = !ash::Shell::HasInstance(); +#endif + for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { base::DictionaryValue* profile_value = new base::DictionaryValue(); @@ -673,7 +679,7 @@ void UserManagerScreenHandler::SendUserList() { profile_value->SetBoolean( kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i)); profile_value->SetBoolean(kKeyIsOwner, false); - profile_value->SetBoolean(kKeyCanRemove, !active_user_is_supervised); + profile_value->SetBoolean(kKeyCanRemove, can_remove); profile_value->SetBoolean(kKeyIsDesktop, true); profile_value->SetString( kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache));