Commit 9a4fcc92 authored by noms's avatar noms Committed by Commit bot

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

Review URL: https://codereview.chromium.org/863063002

Cr-Commit-Position: refs/heads/master@{#313449}
parent 907eabfa
......@@ -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 ||
......
......@@ -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
......
......@@ -138,6 +138,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;
......@@ -608,6 +612,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());
......
......@@ -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";
......@@ -633,9 +637,14 @@ void UserManagerScreenHandler::SendUserList() {
base::ListValue users_list;
const ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
user_auth_type_map_.clear();
// 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();
base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i);
......@@ -657,7 +666,7 @@ void UserManagerScreenHandler::SendUserList() {
profile_value->SetBoolean(
kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i));
profile_value->SetBoolean(kKeyIsOwner, false);
profile_value->SetBoolean(kKeyCanRemove, true);
profile_value->SetBoolean(kKeyCanRemove, can_remove);
profile_value->SetBoolean(kKeyIsDesktop, true);
profile_value->SetString(
kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment