Move task running to UI thread for loadDartDefferredLibrary. (flutter/engine#35460)

This commit is contained in:
xiaomiao
2022-08-19 00:43:24 +08:00
committed by GitHub
parent 0aadd26fbf
commit d490b4edae
2 changed files with 39 additions and 17 deletions

View File

@@ -1371,15 +1371,29 @@ void Shell::LoadDartDeferredLibrary(
void Shell::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
engine_->LoadDartDeferredLibraryError(loading_unit_id, error_message,
transient);
fml::TaskRunner::RunNowOrPostTask(
task_runners_.GetUITaskRunner(),
[engine = weak_engine_, loading_unit_id, error_message, transient] {
if (engine) {
engine->LoadDartDeferredLibraryError(loading_unit_id, error_message,
transient);
}
});
}
void Shell::UpdateAssetResolverByType(
std::unique_ptr<AssetResolver> updated_asset_resolver,
AssetResolver::AssetResolverType type) {
engine_->GetAssetManager()->UpdateResolverByType(
std::move(updated_asset_resolver), type);
fml::TaskRunner::RunNowOrPostTask(
task_runners_.GetUITaskRunner(),
fml::MakeCopyable(
[engine = weak_engine_, type,
asset_resolver = std::move(updated_asset_resolver)]() mutable {
if (engine) {
engine->GetAssetManager()->UpdateResolverByType(
std::move(asset_resolver), type);
}
}));
}
// |Engine::Delegate|

View File

@@ -3339,9 +3339,9 @@ TEST_F(ShellTest, ImageGeneratorRegistryNotNullAfterParentShellDestroyed) {
TEST_F(ShellTest, UpdateAssetResolverByTypeReplaces) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform);
auto task_runner = thread_host.platform_thread->GetTaskRunner();
fml::MessageLoop::EnsureInitializedForCurrentThread();
auto task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
TaskRunners task_runners("test", task_runner, task_runner, task_runner,
task_runner);
auto shell = CreateShell(std::move(settings), task_runners);
@@ -3351,7 +3351,10 @@ TEST_F(ShellTest, UpdateAssetResolverByTypeReplaces) {
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("emptyMain");
auto asset_manager = configuration.GetAssetManager();
RunEngine(shell.get(), std::move(configuration));
shell->RunEngine(std::move(configuration), [&](auto result) {
ASSERT_EQ(result, Engine::RunStatus::Success);
});
auto platform_view =
std::make_unique<PlatformView>(*shell.get(), std::move(task_runners));
@@ -3381,9 +3384,9 @@ TEST_F(ShellTest, UpdateAssetResolverByTypeReplaces) {
TEST_F(ShellTest, UpdateAssetResolverByTypeAppends) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform);
auto task_runner = thread_host.platform_thread->GetTaskRunner();
fml::MessageLoop::EnsureInitializedForCurrentThread();
auto task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
TaskRunners task_runners("test", task_runner, task_runner, task_runner,
task_runner);
auto shell = CreateShell(std::move(settings), task_runners);
@@ -3393,7 +3396,10 @@ TEST_F(ShellTest, UpdateAssetResolverByTypeAppends) {
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("emptyMain");
auto asset_manager = configuration.GetAssetManager();
RunEngine(shell.get(), std::move(configuration));
shell->RunEngine(std::move(configuration), [&](auto result) {
ASSERT_EQ(result, Engine::RunStatus::Success);
});
auto platform_view =
std::make_unique<PlatformView>(*shell.get(), std::move(task_runners));
@@ -3456,10 +3462,9 @@ TEST_F(ShellTest, UpdateAssetResolverByTypeNull) {
TEST_F(ShellTest, UpdateAssetResolverByTypeDoesNotReplaceMismatchType) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host(ThreadHost::ThreadHostConfig(
"io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform));
auto task_runner = thread_host.platform_thread->GetTaskRunner();
fml::MessageLoop::EnsureInitializedForCurrentThread();
auto task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
TaskRunners task_runners("test", task_runner, task_runner, task_runner,
task_runner);
auto shell = CreateShell(std::move(settings), task_runners);
@@ -3469,7 +3474,10 @@ TEST_F(ShellTest, UpdateAssetResolverByTypeDoesNotReplaceMismatchType) {
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("emptyMain");
auto asset_manager = configuration.GetAssetManager();
RunEngine(shell.get(), std::move(configuration));
shell->RunEngine(std::move(configuration), [&](auto result) {
ASSERT_EQ(result, Engine::RunStatus::Success);
});
auto platform_view =
std::make_unique<PlatformView>(*shell.get(), std::move(task_runners));