Skip to content

Commit

Permalink
Remove remaining usages of getUnsafe() (flutter#29941)
Browse files Browse the repository at this point in the history
  • Loading branch information
eggfly authored Nov 30, 2021
1 parent cc414f8 commit 2aaf6ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
12 changes: 0 additions & 12 deletions fml/memory/weak_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,21 @@ std::unique_ptr<Shell> 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<ShellIOManager>(
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());
Expand Down

0 comments on commit 2aaf6ec

Please sign in to comment.