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 { ...@@ -20,6 +20,9 @@ class ProfilePicker {
// Hides the profile picker. // Hides the profile picker.
static void Hide(); static void Hide();
// Returns whether the profile picker is currently open.
static bool IsOpen();
private: private:
DISALLOW_COPY_AND_ASSIGN(ProfilePicker); DISALLOW_COPY_AND_ASSIGN(ProfilePicker);
}; };
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.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/signin/profile_colors_util.h"
#include "chrome/browser/ui/sync/sync_promo_ui.h" #include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
...@@ -400,24 +399,16 @@ void ProfileMenuView::OnAddNewProfileButtonClicked() { ...@@ -400,24 +399,16 @@ void ProfileMenuView::OnAddNewProfileButtonClicked() {
RecordClick(ActionableItem::kAddNewProfileButton); RecordClick(ActionableItem::kAddNewProfileButton);
if (!perform_menu_actions()) if (!perform_menu_actions())
return; return;
if (base::FeatureList::IsEnabled(features::kNewProfilePicker)) { UserManager::Show(/*profile_path_to_focus=*/base::FilePath(),
ProfilePicker::Show(ProfilePicker::Page::kAddNewProfile); profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE);
} else {
UserManager::Show(/*profile_path_to_focus=*/base::FilePath(),
profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE);
}
} }
void ProfileMenuView::OnManageProfilesButtonClicked() { void ProfileMenuView::OnManageProfilesButtonClicked() {
RecordClick(ActionableItem::kManageProfilesButton); RecordClick(ActionableItem::kManageProfilesButton);
if (!perform_menu_actions()) if (!perform_menu_actions())
return; return;
if (base::FeatureList::IsEnabled(features::kNewProfilePicker)) { UserManager::Show(base::FilePath(),
ProfilePicker::Show(ProfilePicker::Page::kManageProfiles); profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
} else {
UserManager::Show(base::FilePath(),
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
}
} }
void ProfileMenuView::OnEditProfileButtonClicked() { void ProfileMenuView::OnEditProfileButtonClicked() {
......
...@@ -64,6 +64,11 @@ void ProfilePicker::Hide() { ...@@ -64,6 +64,11 @@ void ProfilePicker::Hide() {
g_profile_picker_view->Clear(); g_profile_picker_view->Clear();
} }
// static
bool ProfilePicker::IsOpen() {
return g_profile_picker_view;
}
ProfilePickerView::ProfilePickerView() ProfilePickerView::ProfilePickerView()
: keep_alive_(KeepAliveOrigin::USER_MANAGER_VIEW, : keep_alive_(KeepAliveOrigin::USER_MANAGER_VIEW,
KeepAliveRestartOption::DISABLED) { KeepAliveRestartOption::DISABLED) {
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.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/browser/ui/user_manager.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
...@@ -168,6 +170,18 @@ void UserManager::Show( ...@@ -168,6 +170,18 @@ void UserManager::Show(
profiles::UserManagerAction user_manager_action) { profiles::UserManagerAction user_manager_action) {
DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); 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 (g_user_manager_view) {
// If we are showing the User Manager after locking a profile, change the // If we are showing the User Manager after locking a profile, change the
// active profile to Guest. // active profile to Guest.
...@@ -206,6 +220,9 @@ void UserManager::Show( ...@@ -206,6 +220,9 @@ void UserManager::Show(
// static // static
void UserManager::Hide() { void UserManager::Hide() {
// Hide the profile picker, in case it was opened by UserManager::Show().
ProfilePicker::Hide();
if (g_user_manager_view) if (g_user_manager_view)
g_user_manager_view->GetWidget()->Close(); g_user_manager_view->GetWidget()->Close();
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_util.h" #include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/ui/browser_finder.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/user_manager.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h" #include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "components/keep_alive_registry/keep_alive_types.h" #include "components/keep_alive_registry/keep_alive_types.h"
...@@ -60,6 +61,9 @@ void DeleteProfileCallback(std::unique_ptr<ScopedKeepAlive> keep_alive, ...@@ -60,6 +61,9 @@ void DeleteProfileCallback(std::unique_ptr<ScopedKeepAlive> keep_alive,
void OpenNewWindowForProfile(Profile* profile) { void OpenNewWindowForProfile(Profile* profile) {
if (profiles::IsProfileLocked(profile->GetPath())) { if (profiles::IsProfileLocked(profile->GetPath())) {
// The profile picker does not support locked profiles.
DCHECK(!ProfilePicker::IsOpen());
if (signin_util::IsForceSigninEnabled()) { if (signin_util::IsForceSigninEnabled()) {
// If force-sign-in policy is enabled, UserManager will be displayed // If force-sign-in policy is enabled, UserManager will be displayed
// without any sign-in dialog opened. // without any sign-in dialog opened.
...@@ -68,11 +72,18 @@ void OpenNewWindowForProfile(Profile* profile) { ...@@ -68,11 +72,18 @@ void OpenNewWindowForProfile(Profile* profile) {
ShowUserManager( ShowUserManager(
base::Bind(&ShowUnlockDialog, GetProfileUserName(profile))); base::Bind(&ShowUnlockDialog, GetProfileUserName(profile)));
} }
} else { return;
profiles::FindOrCreateNewWindowForProfile( }
profile, chrome::startup::IS_PROCESS_STARTUP,
chrome::startup::IS_FIRST_RUN, false); 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, void DeleteProfileAtPath(base::FilePath file_path,
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
namespace webui { 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); void OpenNewWindowForProfile(Profile* profile);
// Deletes the profile at the given |file_path|. // 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