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 @@
#include "chrome/browser/download/download_open_prompt.h"
#include <memory>
#include <utility>
#include "base/callback.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser_dialogs.h"
......@@ -102,10 +105,11 @@ DownloadOpenPrompt* DownloadOpenPrompt::CreateDownloadOpenConfirmationDialog(
const std::string& extension_name,
const base::FilePath& file_path,
DownloadOpenPrompt::OpenCallback open_callback) {
DownloadOpenConfirmationDialog* prompt = new DownloadOpenConfirmationDialog(
auto prompt = std::make_unique<DownloadOpenConfirmationDialog>(
web_contents, extension_name, file_path, std::move(open_callback));
TabModalConfirmDialog::Create(prompt, web_contents);
return prompt;
DownloadOpenConfirmationDialog* prompt_observer = prompt.get();
TabModalConfirmDialog::Create(std::move(prompt), web_contents);
return prompt_observer;
}
void DownloadOpenPrompt::AcceptConfirmationDialogForTesting(
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h"
#include <memory>
#include "base/callback.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
......@@ -93,7 +95,7 @@ void CreateDirectoryAccessConfirmationDialog(bool writable,
const base::Closure& on_accept,
const base::Closure& on_cancel) {
TabModalConfirmDialog::Create(
new DirectoryAccessConfirmationDialog(
std::make_unique<DirectoryAccessConfirmationDialog>(
writable, app_name, web_contents, on_accept, on_cancel),
web_contents);
}
......@@ -1551,8 +1551,8 @@ bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) {
}
void Browser::ShowRepostFormWarningDialog(WebContents* source) {
TabModalConfirmDialog::Create(new RepostFormWarningController(source),
source);
TabModalConfirmDialog::Create(
std::make_unique<RepostFormWarningController>(source), source);
}
bool Browser::ShouldCreateWebContents(
......
......@@ -66,9 +66,10 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
// Showing constrained window should disable find.
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
MockTabModalConfirmDialogDelegate* delegate =
new MockTabModalConfirmDialogDelegate(web_contents, NULL);
TabModalConfirmDialog::Create(delegate, web_contents);
auto delegate = std::make_unique<MockTabModalConfirmDialogDelegate>(
web_contents, nullptr);
MockTabModalConfirmDialogDelegate* delegate_ptr = delegate.get();
TabModalConfirmDialog::Create(std::move(delegate), web_contents);
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
// Switching to a new (unblocked) tab should reenable it.
......@@ -80,7 +81,7 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
// Closing the constrained window should reenable it.
delegate->Cancel();
delegate_ptr->Cancel();
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
}
......
......@@ -5,6 +5,8 @@
#ifndef 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 "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
......@@ -17,7 +19,8 @@ class TabModalConfirmDialog : public TabModalConfirmDialogCloseDelegate {
public:
// Platform specific factory function. This function will automatically show
// the dialog.
static TabModalConfirmDialog* Create(TabModalConfirmDialogDelegate* delegate,
static TabModalConfirmDialog* Create(
std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents);
// Accepts the dialog.
virtual void AcceptTabModalDialog() = 0;
......
......@@ -4,6 +4,9 @@
#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
......@@ -57,10 +60,12 @@ TabModalConfirmDialogTest::TabModalConfirmDialogTest()
closed_count_(0) {}
void TabModalConfirmDialogTest::SetUpOnMainThread() {
delegate_ = new MockTabModalConfirmDialogDelegate(
auto delegate = std::make_unique<MockTabModalConfirmDialogDelegate>(
browser()->tab_strip_model()->GetActiveWebContents(), this);
delegate_ = delegate.get();
dialog_ = TabModalConfirmDialog::Create(
delegate_, browser()->tab_strip_model()->GetActiveWebContents());
std::move(delegate),
browser()->tab_strip_model()->GetActiveWebContents());
content::RunAllPendingInMessageLoop();
}
......
......@@ -317,12 +317,14 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, GetAccessibleTabModalDialogTitle) {
window_title, base::CompareCase::SENSITIVE));
content::WebContents* contents = browser_view()->GetActiveWebContents();
TestTabModalConfirmDialogDelegate* delegate =
new TestTabModalConfirmDialogDelegate(contents);
TabModalConfirmDialog::Create(delegate, contents);
EXPECT_EQ(browser_view()->GetAccessibleWindowTitle(), delegate->GetTitle());
auto delegate = std::make_unique<TestTabModalConfirmDialogDelegate>(contents);
TestTabModalConfirmDialogDelegate* delegate_observer = delegate.get();
TabModalConfirmDialog::Create(std::move(delegate), contents);
EXPECT_EQ(browser_view()->GetAccessibleWindowTitle(),
delegate_observer->GetTitle());
delegate_observer->Close();
delegate->Close();
EXPECT_TRUE(base::StartsWith(browser_view()->GetAccessibleWindowTitle(),
window_title, base::CompareCase::SENSITIVE));
}
......@@ -349,9 +351,8 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, GetAccessibleTabModalDialogTree) {
nullptr);
content::WebContents* contents = browser_view()->GetActiveWebContents();
TestTabModalConfirmDialogDelegate* delegate =
new TestTabModalConfirmDialogDelegate(contents);
TabModalConfirmDialog::Create(delegate, contents);
auto delegate = std::make_unique<TestTabModalConfirmDialogDelegate>(contents);
TabModalConfirmDialog::Create(std::move(delegate), contents);
// 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.
......
......@@ -4,6 +4,9 @@
#include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h"
#include <memory>
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser_dialogs.h"
......@@ -21,25 +24,25 @@
// static
TabModalConfirmDialog* TabModalConfirmDialog::Create(
TabModalConfirmDialogDelegate* delegate,
std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents) {
return new TabModalConfirmDialogViews(delegate, web_contents);
return new TabModalConfirmDialogViews(std::move(delegate), web_contents);
}
//////////////////////////////////////////////////////////////////////////////
// TabModalConfirmDialogViews, constructor & destructor:
TabModalConfirmDialogViews::TabModalConfirmDialogViews(
TabModalConfirmDialogDelegate* delegate,
std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents)
: delegate_(delegate) {
views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage());
: delegate_(std::move(delegate)) {
views::MessageBoxView::InitParams init_params(delegate_->GetDialogMessage());
init_params.inter_row_vertical_spacing =
ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_UNRELATED_CONTROL_VERTICAL);
message_box_view_ = new views::MessageBoxView(init_params);
base::string16 link_text(delegate->GetLinkText());
base::string16 link_text(delegate_->GetLinkText());
if (!link_text.empty())
message_box_view_->SetLink(link_text, this);
......
......@@ -5,6 +5,8 @@
#ifndef 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/macros.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
......@@ -30,7 +32,8 @@ class TabModalConfirmDialogViews : public TabModalConfirmDialog,
public views::DialogDelegate,
public views::LinkListener {
public:
TabModalConfirmDialogViews(TabModalConfirmDialogDelegate* delegate,
TabModalConfirmDialogViews(
std::unique_ptr<TabModalConfirmDialogDelegate> delegate,
content::WebContents* web_contents);
// views::DialogDelegate:
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/vr/service/xr_session_request_consent_manager_impl.h"
#include <memory>
#include <utility>
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
......@@ -22,10 +23,10 @@ TabModalConfirmDialog*
XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent(
content::WebContents* web_contents,
base::OnceCallback<void(bool)> response_callback) {
auto* delegate = new XrSessionRequestConsentDialogDelegate(
auto delegate = std::make_unique<XrSessionRequestConsentDialogDelegate>(
web_contents, std::move(response_callback));
delegate->OnShowDialog();
return TabModalConfirmDialog::Create(delegate, web_contents);
return TabModalConfirmDialog::Create(std::move(delegate), web_contents);
}
} // 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