Add split AOT loading unit failure/error code path (flutter/engine#22857)

This commit is contained in:
Gary Qian
2020-12-08 23:58:01 -07:00
committed by GitHub
parent 941581c96c
commit 19afd06afc
17 changed files with 202 additions and 8 deletions

View File

@@ -350,17 +350,17 @@ bool DartIsolate::LoadLoadingUnit(
loading_unit_id, dart_snapshot->GetDataMapping(),
dart_snapshot->GetInstructionsMapping());
if (tonic::LogIfError(result)) {
LoadLoadingUnitFailure(loading_unit_id, Dart_GetError(result),
/*transient*/ true);
LoadLoadingUnitError(loading_unit_id, Dart_GetError(result),
/*transient*/ true);
return false;
}
loading_unit_snapshots_.insert(dart_snapshot);
return true;
}
void DartIsolate::LoadLoadingUnitFailure(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
void DartIsolate::LoadLoadingUnitError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
tonic::DartState::Scope scope(this);
Dart_Handle result = Dart_DeferredLoadCompleteError(
loading_unit_id, error_message.c_str(), transient);

View File

@@ -390,9 +390,9 @@ class DartIsolate : public UIDartState {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions);
void LoadLoadingUnitFailure(intptr_t loading_unit_id,
const std::string error_message,
bool transient);
void LoadLoadingUnitError(intptr_t loading_unit_id,
const std::string error_message,
bool transient);
private:
friend class IsolateConfiguration;

View File

@@ -424,6 +424,14 @@ void RuntimeController::LoadDartDeferredLibrary(
std::move(snapshot_instructions));
}
void RuntimeController::LoadDartDeferredLibraryError(
intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message,
transient);
}
void RuntimeController::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
return client_.RequestDartDeferredLibrary(loading_unit_id);
}

View File

@@ -510,6 +510,32 @@ class RuntimeController : public PlatformConfigurationClient {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions);
//--------------------------------------------------------------------------
/// @brief Indicates to the dart VM that the request to load a deferred
/// library with the specified loading unit id has failed.
///
/// The dart future returned by the initiating loadLibrary() call
/// will complete with an error.
///
/// @param[in] loading_unit_id The unique id of the deferred library's
/// loading unit, as passed in by
/// RequestDartDeferredLibrary.
///
/// @param[in] error_message The error message that will appear in the
/// dart Future.
///
/// @param[in] transient A transient error is a failure due to
/// temporary conditions such as no network.
/// Transient errors allow the dart VM to
/// re-request the same deferred library and
/// and loading_unit_id again. Non-transient
/// errors are permanent and attempts to
/// re-request the library will instantly
/// complete with an error.
virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient);
// |PlatformConfigurationClient|
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;

View File

@@ -520,6 +520,18 @@ void Engine::LoadDartDeferredLibrary(
runtime_controller_->LoadDartDeferredLibrary(
loading_unit_id, std::move(snapshot_data),
std::move(snapshot_instructions));
} else {
LoadDartDeferredLibraryError(loading_unit_id, "No running root isolate.",
true);
}
}
void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
if (runtime_controller_->IsRootIsolateRunning()) {
runtime_controller_->LoadDartDeferredLibraryError(loading_unit_id,
error_message, transient);
}
}

View File

@@ -825,6 +825,32 @@ class Engine final : public RuntimeDelegate,
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions);
//--------------------------------------------------------------------------
/// @brief Indicates to the dart VM that the request to load a deferred
/// library with the specified loading unit id has failed.
///
/// The dart future returned by the initiating loadLibrary() call
/// will complete with an error.
///
/// @param[in] loading_unit_id The unique id of the deferred library's
/// loading unit, as passed in by
/// RequestDartDeferredLibrary.
///
/// @param[in] error_message The error message that will appear in the
/// dart Future.
///
/// @param[in] transient A transient error is a failure due to
/// temporary conditions such as no network.
/// Transient errors allow the dart VM to
/// re-request the same deferred library and
/// and loading_unit_id again. Non-transient
/// errors are permanent and attempts to
/// re-request the library will instantly
/// complete with an error.
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient);
private:
Engine::Delegate& delegate_;
const Settings settings_;

View File

@@ -65,6 +65,8 @@ class MockRuntimeController : public RuntimeController {
: RuntimeController(client, p_task_runners) {}
MOCK_METHOD0(IsRootIsolateRunning, bool());
MOCK_METHOD1(DispatchPlatformMessage, bool(fml::RefPtr<PlatformMessage>));
MOCK_METHOD3(LoadDartDeferredLibraryError,
void(intptr_t, const std::string, bool));
};
fml::RefPtr<PlatformMessage> MakePlatformMessage(
@@ -237,4 +239,30 @@ TEST_F(EngineTest, DispatchPlatformMessageInitialRouteIgnored) {
});
}
TEST_F(EngineTest, PassesLoadDartDeferredLibraryErrorToRuntime) {
PostUITaskSync([this] {
intptr_t error_id = 123;
const std::string error_message = "error message";
MockRuntimeDelegate client;
auto mock_runtime_controller =
std::make_unique<MockRuntimeController>(client, task_runners_);
EXPECT_CALL(*mock_runtime_controller, IsRootIsolateRunning())
.WillRepeatedly(::testing::Return(true));
EXPECT_CALL(*mock_runtime_controller,
LoadDartDeferredLibraryError(error_id, error_message, true))
.Times(1);
auto engine = std::make_unique<Engine>(
/*delegate=*/delegate_,
/*dispatcher_maker=*/dispatcher_maker_,
/*image_decoder_task_runner=*/image_decoder_task_runner_,
/*task_runners=*/task_runners_,
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*runtime_controller=*/std::move(mock_runtime_controller));
engine->LoadDartDeferredLibraryError(error_id, error_message, true);
});
}
} // namespace flutter

