Commit 7415ecf5 authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Fix OzonePlatformScenic handling of MessageLoop destruction.

Tear down all sub-components of the OzonePlatformScenic implementation
on MessageLoop destruction, to prevent components which set FIDL error-
handlers from observing ZX_ERR_CANCELED events.

MessagePumpFuchsia is also updated to print out the base::Location at
which the {ZxHandle|Fd}WatchController was created, to help in
diagnosing issues with failing asynchronous watch operations.

Bug: 927400
Change-Id: I91ad15b5a5f83c9e45b602a0647745813c55aef9
Reviewed-on: https://chromium-review.googlesource.com/c/1490953Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636197}
parent 2271635b
...@@ -34,7 +34,8 @@ bool MessagePumpFuchsia::ZxHandleWatchController::WaitBegin() { ...@@ -34,7 +34,8 @@ bool MessagePumpFuchsia::ZxHandleWatchController::WaitBegin() {
zx_status_t status = zx_status_t status =
async_begin_wait(weak_pump_->async_loop_->dispatcher(), this); async_begin_wait(weak_pump_->async_loop_->dispatcher(), this);
if (status != ZX_OK) { if (status != ZX_OK) {
ZX_DLOG(ERROR, status) << "async_begin_wait() failed"; ZX_DLOG(ERROR, status) << "async_begin_wait():"
<< created_from_location_.ToString();
async_wait_t::handler = nullptr; async_wait_t::handler = nullptr;
return false; return false;
} }
...@@ -66,7 +67,8 @@ bool MessagePumpFuchsia::ZxHandleWatchController::StopWatchingZxHandle() { ...@@ -66,7 +67,8 @@ bool MessagePumpFuchsia::ZxHandleWatchController::StopWatchingZxHandle() {
zx_status_t result = zx_status_t result =
async_cancel_wait(weak_pump_->async_loop_->dispatcher(), this); async_cancel_wait(weak_pump_->async_loop_->dispatcher(), this);
ZX_DLOG_IF(ERROR, result != ZX_OK, result) << "async_cancel_wait failed"; ZX_DLOG_IF(ERROR, result != ZX_OK, result)
<< "async_cancel_wait(): " << created_from_location_.ToString();
return result == ZX_OK; return result == ZX_OK;
} }
...@@ -78,14 +80,16 @@ void MessagePumpFuchsia::ZxHandleWatchController::HandleSignal( ...@@ -78,14 +80,16 @@ void MessagePumpFuchsia::ZxHandleWatchController::HandleSignal(
const zx_packet_signal_t* signal) { const zx_packet_signal_t* signal) {
TRACE_EVENT0("toplevel", "ZxHandleSignal"); TRACE_EVENT0("toplevel", "ZxHandleSignal");
ZxHandleWatchController* controller =
static_cast<ZxHandleWatchController*>(wait);
DCHECK_EQ(controller->handler, &HandleSignal);
if (status != ZX_OK) { if (status != ZX_OK) {
ZX_LOG(WARNING, status) << "async wait failed"; ZX_DLOG(WARNING, status) << "async wait failed: "
<< controller->created_from_location_.ToString();
return; return;
} }
ZxHandleWatchController* controller =
static_cast<ZxHandleWatchController*>(wait);
DCHECK_EQ(controller->handler, &HandleSignal);
controller->handler = nullptr; controller->handler = nullptr;
// |signal| can include other spurious things, in particular, that an fd // |signal| can include other spurious things, in particular, that an fd
...@@ -150,7 +154,8 @@ bool MessagePumpFuchsia::FdWatchController::WaitBegin() { ...@@ -150,7 +154,8 @@ bool MessagePumpFuchsia::FdWatchController::WaitBegin() {
// their current state, so we must do this every time we begin to wait. // their current state, so we must do this every time we begin to wait.
fdio_unsafe_wait_begin(io_, desired_events_, &object, &trigger); fdio_unsafe_wait_begin(io_, desired_events_, &object, &trigger);
if (async_wait_t::object == ZX_HANDLE_INVALID) { if (async_wait_t::object == ZX_HANDLE_INVALID) {
DLOG(ERROR) << "fdio_wait_begin failed"; DLOG(ERROR) << "fdio_wait_begin failed: "
<< ZxHandleWatchController::created_from_location_.ToString();
return false; return false;
} }
......
...@@ -154,11 +154,19 @@ class OzonePlatformScenic ...@@ -154,11 +154,19 @@ class OzonePlatformScenic
} }
private: private:
// Performs graceful cleanup tasks on main message loop teardown.
void Shutdown() { window_manager_.reset(); }
// base::MessageLoopCurrent::DestructionObserver implementation. // base::MessageLoopCurrent::DestructionObserver implementation.
void WillDestroyCurrentMessageLoop() override { Shutdown(); } void WillDestroyCurrentMessageLoop() override {
// We must ensure to destroy any resources which rely on the MessageLoop's
// async_dispatcher.
scenic_gpu_host_ptr_ = nullptr;
surface_factory_ = nullptr;
scenic_gpu_host_ = nullptr;
overlay_manager_ = nullptr;
input_controller_ = nullptr;
cursor_factory_ozone_ = nullptr;
platform_event_source_ = nullptr;
window_manager_ = nullptr;
}
std::unique_ptr<ScenicWindowManager> window_manager_; std::unique_ptr<ScenicWindowManager> window_manager_;
......
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