Commit 44860a67 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

x11: Remove unneeded WeakPtr from XWindow

This is an attempt to fix or at least mitigate crash https://crbug.com/1021490.

A base::WeakPtr is used in to bind XWindow::DelayedResize task to
delayed_resize_task_, which is a CancelableCallback, which is not needed and
potentially make it harder to understand the aforementioned crash. So use
base::Unretained() instead of WeakPtr in that case.

Additionally, dcheck Close() is called before XWindow's dtor.

Bug: 1021490
Change-Id: Ibf8b2f185dc020258905f6bf5e26305c51e7a215
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1917079
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746917}
parent 9e8c4579
......@@ -143,7 +143,10 @@ XWindow::XWindow()
DCHECK_NE(x_root_window_, x11::None);
}
XWindow::~XWindow() = default;
XWindow::~XWindow() {
DCHECK_EQ(xwindow_, x11::None) << "XWindow destructed without calling "
"Close() to release allocated resources.";
}
void XWindow::Init(const Configuration& config) {
activatable_ = config.activatable;
......@@ -1367,9 +1370,8 @@ void XWindow::DispatchResize() {
// WM doesn't support _NET_WM_SYNC_REQUEST.
// Or we are too slow, so _NET_WM_SYNC_REQUEST is disabled by the
// compositor.
delayed_resize_task_.Reset(base::BindOnce(&XWindow::DelayedResize,
weak_factory_.GetWeakPtr(),
bounds_in_pixels_));
delayed_resize_task_.Reset(base::BindOnce(
&XWindow::DelayedResize, base::Unretained(this), bounds_in_pixels_));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, delayed_resize_task_.callback());
return;
......
......@@ -13,7 +13,6 @@
#include "base/component_export.h"
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "ui/gfx/geometry/insets.h"
......@@ -371,14 +370,12 @@ class COMPONENT_EXPORT(UI_BASE_X) XWindow {
bool pending_counter_value_is_extended_ = false;
bool configure_counter_value_is_extended_ = false;
base::CancelableOnceCallback<void()> delayed_resize_task_;
base::CancelableOnceClosure delayed_resize_task_;
// Keep track of barriers to confine cursor.
bool has_pointer_barriers_ = false;
std::array<XID, 4> pointer_barriers_;
base::WeakPtrFactory<XWindow> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(XWindow);
};
......
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