Commit 0385f9fd authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Stay in the profile picker after deleting a profile

If the last active profile was deleted, a new browser was always opened.
After this CL, no browser is automatically opened if there is a profile
picker.

Note: if the last profile was deleted, a new profile is still created
and loaded in memory.

This CL also fixes a few instances where the wrong user manager was
opened (ProfilePicker opened instead of UserManager or vice-versa).

Fixed: 1121545
Change-Id: Ifbcd02ec1b1015a5736dd1714e36d5cf61d043da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375211
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Auto-Submit: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801923}
parent da2cd8dd
......@@ -20,6 +20,9 @@ class ProfilePicker {
// Hides the profile picker.
static void Hide();
// Returns whether the profile picker is currently open.
static bool IsOpen();
private:
DISALLOW_COPY_AND_ASSIGN(ProfilePicker);
};
......
......@@ -34,7 +34,6 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/ui_features.h"
......@@ -400,24 +399,16 @@ void ProfileMenuView::OnAddNewProfileButtonClicked() {
RecordClick(ActionableItem::kAddNewProfileButton);
if (!perform_menu_actions())
return;
if (base::FeatureList::IsEnabled(features::kNewProfilePicker)) {
ProfilePicker::Show(ProfilePicker::Page::kAddNewProfile);
} else {
UserManager::Show(/*profile_path_to_focus=*/base::FilePath(),
profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE);
}
UserManager::Show(/*profile_path_to_focus=*/base::FilePath(),
profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE);
}
void ProfileMenuView::OnManageProfilesButtonClicked() {
RecordClick(ActionableItem::kManageProfilesButton);
if (!perform_menu_actions())
return;
if (base::FeatureList::IsEnabled(features::kNewProfilePicker)) {
ProfilePicker::Show(ProfilePicker::Page::kManageProfiles);
} else {
UserManager::Show(base::FilePath(),
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
}
UserManager::Show(base::FilePath(),
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
}
void ProfileMenuView::OnEditProfileButtonClicked() {
......
......@@ -64,6 +64,11 @@ void ProfilePicker::Hide() {
g_profile_picker_view->Clear();
}
// static
bool ProfilePicker::IsOpen() {
return g_profile_picker_view;
}
ProfilePickerView::ProfilePickerView()
: keep_alive_(KeepAliveOrigin::USER_MANAGER_VIEW,
KeepAliveRestartOption::DISABLED) {
......
......@@ -25,6 +25,8 @@
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
......@@ -168,6 +170,18 @@ void UserManager::Show(
profiles::UserManagerAction user_manager_action) {
DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());
if (!signin_util::IsForceSigninEnabled() &&
(user_manager_action == profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION ||
user_manager_action == profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE) &&
base::FeatureList::IsEnabled(features::kNewProfilePicker)) {
// Use the new profile picker instead.
ProfilePicker::Show(user_manager_action ==
profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE
? ProfilePicker::Page::kAddNewProfile
: ProfilePicker::Page::kManageProfiles);
return;
}
if (g_user_manager_view) {
// If we are showing the User Manager after locking a profile, change the
// active profile to Guest.
......@@ -206,6 +220,9 @@ void UserManager::Show(
// static
void UserManager::Hide() {
// Hide the profile picker, in case it was opened by UserManager::Show().
ProfilePicker::Hide();
if (g_user_manager_view)
g_user_manager_view->GetWidget()->Close();
}
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "components/keep_alive_registry/keep_alive_types.h"
......@@ -60,6 +61,9 @@ void DeleteProfileCallback(std::unique_ptr<ScopedKeepAlive> keep_alive,
void OpenNewWindowForProfile(Profile* profile) {
if (profiles::IsProfileLocked(profile->GetPath())) {
// The profile picker does not support locked profiles.
DCHECK(!ProfilePicker::IsOpen());
if (signin_util::IsForceSigninEnabled()) {
// If force-sign-in policy is enabled, UserManager will be displayed
// without any sign-in dialog opened.
......@@ -68,11 +72,18 @@ void OpenNewWindowForProfile(Profile* profile) {
ShowUserManager(
base::Bind(&ShowUnlockDialog, GetProfileUserName(profile)));
}
} else {
profiles::FindOrCreateNewWindowForProfile(
profile, chrome::startup::IS_PROCESS_STARTUP,
chrome::startup::IS_FIRST_RUN, false);
return;
}
if (ProfilePicker::IsOpen()) {
// If the profile picker is open, do not open a new browser automatically.
ProfilePicker::Show();
return;
}
profiles::FindOrCreateNewWindowForProfile(
profile, chrome::startup::IS_PROCESS_STARTUP,
chrome::startup::IS_FIRST_RUN, false);
}
void DeleteProfileAtPath(base::FilePath file_path,
......
......@@ -11,6 +11,10 @@
namespace webui {
// Opens a new window for |profile|, or:
// - if the profile is locked, opens the user manager instead
// - if the profile picker is already open, focuses it instead
// Exposed for testing.
void OpenNewWindowForProfile(Profile* profile);
// Deletes the profile at the given |file_path|.
......
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