Commit e5459643 authored by Jeremy Chinsen's avatar Jeremy Chinsen Committed by Commit Bot

Make TabModalConfirmDialog::Create take a unique_ptr

TabModalConfirmDialog takes ownership of the
TabModalConfirmDialogDelegate* passed in, but its comment did not convey
this. Changing the parameter to a unique_ptr expresses this explicitly.

Bug: 961772
Change-Id: Id7f4242a0797d3d49237b833b0bd6af4c146dd98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626502Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jeremy Chinsen <chinsenj@google.com>
Cr-Commit-Position: refs/heads/master@{#664034}
parent 607cb24e
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/download/download_open_prompt.h" #include "chrome/browser/download/download_open_prompt.h"
#include <memory>
#include <utility>
#include "base/callback.h" #include "base/callback.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
...@@ -102,10 +105,11 @@ DownloadOpenPrompt* DownloadOpenPrompt::CreateDownloadOpenConfirmationDialog( ...@@ -102,10 +105,11 @@ DownloadOpenPrompt* DownloadOpenPrompt::CreateDownloadOpenConfirmationDialog(
const std::string& extension_name, const std::string& extension_name,
const base::FilePath& file_path, const base::FilePath& file_path,
DownloadOpenPrompt::OpenCallback open_callback) { DownloadOpenPrompt::OpenCallback open_callback) {
DownloadOpenConfirmationDialog* prompt = new DownloadOpenConfirmationDialog( auto prompt = std::make_unique<DownloadOpenConfirmationDialog>(
web_contents, extension_name, file_path, std::move(open_callback)); web_contents, extension_name, file_path, std::move(open_callback));
TabModalConfirmDialog::Create(prompt, web_contents); DownloadOpenConfirmationDialog* prompt_observer = prompt.get();
return prompt; TabModalConfirmDialog::Create(std::move(prompt), web_contents);
return prompt_observer;
} }
void DownloadOpenPrompt::AcceptConfirmationDialogForTesting( void DownloadOpenPrompt::AcceptConfirmationDialogForTesting(
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h" #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h"
#include <memory>
#include "base/callback.h" #include "base/callback.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h" #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
...@@ -93,7 +95,7 @@ void CreateDirectoryAccessConfirmationDialog(bool writable, ...@@ -93,7 +95,7 @@ void CreateDirectoryAccessConfirmationDialog(bool writable,
const base::Closure& on_accept, const base::Closure& on_accept,
const base::Closure& on_cancel) { const base::Closure& on_cancel) {
TabModalConfirmDialog::Create( TabModalConfirmDialog::Create(
new DirectoryAccessConfirmationDialog( std::make_unique<DirectoryAccessConfirmationDialog>(
writable, app_name, web_contents, on_accept, on_cancel), writable, app_name, web_contents, on_accept, on_cancel),
web_contents); web_contents);
} }
...@@ -1551,8 +1551,8 @@ bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) { ...@@ -1551,8 +1551,8 @@ bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) {
} }
void Browser::ShowRepostFormWarningDialog(WebContents* source) { void Browser::ShowRepostFormWarningDialog(WebContents* source) {
TabModalConfirmDialog::Create(new RepostFormWarningController(source), TabModalConfirmDialog::Create(
source); std::make_unique<RepostFormWarningController>(source), source);
} }
bool Browser::ShouldCreateWebContents( bool Browser::ShouldCreateWebContents(
......
...@@ -66,9 +66,10 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) { ...@@ -66,9 +66,10 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
// Showing constrained window should disable find. // Showing constrained window should disable find.
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
MockTabModalConfirmDialogDelegate* delegate = auto delegate = std::make_unique<MockTabModalConfirmDialogDelegate>(
new MockTabModalConfirmDialogDelegate(web_contents, NULL); web_contents, nullptr);
TabModalConfirmDialog::Create(delegate, web_contents); MockTabModalConfirmDialogDelegate* delegate_ptr = delegate.get();
TabModalConfirmDialog::Create(std::move(delegate), web_contents);
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
// Switching to a new (unblocked) tab should reenable it. // Switching to a new (unblocked) tab should reenable it.
...@@ -80,7 +81,7 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) { ...@@ -80,7 +81,7 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
// Closing the constrained window should reenable it. // Closing the constrained window should reenable it.
delegate->Cancel(); delegate_ptr->Cancel();
content::RunAllPendingInMessageLoop(); content::RunAllPendingInMessageLoop();
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_H_ #ifndef CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_H_
#define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_H_ #define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_H_
#include <memory>
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
...@@ -17,8 +19,9 @@ class TabModalConfirmDialog : public TabModalConfirmDialogCloseDelegate { ...@@ -17,8 +19,9 @@ class TabModalConfirmDialog : public TabModalConfirmDialogCloseDelegate {
public: public:
// Platform specific factory function. This function will automatically show // Platform specific factory function. This function will automatically show
// the dialog. // the dialog.
static TabModalConfirmDialog* Create(TabModalConfirmDialogDelegate* delegate, static TabModalConfirmDialog* Create(
content::WebContents* web_contents); std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents);
// Accepts the dialog. // Accepts the dialog.
virtual void AcceptTabModalDialog() = 0; virtual void AcceptTabModalDialog() = 0;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h" #include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
#include <memory>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
...@@ -57,10 +60,12 @@ TabModalConfirmDialogTest::TabModalConfirmDialogTest() ...@@ -57,10 +60,12 @@ TabModalConfirmDialogTest::TabModalConfirmDialogTest()
closed_count_(0) {} closed_count_(0) {}
void TabModalConfirmDialogTest::SetUpOnMainThread() { void TabModalConfirmDialogTest::SetUpOnMainThread() {
delegate_ = new MockTabModalConfirmDialogDelegate( auto delegate = std::make_unique<MockTabModalConfirmDialogDelegate>(
browser()->tab_strip_model()->GetActiveWebContents(), this); browser()->tab_strip_model()->GetActiveWebContents(), this);
delegate_ = delegate.get();
dialog_ = TabModalConfirmDialog::Create( dialog_ = TabModalConfirmDialog::Create(
delegate_, browser()->tab_strip_model()->GetActiveWebContents()); std::move(delegate),
browser()->tab_strip_model()->GetActiveWebContents());
content::RunAllPendingInMessageLoop(); content::RunAllPendingInMessageLoop();
} }
......
...@@ -317,12 +317,14 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, GetAccessibleTabModalDialogTitle) { ...@@ -317,12 +317,14 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, GetAccessibleTabModalDialogTitle) {
window_title, base::CompareCase::SENSITIVE)); window_title, base::CompareCase::SENSITIVE));
content::WebContents* contents = browser_view()->GetActiveWebContents(); content::WebContents* contents = browser_view()->GetActiveWebContents();
TestTabModalConfirmDialogDelegate* delegate = auto delegate = std::make_unique<TestTabModalConfirmDialogDelegate>(contents);
new TestTabModalConfirmDialogDelegate(contents); TestTabModalConfirmDialogDelegate* delegate_observer = delegate.get();
TabModalConfirmDialog::Create(delegate, contents); TabModalConfirmDialog::Create(std::move(delegate), contents);
EXPECT_EQ(browser_view()->GetAccessibleWindowTitle(), delegate->GetTitle()); EXPECT_EQ(browser_view()->GetAccessibleWindowTitle(),
delegate_observer->GetTitle());
delegate_observer->Close();
delegate->Close();
EXPECT_TRUE(base::StartsWith(browser_view()->GetAccessibleWindowTitle(), EXPECT_TRUE(base::StartsWith(browser_view()->GetAccessibleWindowTitle(),
window_title, base::CompareCase::SENSITIVE)); window_title, base::CompareCase::SENSITIVE));
} }
...@@ -349,9 +351,8 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, GetAccessibleTabModalDialogTree) { ...@@ -349,9 +351,8 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, GetAccessibleTabModalDialogTree) {
nullptr); nullptr);
content::WebContents* contents = browser_view()->GetActiveWebContents(); content::WebContents* contents = browser_view()->GetActiveWebContents();
TestTabModalConfirmDialogDelegate* delegate = auto delegate = std::make_unique<TestTabModalConfirmDialogDelegate>(contents);
new TestTabModalConfirmDialogDelegate(contents); TabModalConfirmDialog::Create(std::move(delegate), contents);
TabModalConfirmDialog::Create(delegate, contents);
// The tab modal dialog should be in the accessibility tree; everything else // The tab modal dialog should be in the accessibility tree; everything else
// should be hidden. So we expect an "OK" button and no reload button. // should be hidden. So we expect an "OK" button and no reload button.
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h" #include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h"
#include <memory>
#include <utility>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
...@@ -21,25 +24,25 @@ ...@@ -21,25 +24,25 @@
// static // static
TabModalConfirmDialog* TabModalConfirmDialog::Create( TabModalConfirmDialog* TabModalConfirmDialog::Create(
TabModalConfirmDialogDelegate* delegate, std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents) { content::WebContents* web_contents) {
return new TabModalConfirmDialogViews(delegate, web_contents); return new TabModalConfirmDialogViews(std::move(delegate), web_contents);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// TabModalConfirmDialogViews, constructor & destructor: // TabModalConfirmDialogViews, constructor & destructor:
TabModalConfirmDialogViews::TabModalConfirmDialogViews( TabModalConfirmDialogViews::TabModalConfirmDialogViews(
TabModalConfirmDialogDelegate* delegate, std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents) content::WebContents* web_contents)
: delegate_(delegate) { : delegate_(std::move(delegate)) {
views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage()); views::MessageBoxView::InitParams init_params(delegate_->GetDialogMessage());
init_params.inter_row_vertical_spacing = init_params.inter_row_vertical_spacing =
ChromeLayoutProvider::Get()->GetDistanceMetric( ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_UNRELATED_CONTROL_VERTICAL); views::DISTANCE_UNRELATED_CONTROL_VERTICAL);
message_box_view_ = new views::MessageBoxView(init_params); message_box_view_ = new views::MessageBoxView(init_params);
base::string16 link_text(delegate->GetLinkText()); base::string16 link_text(delegate_->GetLinkText());
if (!link_text.empty()) if (!link_text.empty())
message_box_view_->SetLink(link_text, this); message_box_view_->SetLink(link_text, this);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_ #ifndef CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_ #define CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_
#include <memory>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h" #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
...@@ -30,8 +32,9 @@ class TabModalConfirmDialogViews : public TabModalConfirmDialog, ...@@ -30,8 +32,9 @@ class TabModalConfirmDialogViews : public TabModalConfirmDialog,
public views::DialogDelegate, public views::DialogDelegate,
public views::LinkListener { public views::LinkListener {
public: public:
TabModalConfirmDialogViews(TabModalConfirmDialogDelegate* delegate, TabModalConfirmDialogViews(
content::WebContents* web_contents); std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents);
// views::DialogDelegate: // views::DialogDelegate:
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/vr/service/xr_session_request_consent_manager_impl.h" #include "chrome/browser/vr/service/xr_session_request_consent_manager_impl.h"
#include <memory>
#include <utility> #include <utility>
#include "chrome/browser/ui/tab_modal_confirm_dialog.h" #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
...@@ -22,10 +23,10 @@ TabModalConfirmDialog* ...@@ -22,10 +23,10 @@ TabModalConfirmDialog*
XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent( XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
base::OnceCallback<void(bool)> response_callback) { base::OnceCallback<void(bool)> response_callback) {
auto* delegate = new XrSessionRequestConsentDialogDelegate( auto delegate = std::make_unique<XrSessionRequestConsentDialogDelegate>(
web_contents, std::move(response_callback)); web_contents, std::move(response_callback));
delegate->OnShowDialog(); delegate->OnShowDialog();
return TabModalConfirmDialog::Create(delegate, web_contents); return TabModalConfirmDialog::Create(std::move(delegate), web_contents);
} }
} // namespace vr } // namespace vr
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