Commit 6c85a056 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbui: migrate ProfileSigninConfirmationDialogViews to set_button_label

This dialog had a two-phase construction to supply some state that
logically was part of construction but was not yet available at
construction time. This change collapses construction of this dialog
into a single logical phase. Specifically:

1) ProfileSigninConfirmationDialogViews::ShowDialog now defers
   construction of the dialog until after
   ui::CheckShouldPromptForNewProfile
1) CheckShouldPromptForNewProfile now takes a base::OnceCallback instead
   of a base::Callback, to allow ownership of the
   ProfileSigninConfirmationDelegate to be passed through it
3) ProfileSigninConfirmationDialogViews::Show now both constructs and
   shows the ProfileSigninConfirmationDialogViews, passing in the
   prompt_for_new_profile member
4) The prompt_for_new_profile member is now made const
5) That makes the return values of GetDialogButtonLabel also constant
   after construction, which opens up migration to set_button_label

Bug: 1011446
Change-Id: I975d425546db6e2d231f0003d38f0f3fac64ad88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869489Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707480}
parent 12eae302
...@@ -85,20 +85,21 @@ bool HasSyncedExtensions(Profile* profile) { ...@@ -85,20 +85,21 @@ bool HasSyncedExtensions(Profile* profile) {
void CheckShouldPromptForNewProfile( void CheckShouldPromptForNewProfile(
Profile* profile, Profile* profile,
const base::Callback<void(bool)>& return_result) { base::OnceCallback<void(bool)> return_result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (HasBeenShutdown(profile) || if (HasBeenShutdown(profile) ||
HasBookmarks(profile) || HasBookmarks(profile) ||
HasSyncedExtensions(profile)) { HasSyncedExtensions(profile)) {
return_result.Run(true); std::move(return_result).Run(true);
return; return;
} }
history::HistoryService* service = history::HistoryService* service =
HistoryServiceFactory::GetForProfileWithoutCreating(profile); HistoryServiceFactory::GetForProfileWithoutCreating(profile);
// Fire asynchronous queries for profile data. // Fire asynchronous queries for profile data.
browser_sync::SigninConfirmationHelper* helper = browser_sync::SigninConfirmationHelper* helper =
new browser_sync::SigninConfirmationHelper(service, return_result); new browser_sync::SigninConfirmationHelper(service,
std::move(return_result));
helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt);
helper->CheckHasTypedURLs(); helper->CheckHasTypedURLs();
} }
......
...@@ -29,9 +29,8 @@ bool HasSyncedExtensions(Profile* profile); ...@@ -29,9 +29,8 @@ bool HasSyncedExtensions(Profile* profile);
// Determines whether the user should be prompted to create a new // Determines whether the user should be prompted to create a new
// profile before signin. // profile before signin.
void CheckShouldPromptForNewProfile( void CheckShouldPromptForNewProfile(Profile* profile,
Profile* profile, base::OnceCallback<void(bool)> cb);
const base::Callback<void(bool)>& cb);
// Handles user input from confirmation dialog. // Handles user input from confirmation dialog.
class ProfileSigninConfirmationDelegate { class ProfileSigninConfirmationDelegate {
......
...@@ -62,12 +62,13 @@ void GetValueAndQuit(T* result, const base::Closure& quit, T actual) { ...@@ -62,12 +62,13 @@ void GetValueAndQuit(T* result, const base::Closure& quit, T actual) {
quit.Run(); quit.Run();
} }
template<typename T> template <typename T>
T GetCallbackResult( T GetCallbackResult(
const base::Callback<void(const base::Callback<void(T)>&)>& callback) { const base::Callback<void(base::OnceCallback<void(T)>)>& callback) {
T result = false; T result = false;
base::RunLoop loop; base::RunLoop loop;
callback.Run(base::Bind(&GetValueAndQuit<T>, &result, loop.QuitClosure())); callback.Run(
base::BindOnce(&GetValueAndQuit<T>, &result, loop.QuitClosure()));
loop.Run(); loop.Run();
return result; return result;
} }
......
...@@ -47,18 +47,46 @@ ...@@ -47,18 +47,46 @@
ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews(
Browser* browser, Browser* browser,
const std::string& username, const std::string& username,
std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate,
bool prompt_for_new_profile)
: browser_(browser), : browser_(browser),
username_(username), username_(username),
delegate_(std::move(delegate)), delegate_(std::move(delegate)),
prompt_for_new_profile_(true) { prompt_for_new_profile_(prompt_for_new_profile) {
DialogDelegate::set_default_button(ui::DIALOG_BUTTON_NONE); DialogDelegate::set_default_button(ui::DIALOG_BUTTON_NONE);
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(prompt_for_new_profile_
? IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE
: IDS_ENTERPRISE_SIGNIN_CONTINUE));
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL));
if (prompt_for_new_profile) {
DialogDelegate::SetExtraView(views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE)));
}
chrome::RecordDialogCreation( chrome::RecordDialogCreation(
chrome::DialogIdentifier::PROFILE_SIGNIN_CONFIRMATION); chrome::DialogIdentifier::PROFILE_SIGNIN_CONFIRMATION);
} }
ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {}
// static
void ProfileSigninConfirmationDialogViews::Show(
Browser* browser,
const std::string& username,
std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate,
bool prompt) {
auto dialog = std::make_unique<ProfileSigninConfirmationDialogViews>(
browser, username, std::move(delegate), prompt);
constrained_window::CreateBrowserModalDialogViews(
dialog.release(), browser->window()->GetNativeWindow())
->Show();
}
// static // static
void ProfileSigninConfirmationDialogViews::ShowDialog( void ProfileSigninConfirmationDialogViews::ShowDialog(
Browser* browser, Browser* browser,
...@@ -74,25 +102,12 @@ void ProfileSigninConfirmationDialogViews::ShowDialog( ...@@ -74,25 +102,12 @@ void ProfileSigninConfirmationDialogViews::ShowDialog(
// is fixed. // is fixed.
ProfileMenuView::Hide(); ProfileMenuView::Hide();
ProfileSigninConfirmationDialogViews* dialog = // Checking whether to show the prompt is sometimes asynchronous. Defer
new ProfileSigninConfirmationDialogViews(browser, username, // constructing the dialog (in ::Show) until that check completes.
std::move(delegate));
ui::CheckShouldPromptForNewProfile( ui::CheckShouldPromptForNewProfile(
profile, profile,
// This callback is guaranteed to be invoked, and once it is, the dialog base::BindOnce(&ProfileSigninConfirmationDialogViews::Show,
// owns itself. base::Unretained(browser), username, std::move(delegate)));
base::Bind(&ProfileSigninConfirmationDialogViews::Show,
base::Unretained(dialog)));
}
void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) {
prompt_for_new_profile_ = prompt_for_new_profile;
if (prompt_for_new_profile) {
DialogDelegate::SetExtraView(views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE)));
}
constrained_window::CreateBrowserModalDialogViews(
this, browser_->window()->GetNativeWindow())->Show();
} }
base::string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const { base::string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const {
...@@ -100,19 +115,6 @@ base::string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const { ...@@ -100,19 +115,6 @@ base::string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const {
IDS_ENTERPRISE_SIGNIN_TITLE); IDS_ENTERPRISE_SIGNIN_TITLE);
} }
base::string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel(
ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK) {
// If we're giving the option to create a new profile, then OK is
// "Create new profile". Otherwise it is "Continue signin".
return l10n_util::GetStringUTF16(
prompt_for_new_profile_ ?
IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE :
IDS_ENTERPRISE_SIGNIN_CONTINUE);
}
return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL);
}
bool ProfileSigninConfirmationDialogViews::Accept() { bool ProfileSigninConfirmationDialogViews::Accept() {
if (delegate_) { if (delegate_) {
if (prompt_for_new_profile_) if (prompt_for_new_profile_)
......
...@@ -31,16 +31,22 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView, ...@@ -31,16 +31,22 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
const std::string& username, const std::string& username,
std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate); std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate);
private:
ProfileSigninConfirmationDialogViews( ProfileSigninConfirmationDialogViews(
Browser* browser, Browser* browser,
const std::string& username, const std::string& username,
std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate); std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate,
bool prompt_for_new_profile);
~ProfileSigninConfirmationDialogViews() override; ~ProfileSigninConfirmationDialogViews() override;
private:
static void Show(
Browser* browser,
const std::string& username,
std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate,
bool prompt_for_new_profile);
// views::DialogDelegateView: // views::DialogDelegateView:
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
...@@ -58,11 +64,6 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView, ...@@ -58,11 +64,6 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button*, const ui::Event& event) override; void ButtonPressed(views::Button*, const ui::Event& event) override;
// Shows the dialog and releases ownership of this object. It will
// delete itself when the dialog is closed. If |prompt_for_new_profile|
// is true, the dialog will offer to create a new profile before signin.
void Show(bool prompt_for_new_profile);
// Weak ptr to parent view. // Weak ptr to parent view.
Browser* const browser_; Browser* const browser_;
...@@ -73,7 +74,7 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView, ...@@ -73,7 +74,7 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate_; std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate_;
// Whether the user should be prompted to create a new profile. // Whether the user should be prompted to create a new profile.
bool prompt_for_new_profile_; const bool prompt_for_new_profile_;
DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationDialogViews); DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationDialogViews);
}; };
......
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