Commit 222b370e authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Reset item containers when holding space bubble is reset

Holding space item views depend on HoldingSpaceItemViewDelegate owned by
the HoldingSpaceTray. The delegate is reset with HoldingSpaceTrayBubble
when the bubble is closed, which happens before the bubble widget gets
torn down. Given that widget is destroyed asynchronously, there's a
short time interval where holding space item container views are still
around, but the delegate they depend on is destroyed - if a new item
gets added at this time, it would cause usage of deleted delegate.
(Found by tests added in CL:2493323).

To prevent this, remove container views from holding space controller
model and controller immediately when the HoldingSpaceTrayBubble gets
reset.

Change-Id: Icf5c523027ad352adff11ce9856a82bd93a7e4c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503628Reviewed-by: default avatarDavid Black <dmblack@google.com>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821361}
parent d943b2e6
...@@ -14,6 +14,12 @@ HoldingSpaceItemViewsContainer::HoldingSpaceItemViewsContainer() { ...@@ -14,6 +14,12 @@ HoldingSpaceItemViewsContainer::HoldingSpaceItemViewsContainer() {
HoldingSpaceItemViewsContainer::~HoldingSpaceItemViewsContainer() = default; HoldingSpaceItemViewsContainer::~HoldingSpaceItemViewsContainer() = default;
void HoldingSpaceItemViewsContainer::Reset() {
model_observer_.RemoveAll();
controller_observer_.RemoveAll();
RemoveAllHoldingSpaceItemViews();
}
void HoldingSpaceItemViewsContainer::ChildPreferredSizeChanged( void HoldingSpaceItemViewsContainer::ChildPreferredSizeChanged(
views::View* child) { views::View* child) {
PreferredSizeChanged(); PreferredSizeChanged();
......
...@@ -28,6 +28,14 @@ class HoldingSpaceItemViewsContainer : public views::View, ...@@ -28,6 +28,14 @@ class HoldingSpaceItemViewsContainer : public views::View,
const HoldingSpaceItemViewsContainer& other) = delete; const HoldingSpaceItemViewsContainer& other) = delete;
~HoldingSpaceItemViewsContainer() override; ~HoldingSpaceItemViewsContainer() override;
// Resets the container. Called when the tray bubble starts closing - holding
// space item views depend on the `HoldingSpaceItemViewDelegate` which is
// reset when the `HoldingSpaceTrayBubble` is reset.
// This removes all children that depend on the delegate, and stops observing
// holding space model to ensure no new items are created while the bubble
// widget is being closed (which happens asynchronously).
void Reset();
virtual void AddHoldingSpaceItemView(const HoldingSpaceItem* item) = 0; virtual void AddHoldingSpaceItemView(const HoldingSpaceItem* item) = 0;
virtual void RemoveAllHoldingSpaceItemViews() = 0; virtual void RemoveAllHoldingSpaceItemViews() = 0;
virtual void RemoveHoldingSpaceItemView(const HoldingSpaceItem* item) = 0; virtual void RemoveHoldingSpaceItemView(const HoldingSpaceItem* item) = 0;
......
...@@ -169,6 +169,11 @@ HoldingSpaceTrayBubble::HoldingSpaceTrayBubble( ...@@ -169,6 +169,11 @@ HoldingSpaceTrayBubble::HoldingSpaceTrayBubble(
HoldingSpaceTrayBubble::~HoldingSpaceTrayBubble() { HoldingSpaceTrayBubble::~HoldingSpaceTrayBubble() {
bubble_wrapper_->bubble_view()->ResetDelegate(); bubble_wrapper_->bubble_view()->ResetDelegate();
// Clear container state before `delegate_` is deleted, as container views
// depend on it.
pinned_files_container_->Reset();
recent_files_container_->Reset();
} }
void HoldingSpaceTrayBubble::AnchorUpdated() { void HoldingSpaceTrayBubble::AnchorUpdated() {
......
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