Commit 8098fdb3 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Fix Ownership of SendTabToSelfBubbleDeviceButton

SendTabToSelfBubbleDeviceButton is owned by Views once added to the
Views tree.

BUG=985990

Change-Id: I641124d31eb69a17ce0764f50220dbb2f9b9287c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728442Reviewed-by: default avatarJeffrey Cohen <jeffreycohen@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682993}
parent fab4d519
...@@ -99,7 +99,7 @@ void SendTabToSelfBubbleViewImpl::Show(DisplayReason reason) { ...@@ -99,7 +99,7 @@ void SendTabToSelfBubbleViewImpl::Show(DisplayReason reason) {
ShowForReason(reason); ShowForReason(reason);
} }
const std::vector<std::unique_ptr<SendTabToSelfBubbleDeviceButton>>& const std::vector<SendTabToSelfBubbleDeviceButton*>&
SendTabToSelfBubbleViewImpl::GetDeviceButtonsForTest() { SendTabToSelfBubbleViewImpl::GetDeviceButtonsForTest() {
return device_buttons_; return device_buttons_;
} }
...@@ -128,7 +128,7 @@ void SendTabToSelfBubbleViewImpl::CreateScrollView() { ...@@ -128,7 +128,7 @@ void SendTabToSelfBubbleViewImpl::CreateScrollView() {
void SendTabToSelfBubbleViewImpl::PopulateScrollView( void SendTabToSelfBubbleViewImpl::PopulateScrollView(
const std::vector<TargetDeviceInfo>& devices) { const std::vector<TargetDeviceInfo>& devices) {
device_buttons_.clear(); DCHECK(device_buttons_.empty());
auto device_list_view = std::make_unique<views::View>(); auto device_list_view = std::make_unique<views::View>();
device_list_view->SetLayoutManager(std::make_unique<views::BoxLayout>( device_list_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical)); views::BoxLayout::Orientation::kVertical));
...@@ -137,8 +137,8 @@ void SendTabToSelfBubbleViewImpl::PopulateScrollView( ...@@ -137,8 +137,8 @@ void SendTabToSelfBubbleViewImpl::PopulateScrollView(
auto device_button = std::make_unique<SendTabToSelfBubbleDeviceButton>( auto device_button = std::make_unique<SendTabToSelfBubbleDeviceButton>(
this, device, this, device,
/** button_tag */ tag++); /** button_tag */ tag++);
device_buttons_.push_back(std::move(device_button)); device_buttons_.push_back(device_button.get());
device_list_view->AddChildView(device_buttons_.back().get()); device_list_view->AddChildView(std::move(device_button));
} }
scroll_view_->SetContents(std::move(device_list_view)); scroll_view_->SetContents(std::move(device_list_view));
...@@ -150,7 +150,10 @@ void SendTabToSelfBubbleViewImpl::DevicePressed(size_t index) { ...@@ -150,7 +150,10 @@ void SendTabToSelfBubbleViewImpl::DevicePressed(size_t index) {
if (!controller_) { if (!controller_) {
return; return;
} }
SendTabToSelfBubbleDeviceButton* device_button = device_buttons_[index].get();
DCHECK_LT(index, device_buttons_.size());
SendTabToSelfBubbleDeviceButton* device_button = device_buttons_[index];
controller_->OnDeviceSelected(device_button->device_name(), controller_->OnDeviceSelected(device_button->device_name(),
device_button->device_guid()); device_button->device_guid());
Hide(); Hide();
......
...@@ -68,7 +68,7 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView, ...@@ -68,7 +68,7 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView,
void Show(DisplayReason reason); void Show(DisplayReason reason);
// Called by tests. // Called by tests.
const std::vector<std::unique_ptr<SendTabToSelfBubbleDeviceButton>>& const std::vector<SendTabToSelfBubbleDeviceButton*>&
GetDeviceButtonsForTest(); GetDeviceButtonsForTest();
private: private:
...@@ -99,7 +99,7 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView, ...@@ -99,7 +99,7 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView,
base::string16 bubble_title_; base::string16 bubble_title_;
// Contains references to device buttons in the order they appear. // Contains references to device buttons in the order they appear.
std::vector<std::unique_ptr<SendTabToSelfBubbleDeviceButton>> device_buttons_; std::vector<SendTabToSelfBubbleDeviceButton*> device_buttons_;
// ScrollView containing the list of device buttons. // ScrollView containing the list of device buttons.
views::ScrollView* scroll_view_ = nullptr; views::ScrollView* scroll_view_ = nullptr;
......
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