From acf5bd135ebd908ede649ab9da8ff92ea5460ad1 Mon Sep 17 00:00:00 2001 From: eggfly Date: Fri, 26 Nov 2021 00:34:56 +0800 Subject: [PATCH] Remove remaining usages of getUnsafe(). --- fml/memory/weak_ptr.h | 12 ------------ shell/common/shell.cc | 13 +++++-------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/fml/memory/weak_ptr.h b/fml/memory/weak_ptr.h index 2ff448ea36fa2..a78d8cc039389 100644 --- a/fml/memory/weak_ptr.h +++ b/fml/memory/weak_ptr.h @@ -91,18 +91,6 @@ class WeakPtr { return *this ? ptr_ : nullptr; } - // TODO(gw280): Remove all remaining usages of getUnsafe(). - // No new usages of getUnsafe() are allowed. - // - // https://github.com/flutter/flutter/issues/42949 - T* getUnsafe() const { - // This is an unsafe method to get access to the raw pointer. - // We still check the flag_ to determine if the pointer is valid - // but callees should note that this WeakPtr could have been - // invalidated on another thread. - return flag_ && flag_->is_valid() ? ptr_ : nullptr; - } - T& operator*() const { CheckThreadSafety(); FML_DCHECK(*this); diff --git a/shell/common/shell.cc b/shell/common/shell.cc index f7c91472facab..4252eb23fa4bb 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -224,24 +224,21 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( auto unref_queue_future = unref_queue_promise.get_future(); auto io_task_runner = shell->GetTaskRunners().GetIOTaskRunner(); - // TODO(gw280): The WeakPtr here asserts that we are derefing it on the - // same thread as it was created on. We are currently on the IO thread - // inside this lambda but we need to deref the PlatformView, which was - // constructed on the platform thread. - // - // https://github.com/flutter/flutter/issues/42948 + // The platform_view will be stored into shell's platform_view_ in + // shell->Setup(std::move(platform_view), ...) at the end. + PlatformView* platform_view_ptr = platform_view.get(); fml::TaskRunner::RunNowOrPostTask( io_task_runner, [&io_manager_promise, // &weak_io_manager_promise, // &unref_queue_promise, // - platform_view = platform_view->GetWeakPtr(), // + platform_view_ptr, // io_task_runner, // is_backgrounded_sync_switch = shell->GetIsGpuDisabledSyncSwitch() // ]() { TRACE_EVENT0("flutter", "ShellSetupIOSubsystem"); auto io_manager = std::make_unique( - platform_view.getUnsafe()->CreateResourceContext(), + platform_view_ptr->CreateResourceContext(), is_backgrounded_sync_switch, io_task_runner); weak_io_manager_promise.set_value(io_manager->GetWeakPtr()); unref_queue_promise.set_value(io_manager->GetSkiaUnrefQueue());