From 42f5bc5fdff84ea20d603c765298e1773e2986c6 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 3 Aug 2017 10:53:17 -0700 Subject: [PATCH] Fixes related to usage of std::weak_ptr to hold PlatformViews (#3949) * Call weak_ptr.lock(), which returns a null shared_ptr and does not throw * IsViewInvalid was inverted --- shell/common/engine.cc | 4 ++-- shell/common/shell.cc | 6 +++--- shell/platform/android/platform_view_android.cc | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 4d4e08bf00..4d7631887b 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -485,7 +485,7 @@ void Engine::Render(std::unique_ptr layer_tree) { void Engine::UpdateSemantics(std::vector update) { blink::Threads::Platform()->PostTask(ftl::MakeCopyable( - [ platform_view = std::shared_ptr{platform_view_}, update = std::move(update) ]() mutable { + [ platform_view = platform_view_.lock(), update = std::move(update) ]() mutable { if (platform_view) platform_view->UpdateSemantics(std::move(update)); })); @@ -498,7 +498,7 @@ void Engine::HandlePlatformMessage( return; } blink::Threads::Platform()->PostTask([ - platform_view = std::shared_ptr{platform_view_}, message = std::move(message) + platform_view = platform_view_.lock(), message = std::move(message) ]() mutable { if (platform_view) platform_view->HandlePlatformMessage(std::move(message)); diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 5c791d45e6..90c1e569c6 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -34,7 +34,7 @@ bool IsInvalid(const ftl::WeakPtr& rasterizer) { } bool IsViewInvalid(const std::weak_ptr& platform_view) { - return !(platform_view.expired()); + return platform_view.expired(); } template @@ -266,7 +266,7 @@ void Shell::GetPlatformViewIds( std::vector* platform_view_ids) { std::lock_guard lk(platform_views_mutex_); for (auto it = platform_views_.begin(); it != platform_views_.end(); it++) { - std::shared_ptr view{*it}; + std::shared_ptr view = it->lock(); if (!view) { // Skip dead views. continue; @@ -317,7 +317,7 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id, *view_existed = false; for (auto it = platform_views_.begin(); it != platform_views_.end(); it++) { - std::shared_ptr view{*it}; + std::shared_ptr view = it->lock(); if (!view) continue; if (reinterpret_cast(view.get()) == view_id) { *view_existed = true; diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index f261dbb187..4debdd98f7 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -37,7 +37,7 @@ class PlatformMessageResponseAndroid : public blink::PlatformMessageResponse { ftl::RefPtr self(this); blink::Threads::Platform()->PostTask( ftl::MakeCopyable([ self, data = std::move(data) ]() mutable { - std::shared_ptr view{self->view_}; + std::shared_ptr view = self->view_.lock(); if (!view) return; static_cast(view.get()) @@ -49,7 +49,7 @@ class PlatformMessageResponseAndroid : public blink::PlatformMessageResponse { void CompleteEmpty() override { ftl::RefPtr self(this); blink::Threads::Platform()->PostTask(ftl::MakeCopyable([self]() mutable { - std::shared_ptr view{self->view_}; + std::shared_ptr view = self->view_.lock(); if (!view) return; static_cast(view.get()) -- GitLab