View File

@@ -166,6 +166,10 @@ void PlatformView::LoadDartDeferredLibrary(
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) {}
void PlatformView::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {}
void PlatformView::UpdateAssetManager(
std::shared_ptr<AssetManager> asset_manager) {}

View File

@@ -247,6 +247,32 @@ class PlatformView {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) = 0;
//--------------------------------------------------------------------------
/// @brief Indicates to the dart VM that the request to load a deferred
/// library with the specified loading unit id has failed.
///
/// The dart future returned by the initiating loadLibrary()
/// call will complete with an error.
///
/// @param[in] loading_unit_id The unique id of the deferred library's
/// loading unit, as passed in by
/// RequestDartDeferredLibrary.
///
/// @param[in] error_message The error message that will appear in the
/// dart Future.
///
/// @param[in] transient A transient error is a failure due to
/// temporary conditions such as no network.
/// Transient errors allow the dart VM to
/// re-request the same deferred library and
/// and loading_unit_id again. Non-transient
/// errors are permanent and attempts to
/// re-request the library will instantly
/// complete with an error.
virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) = 0;
// TODO(garyq): Implement a proper asset_resolver replacement instead of
// overwriting the entire asset manager.
//--------------------------------------------------------------------------
@@ -667,6 +693,33 @@ class PlatformView {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions);
//--------------------------------------------------------------------------
/// @brief Indicates to the dart VM that the request to load a deferred
/// library with the specified loading unit id has failed.
///
/// The dart future returned by the initiating loadLibrary() call
/// will complete with an error.
///
/// @param[in] loading_unit_id The unique id of the deferred library's
/// loading unit, as passed in by
/// RequestDartDeferredLibrary.
///
/// @param[in] error_message The error message that will appear in the
/// dart Future.
///
/// @param[in] transient A transient error is a failure due to
/// temporary conditions such as no network.
/// Transient errors allow the dart VM to
/// re-request the same deferred library and
/// and loading_unit_id again. Non-transient
/// errors are permanent and attempts to
/// re-request the library will instantly
/// complete with an error.
///
virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient);
// TODO(garyq): Implement a proper asset_resolver replacement instead of
// overwriting the entire asset manager.
//--------------------------------------------------------------------------

View File

@@ -1193,6 +1193,13 @@ void Shell::LoadDartDeferredLibrary(
std::move(snapshot_instructions));
}
void Shell::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
engine_->LoadDartDeferredLibraryError(loading_unit_id, error_message,
transient);
}
void Shell::UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) {
engine_->UpdateAssetManager(std::move(asset_manager));
}

View File

@@ -513,6 +513,10 @@ class Shell final : public PlatformView::Delegate,
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) override;
// |PlatformView::Delegate|
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;

View File

@@ -353,6 +353,15 @@ void PlatformViewAndroid::LoadDartDeferredLibrary(
std::move(snapshot_instructions));
}
// |PlatformView|
void PlatformViewAndroid::LoadDartDeferredLibraryError(
intptr_t loading_unit_id,
const std::string error_message,
bool transient) {
delegate_.LoadDartDeferredLibraryError(loading_unit_id, error_message,
transient);
}
// |PlatformView|
void PlatformViewAndroid::UpdateAssetManager(
std::shared_ptr<AssetManager> asset_manager) {

View File

@@ -99,6 +99,10 @@ class PlatformViewAndroid final : public PlatformView {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) override;
// |PlatformView|
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;

View File

@@ -38,6 +38,9 @@ class MockDelegate : public PlatformView::Delegate {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) override {
}
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) override {}
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override {}
};

View File

@@ -108,6 +108,9 @@ class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView::De
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) override {
}
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) override {}
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override {}
};

View File

@@ -91,6 +91,9 @@ class MockDelegate : public PlatformView::Delegate {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) override {
}
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) override {}
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override {}
};

View File

@@ -110,6 +110,10 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate {
std::unique_ptr<const fml::Mapping> snapshot_data,
std::unique_ptr<const fml::Mapping> snapshot_instructions) {}
// |flutter::PlatformView::Delegate|
void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
const std::string error_message,
bool transient) {}
// |flutter::PlatformView::Delegate|
void UpdateAssetManager(
std::shared_ptr<flutter::AssetManager> asset_manager) {}