Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[engine] always force platform channel responses to schedule a task. #54975

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,10 @@ void Shell::OnPlatformViewDispatchPlatformMessage(

// The static leak checker gets confused by the use of fml::MakeCopyable.
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
fml::TaskRunner::RunNowOrPostTask(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this conditional on merged thread mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merged thread mode, RunNowOrPost task would always force a task to be posted because it was not possible for platform channel responses to come from the UI thread - only from plugins on the platform thread. In merged thread mode, RunNowOrPostTask is immediately invoking the closure without scheduling a task - which means the dart event loop isn't worken up.

So all I'm doing here is removing the conditional behavior for merged thread mode which is always incorrect.

task_runners_.GetUITaskRunner(),
fml::MakeCopyable([engine = engine_->GetWeakPtr(),
message = std::move(message)]() mutable {
// This logic must always explicitly post a task so that we are guaranteed
// to wake up the UI message loop to flush tasks.
task_runners_.GetUITaskRunner()->PostTask(fml::MakeCopyable(
[engine = engine_->GetWeakPtr(), message = std::move(message)]() mutable {
if (engine) {
engine->DispatchPlatformMessage(std::move(message));
}
Expand Down