Commit 9d460464 authored by Alex Ilin's avatar Alex Ilin Committed by Commit Bot

[ProfilePicker] Link to the new profile picker from the profile menu

The profile menu has the "manage profiles" and the "add new profile"
buttons that should link to the new profile manager when it's enabled.

Bug: 1063856
Change-Id: I8ce5ea06910f7d3d16d512743bb9b06e8b66862e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362790
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Auto-Submit: Alex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799122}
parent 3e3c85f5
......@@ -7,8 +7,15 @@
class ProfilePicker {
public:
// Shows the Profile picker or re-activates an existing one.
static void Show();
// Different pages to be displayed when the profile picker window opens.
enum class Page {
kManageProfiles,
kAddNewProfile,
};
// Shows the Profile picker on the given `page` or re-activates an existing
// one. In the latter case, the `page` parameter is ignored.
static void Show(Page page = Page::kManageProfiles);
// Hides the profile picker.
static void Hide();
......
......@@ -34,6 +34,7 @@
#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"
......@@ -399,16 +400,24 @@ void ProfileMenuView::OnAddNewProfileButtonClicked() {
RecordClick(ActionableItem::kAddNewProfileButton);
if (!perform_menu_actions())
return;
UserManager::Show(/*profile_path_to_focus=*/base::FilePath(),
profiles::USER_MANAGER_OPEN_CREATE_USER_PAGE);
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);
}
}
void ProfileMenuView::OnManageProfilesButtonClicked() {
RecordClick(ActionableItem::kManageProfilesButton);
if (!perform_menu_actions())
return;
UserManager::Show(base::FilePath(),
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
if (base::FeatureList::IsEnabled(features::kNewProfilePicker)) {
ProfilePicker::Show(ProfilePicker::Page::kManageProfiles);
} else {
UserManager::Show(base::FilePath(),
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
}
}
void ProfileMenuView::OnEditProfileButtonClicked() {
......
......@@ -33,14 +33,25 @@ ProfilePickerView* g_profile_picker_view = nullptr;
constexpr int kWindowWidth = 1024;
constexpr int kWindowHeight = 758;
constexpr float kMaxRatioOfWorkArea = 0.9;
GURL CreateURLForPage(ProfilePicker::Page page) {
GURL base_url = GURL(chrome::kChromeUIProfilePickerUrl);
switch (page) {
case ProfilePicker::Page::kManageProfiles:
return base_url;
case ProfilePicker::Page::kAddNewProfile:
return base_url.Resolve("new-profile");
}
}
} // namespace
// static
void ProfilePicker::Show() {
void ProfilePicker::Show(Page page) {
if (!g_profile_picker_view)
g_profile_picker_view = new ProfilePickerView();
g_profile_picker_view->Display();
g_profile_picker_view->Display(page);
}
// static
......@@ -60,13 +71,13 @@ ProfilePickerView::ProfilePickerView()
ProfilePickerView::~ProfilePickerView() = default;
void ProfilePickerView::Display() {
void ProfilePickerView::Display(ProfilePicker::Page page) {
if (initialized_ == kNotInitialized) {
initialized_ = kInProgress;
g_browser_process->profile_manager()->CreateProfileAsync(
ProfileManager::GetSystemProfilePath(),
base::BindRepeating(&ProfilePickerView::OnSystemProfileCreated,
weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr(), page),
/*name=*/base::string16(), /*icon_url=*/std::string());
return;
}
......@@ -87,16 +98,18 @@ void ProfilePickerView::Clear() {
DeleteDelegate();
}
void ProfilePickerView::OnSystemProfileCreated(Profile* system_profile,
void ProfilePickerView::OnSystemProfileCreated(ProfilePicker::Page init_page,
Profile* system_profile,
Profile::CreateStatus status) {
DCHECK_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL);
if (status != Profile::CREATE_STATUS_INITIALIZED)
return;
Init(system_profile);
Init(init_page, system_profile);
}
void ProfilePickerView::Init(Profile* system_profile) {
void ProfilePickerView::Init(ProfilePicker::Page init_page,
Profile* system_profile) {
web_view_ = new views::WebView(system_profile);
AddChildView(web_view_);
SetLayoutManager(std::make_unique<views::FillLayout>());
......@@ -111,7 +124,7 @@ void ProfilePickerView::Init(Profile* system_profile) {
views::HWNDForWidget(GetWidget()));
#endif
web_view_->LoadInitialURL(GURL(chrome::kChromeUIProfilePickerUrl));
web_view_->LoadInitialURL(CreateURLForPage(init_page));
GetWidget()->Show();
web_view_->RequestFocus();
initialized_ = InitState::kDone;
......
......@@ -26,16 +26,17 @@ class ProfilePickerView : public views::DialogDelegateView {
};
// Displays the profile picker.
void Display();
void Display(ProfilePicker::Page page);
// Hides the profile picker.
void Clear();
// On system profile creation success, it initializes the view.
void OnSystemProfileCreated(Profile* system_profile,
void OnSystemProfileCreated(ProfilePicker::Page init_page,
Profile* system_profile,
Profile::CreateStatus status);
// Creates and shows the dialog.
void Init(Profile* guest_profile);
void Init(ProfilePicker::Page init_page, Profile* system_profile);
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
......
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