Commit 136c305d authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Add unique_ptr version of BDDV::CreateBubble()

Allows calling BubbleDialogDelegateView::CreateBubble with unique_ptrs
instead of calling unique_ptr.release().

Some call sites could fairly-trivially be converted to use unique_ptr. I
only went through those that were really trivial (most of them contained
.release() so they were trivially converted to std::move).

Bug: None
Change-Id: I3a13f4dd38e26fc150a58fe824750e722a3f4d1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373269
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801520}
parent 4f9423ac
......@@ -170,6 +170,7 @@ void MaybeShowInvertBubbleView(BrowserView* browser_view) {
}
void ShowInvertBubbleView(Browser* browser, views::View* anchor) {
InvertBubbleView* delegate = new InvertBubbleView(browser, anchor);
views::BubbleDialogDelegateView::CreateBubble(delegate)->Show();
views::BubbleDialogDelegateView::CreateBubble(
std::make_unique<InvertBubbleView>(browser, anchor))
->Show();
}
......@@ -244,7 +244,7 @@ void BookmarkBubbleView::ShowBubble(
#endif
views::Widget* const widget =
views::BubbleDialogDelegateView::CreateBubble(bubble.release());
views::BubbleDialogDelegateView::CreateBubble(std::move(bubble));
widget->Show();
chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK);
......
......@@ -62,7 +62,6 @@ TEST_F(ContentSettingBubbleContentsTest, NullDeref) {
std::unique_ptr<views::Widget> widget(
views::BubbleDialogDelegateView::CreateBubble(
std::make_unique<TestContentSettingBubbleContents>(
web_contents.get(), parent_widget->GetNativeView())
.release()));
web_contents.get(), parent_widget->GetNativeView())));
widget->Show();
}
......@@ -154,7 +154,7 @@ void ExtensionInstalledBubbleView::Show(
std::make_unique<ExtensionInstalledBubbleView>(browser, std::move(model));
auto* weak_delegate = delegate.get();
views::Widget* const widget =
views::BubbleDialogDelegateView::CreateBubble(delegate.release());
views::BubbleDialogDelegateView::CreateBubble(std::move(delegate));
// When the extension is installed to the ExtensionsToolbarContainer, use the
// container to pop out the extension icon and show the widget. Otherwise show
// the widget directly.
......
......@@ -349,7 +349,7 @@ void ExtensionsToolbarContainer::ShowToolbarActionBubble(
views::View* const anchor_view = GetViewForId(extension_id);
views::Widget* const widget = views::BubbleDialogDelegateView::CreateBubble(
new ToolbarActionsBarBubbleViews(
std::make_unique<ToolbarActionsBarBubbleViews>(
anchor_view ? anchor_view : extensions_button_,
anchor_view != nullptr, std::move(controller)));
......
......@@ -106,7 +106,7 @@ void ShowRemoveSuggestion(TemplateURLService* template_url_service,
const AutocompleteMatch& match,
base::OnceClosure remove_closure) {
views::BubbleDialogDelegateView::CreateBubble(
new RemoveSuggestionBubbleDialogDelegateView(
std::make_unique<RemoveSuggestionBubbleDialogDelegateView>(
template_url_service, anchor_view, match, std::move(remove_closure)))
->Show();
}
......@@ -161,7 +161,7 @@ void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
std::make_unique<views::BubbleDialogModelHost>(std::move(dialog_model));
bubble->SetAnchorView(anchor_view);
bubble->SetArrow(views::BubbleBorder::TOP_RIGHT);
views::BubbleDialogDelegateView::CreateBubble(bubble.release())->Show();
views::BubbleDialogDelegateView::CreateBubble(std::move(bubble))->Show();
chrome::RecordDialogCreation(chrome::DialogIdentifier::OUTDATED_UPGRADE);
......
......@@ -197,7 +197,7 @@ base::OnceClosure ShowDeviceChooserDialog(
base::OnceClosure close_closure = bubble->MakeCloseClosure();
views::Widget* widget =
views::BubbleDialogDelegateView::CreateBubble(bubble.release());
views::BubbleDialogDelegateView::CreateBubble(std::move(bubble));
if (browser->window()->IsActive())
widget->Show();
else
......
......@@ -86,9 +86,8 @@ class TabSearchWebView : public views::WebView {
views::Widget* TabSearchBubbleView::CreateTabSearchBubble(
content::BrowserContext* browser_context,
views::View* anchor_view) {
auto delegate =
std::make_unique<TabSearchBubbleView>(browser_context, anchor_view);
return BubbleDialogDelegateView::CreateBubble(delegate.release());
return BubbleDialogDelegateView::CreateBubble(
std::make_unique<TabSearchBubbleView>(browser_context, anchor_view));
}
TabSearchBubbleView::TabSearchBubbleView(
......
......@@ -333,6 +333,10 @@ Widget* BubbleDialogDelegate::CreateBubble(
return bubble_widget;
}
Widget* BubbleDialogDelegateView::CreateBubble(
std::unique_ptr<BubbleDialogDelegateView> delegate) {
return CreateBubble(delegate.release());
}
Widget* BubbleDialogDelegateView::CreateBubble(BubbleDialogDelegateView* view) {
return BubbleDialogDelegate::CreateBubble(view);
}
......
......@@ -370,6 +370,8 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public BubbleDialogDelegate,
METADATA_HEADER(BubbleDialogDelegateView);
// Create and initialize the bubble Widget(s) with proper bounds.
static Widget* CreateBubble(
std::unique_ptr<BubbleDialogDelegateView> delegate);
static Widget* CreateBubble(BubbleDialogDelegateView* bubble_delegate);
BubbleDialogDelegateView();
......
......@@ -634,7 +634,7 @@ TEST_F(BubbleDialogDelegateClientLayerTest, WithClientLayerTest) {
bubble_delegate->set_parent_window(anchor_widget->GetNativeView());
WidgetAutoclosePtr bubble_widget(
BubbleDialogDelegateView::CreateBubble(bubble_delegate.release()));
BubbleDialogDelegateView::CreateBubble(std::move(bubble_delegate)));
EXPECT_NE(nullptr, bubble_widget->client_view()->layer());
}
......@@ -648,7 +648,7 @@ TEST_F(BubbleDialogDelegateClientLayerTest, WithoutClientLayerTest) {
bubble_delegate->set_parent_window(anchor_widget->GetNativeView());
WidgetAutoclosePtr bubble_widget(
BubbleDialogDelegateView::CreateBubble(bubble_delegate.release()));
BubbleDialogDelegateView::CreateBubble(std::move(bubble_delegate)));
EXPECT_EQ(nullptr, bubble_widget->client_view()->layer());
}
......
......@@ -362,7 +362,7 @@ TEST_F(DesktopWidgetTestInteractive, FocusChangesOnBubble) {
owned_bubble_delegate_view->SetFocusBehavior(View::FocusBehavior::ALWAYS);
BubbleDialogDelegateView* bubble_delegate_view =
owned_bubble_delegate_view.get();
BubbleDialogDelegateView::CreateBubble(owned_bubble_delegate_view.release())
BubbleDialogDelegateView::CreateBubble(std::move(owned_bubble_delegate_view))
->Show();
bubble_delegate_view->RequestFocus();
......
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