Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Merge] Don't allow profile deletion in Metro mode.
Browse files Browse the repository at this point in the history
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 9a4fcc9)

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: 827a380-refs/heads/master@{#310958}
  • Loading branch information
notwaldorf committed Feb 5, 2015
1 parent 2d097b0 commit 0bb1ba3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
5 changes: 3 additions & 2 deletions chrome/browser/resources/options/browser_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions chrome/browser/ui/webui/options/browser_options_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down
16 changes: 11 additions & 5 deletions chrome/browser/ui/webui/signin/user_manager_screen_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();

Expand All @@ -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));
Expand Down

0 comments on commit 0bb1ba3

Please sign in to comment.