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

Commit 1a51a4b

Browse files
committed
Refactor and rename methods
Rename to LoadDartDeferredLibrary Additional renaming Add back moduleName to params Documentation Pass asset manager to persistent cache Fix license, cleanup, fix docs, rename methods Javadocs, API adjustments More docs, rename log tag
1 parent 0c490e1 commit 1a51a4b

20 files changed

+293
-224
lines changed

shell/common/engine.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,16 @@ const std::string& Engine::GetLastEntrypointLibrary() const {
511511
// feature. Left commented out until it lands:
512512

513513
// // |RuntimeDelegate|
514-
// void Engine::OnDartLoadLibrary(intptr_t loading_unit_id) {
515-
// return delegate_.OnDartLoadLibrary(loading_unit_id);
514+
// void Engine::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
515+
// return delegate_.RequestDartDeferredLibrary(loading_unit_id);
516516
// }
517517

518-
void Engine::CompleteDartLoadLibrary(intptr_t loading_unit_id,
519-
const uint8_t* snapshot_data,
520-
const uint8_t* snapshot_instructions) {
518+
void Engine::CompleteDartDeferredLibraryLoading(
519+
intptr_t loading_unit_id,
520+
const uint8_t* snapshot_data,
521+
const uint8_t* snapshot_instructions) {
521522
if (runtime_controller_->IsRootIsolateRunning()) {
522-
// runtime_controller_->CompleteDartLoadLibrary(loading_unit_id,
523+
// runtime_controller_->CompleteDartDeferredLibraryLoading(loading_unit_id,
523524
// snapshot_data, snapshot_instructions);
524525
}
525526
}

shell/common/engine.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Engine final : public RuntimeDelegate,
270270
/// @param[in] loading_unit_id The unique id of the deferred library's
271271
/// loading unit.
272272
///
273-
virtual void OnDartLoadLibrary(intptr_t loading_unit_id) = 0;
273+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id) = 0;
274274
};
275275

276276
//----------------------------------------------------------------------------
@@ -795,9 +795,9 @@ class Engine final : public RuntimeDelegate,
795795
/// @param[in] snapshot_data Dart snapshot instructions of the loading
796796
/// unit's shared library.
797797
///
798-
void CompleteDartLoadLibrary(intptr_t loading_unit_id,
799-
const uint8_t* snapshot_data,
800-
const uint8_t* snapshot_instructions);
798+
void CompleteDartDeferredLibraryLoading(intptr_t loading_unit_id,
799+
const uint8_t* snapshot_data,
800+
const uint8_t* snapshot_instructions);
801801

802802
private:
803803
Engine::Delegate& delegate_;
@@ -851,7 +851,7 @@ class Engine final : public RuntimeDelegate,
851851
// feature. Left commented out until it lands:
852852

853853
// // |RuntimeDelegate|
854-
// void OnDartLoadLibrary(intptr_t loading_unit_id) override;
854+
// void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
855855

856856
void SetNeedsReportTimings(bool value) override;
857857

shell/common/engine_unittests.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "rapidjson/document.h"
1414
#include "rapidjson/stringbuffer.h"
1515
#include "rapidjson/writer.h"
16-
#include "third_party/dart/runtime/include/dart_api.h"
1716

1817
///\note Deprecated MOCK_METHOD macros used until this issue is resolved:
1918
// https://github.com/google/googletest/issues/2490
@@ -33,7 +32,7 @@ class MockDelegate : public Engine::Delegate {
3332
MOCK_METHOD1(ComputePlatformResolvedLocale,
3433
std::unique_ptr<std::vector<std::string>>(
3534
const std::vector<std::string>&));
36-
MOCK_METHOD1(OnDartLoadLibrary, Dart_Handle(intptr_t));
35+
MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
3736
};
3837

3938
class MockResponse : public PlatformMessageResponse {
@@ -57,7 +56,7 @@ class MockRuntimeDelegate : public RuntimeDelegate {
5756
MOCK_METHOD1(ComputePlatformResolvedLocale,
5857
std::unique_ptr<std::vector<std::string>>(
5958
const std::vector<std::string>&));
60-
MOCK_METHOD1(OnDartLoadLibrary, Dart_Handle(intptr_t));
59+
MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
6160
};
6261

6362
class MockRuntimeController : public RuntimeController {

shell/common/platform_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ PlatformView::ComputePlatformResolvedLocales(
159159
return out;
160160
}
161161

162-
void PlatformView::OnDartLoadLibrary(intptr_t loading_unit_id) {}
162+
void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
163163

164-
void PlatformView::CompleteDartLoadLibrary(
164+
void PlatformView::CompleteDartDeferredLibraryLoading(
165165
intptr_t loading_unit_id,
166166
const uint8_t* snapshot_data,
167167
const uint8_t* snapshot_instructions) {}

shell/common/platform_view.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,6 @@ class PlatformView {
211211
virtual void OnPlatformViewMarkTextureFrameAvailable(
212212
int64_t texture_id) = 0;
213213

214-
//--------------------------------------------------------------------------
215-
/// @brief Invoked when the dart VM requests that a deferred library
216-
/// be loaded. Notifies the engine that the requested loading
217-
/// unit should be downloaded and loaded.
218-
///
219-
/// @param[in] loading_unit_id The unique id of the deferred library's
220-
/// loading unit.
221-
///
222-
virtual void OnPlatformViewDartLoadLibrary(intptr_t loading_unit_id) = 0;
223-
224214
//--------------------------------------------------------------------------
225215
/// @brief Loads the dart shared library into the dart VM. When the
226216
/// dart library is loaded successfully, the dart future
@@ -238,7 +228,7 @@ class PlatformView {
238228
/// @param[in] snapshot_data Dart snapshot instructions of the loading
239229
/// unit's shared library.
240230
///
241-
virtual void CompleteDartLoadLibrary(
231+
virtual void CompleteDartDeferredLibraryLoading(
242232
intptr_t loading_unit_id,
243233
const uint8_t* snapshot_data,
244234
const uint8_t* snapshot_instructions) = 0;
@@ -611,7 +601,7 @@ class PlatformView {
611601
/// @param[in] loading_unit_id The unique id of the deferred library's
612602
/// loading unit.
613603
///
614-
virtual void OnDartLoadLibrary(intptr_t loading_unit_id);
604+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id);
615605

616606
//--------------------------------------------------------------------------
617607
/// @brief Loads the dart shared library into the dart VM. When the
@@ -630,9 +620,10 @@ class PlatformView {
630620
/// @param[in] snapshot_data Dart snapshot instructions of the loading
631621
/// unit's shared library.
632622
///
633-
virtual void CompleteDartLoadLibrary(intptr_t loading_unit_id,
634-
const uint8_t* snapshot_data,
635-
const uint8_t* snapshot_instructions);
623+
virtual void CompleteDartDeferredLibraryLoading(
624+
intptr_t loading_unit_id,
625+
const uint8_t* snapshot_data,
626+
const uint8_t* snapshot_instructions);
636627

637628
//--------------------------------------------------------------------------
638629
/// @brief Sets the asset manager of the engine to asset_manager

shell/common/shell.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,25 +1181,21 @@ std::unique_ptr<std::vector<std::string>> Shell::ComputePlatformResolvedLocale(
11811181
return platform_view_->ComputePlatformResolvedLocales(supported_locale_data);
11821182
}
11831183

1184-
void Shell::CompleteDartLoadLibrary(intptr_t loading_unit_id,
1185-
const uint8_t* snapshot_data,
1186-
const uint8_t* snapshot_instructions) {
1187-
engine_->CompleteDartLoadLibrary(loading_unit_id, snapshot_data,
1188-
snapshot_instructions);
1184+
void Shell::CompleteDartDeferredLibraryLoading(
1185+
intptr_t loading_unit_id,
1186+
const uint8_t* snapshot_data,
1187+
const uint8_t* snapshot_instructions) {
1188+
engine_->CompleteDartDeferredLibraryLoading(loading_unit_id, snapshot_data,
1189+
snapshot_instructions);
11891190
}
11901191

11911192
void Shell::UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) {
11921193
engine_->UpdateAssetManager(std::move(asset_manager));
11931194
}
11941195

11951196
// |Engine::Delegate|
1196-
void Shell::OnDartLoadLibrary(intptr_t loading_unit_id) {
1197-
OnPlatformViewDartLoadLibrary(loading_unit_id);
1198-
}
1199-
1200-
// |PlatformView::Delegate|
1201-
void Shell::OnPlatformViewDartLoadLibrary(intptr_t loading_unit_id) {
1202-
platform_view_->OnDartLoadLibrary(loading_unit_id);
1197+
void Shell::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
1198+
platform_view_->RequestDartDeferredLibrary(loading_unit_id);
12031199
}
12041200

12051201
void Shell::ReportTimings() {

shell/common/shell.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,10 @@ class Shell final : public PlatformView::Delegate,
509509
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override;
510510

511511
// |PlatformView::Delegate|
512-
void OnPlatformViewDartLoadLibrary(intptr_t loading_unit_id) override;
513-
514-
// |PlatformView::Delegate|
515-
void CompleteDartLoadLibrary(intptr_t loading_unit_id,
516-
const uint8_t* snapshot_data,
517-
const uint8_t* snapshot_instructions) override;
512+
void CompleteDartDeferredLibraryLoading(
513+
intptr_t loading_unit_id,
514+
const uint8_t* snapshot_data,
515+
const uint8_t* snapshot_instructions) override;
518516

519517
// |PlatformView::Delegate|
520518
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;
@@ -561,7 +559,7 @@ class Shell final : public PlatformView::Delegate,
561559
const std::vector<std::string>& supported_locale_data) override;
562560

563561
// |Engine::Delegate|
564-
void OnDartLoadLibrary(intptr_t loading_unit_id) override;
562+
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
565563

566564
// |Rasterizer::Delegate|
567565
void OnFrameRasterized(const FrameTiming&) override;

shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ public FlutterEngine(
306306

307307
dynamicFeatureManager = new PlayStoreDynamicFeatureManager(context, flutterJNI);
308308
flutterJNI.setDynamicFeatureManager(dynamicFeatureManager);
309-
flutterJNI.setDynamicFeatureContext(context);
310309

311310
attachToJni();
312311

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -951,69 +951,63 @@ public void setDynamicFeatureManager(@NonNull DynamicFeatureManager dynamicFeatu
951951
this.dynamicFeatureManager = dynamicFeatureManager;
952952
}
953953

954-
private Context dynamicFeatureContext;
955-
956-
@UiThread
957-
public void setDynamicFeatureContext(@NonNull Context context) {
958-
ensureRunningOnMainThread();
959-
this.dynamicFeatureContext = context;
960-
}
961-
962-
@SuppressWarnings("unused")
963-
@UiThread
964-
public void downloadDynamicFeature(int loadingUnitId) {
965-
int moduleNameIdentifier =
966-
dynamicFeatureContext
967-
.getResources()
968-
.getIdentifier(
969-
"loadingUnit" + loadingUnitId, "string", dynamicFeatureContext.getPackageName());
970-
String moduleName = dynamicFeatureContext.getResources().getString(moduleNameIdentifier);
971-
downloadDynamicFeature(moduleName, loadingUnitId);
972-
}
973-
974-
// Called by the engine upon invocation of dart loadLibrary() request
954+
/**
955+
* Called by dart's deferred load handler to request that a dart deferred library corresponding
956+
* to loadingUnitId be downloaded (if necessary) and loaded into the dart vm.
957+
*
958+
* <p>This method delegates the task to DynamicFeatureManager, which handles the download and
959+
* loading of the dart library and any assets.
960+
*
961+
* @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
962+
* automatically retrieved when loadLibrary() is called on a dart deferred
963+
* library.
964+
*/
975965
@SuppressWarnings("unused")
976966
@UiThread
977-
public void downloadDynamicFeature(String moduleName, int loadingUnitId) {
978-
dynamicFeatureManager.downloadFeature(moduleName, loadingUnitId);
967+
public void RequestDartDeferredLibrary(int loadingUnitId) {
968+
dynamicFeatureManager.downloadDynamicFeature(loadingUnitId, null);
979969
}
980970

981971
/**
982-
* This should be called for every loading unit to be loaded into the dart isolate.
983-
*
984-
* <p>abi, libName, and apkPaths are used together to search the installed apks for the desired
985-
* .so library. If not found, soPath may be provided as a fallback if a pre-extracted .so exists,
986-
* especially on older devices with libs compressed in the apk.
972+
* Searches each of the provided paths for a valid dart shared library .so file and resolves
973+
* symbols to load into the dart VM.
987974
*
988-
* <p>Successful loading of the dart library also completes the loadLibrary() future that
975+
* <p>Successful loading of the dart library completes the future returned by loadLibrary() that
989976
* triggered the install/load process.
977+
*
978+
* @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
979+
* automatically retrieved when loadLibrary() is called on a dart deferred
980+
* library. This is used to identify which dart deferred library the resolved
981+
* correspond to.
982+
*
983+
* @param searchPaths An array of paths in which to look for valid dart shared libraries. This
984+
* supports paths within zipped apks as long as the apks are not compressed
985+
* using the `path/to/apk.apk!path/inside/apk/lib.so` format. Paths will be
986+
* tried first to last and ends when a library is sucessfully found. When the
987+
* found library is invalid, no additional paths will be attempted.
990988
*/
991989
@UiThread
992-
public void loadDartLibrary(
990+
public void loadDartDeferredLibrary(
993991
int loadingUnitId,
994-
@NonNull String libName,
995-
@NonNull String[] apkPaths,
996-
@NonNull String abi,
997-
@NonNull String soPath) {
992+
@NonNull String[] searchPaths) {
998993
ensureRunningOnMainThread();
999994
ensureAttachedToNative();
1000-
nativeLoadDartLibrary(nativePlatformViewId, loadingUnitId, libName, apkPaths, abi, soPath);
995+
nativeLoadDartDeferredLibrary(nativePlatformViewId, loadingUnitId, searchPaths);
1001996
}
1002997

1003-
private native void nativeLoadDartLibrary(
998+
private native void nativeLoadDartDeferredLibrary(
1004999
long nativePlatformViewId,
10051000
int loadingUnitId,
1006-
@NonNull String libName,
1007-
@NonNull String[] apkPaths,
1008-
@NonNull String abi,
1009-
@NonNull String soPath);
1001+
@NonNull String[] searchPaths);
10101002

10111003
/**
10121004
* Specifies a new AssetManager that has access to the dynamic feature's assets in addition to the
10131005
* base module's assets.
10141006
*
1015-
* <p>assetBundlePath is the subdirectory that the flutter assets are stored in. The typical value
1016-
* is `flutter_assets`.
1007+
* @param assetManager An android AssetManager that is able to access the newly downloaded assets.
1008+
*
1009+
* @param assetBundlePath The subdirectory that the flutter assets are stored in. The typical value
1010+
* is `flutter_assets`.
10171011
*/
10181012
@UiThread
10191013
public void updateAssetManager(
@@ -1028,19 +1022,34 @@ private native void nativeUpdateAssetManager(
10281022
@NonNull AssetManager assetManager,
10291023
@NonNull String assetBundlePath);
10301024

1031-
// Called when an install encounters a failure during the Android portion of installing a module.
1032-
// When transient is false, new attempts to install will automatically result in same error in
1033-
// dart before the request is passed to Android.
1025+
/**
1026+
* Indicates that a failure was encountered during the Android portion of downloading a dynamic
1027+
* feature module and loading a dart deferred library, which is typically done by
1028+
* DynamicFeatureManager.
1029+
*
1030+
* <p>This will inform dart that the future returned by loadLibrary() should complete with an error.
1031+
*
1032+
* @param loadingUnitId The loadingUnitId that corresponds to the dart deferred library that
1033+
* failed to install.
1034+
*
1035+
* @param moduleName The name of the module that includes the loadingUnitId. This parameter is
1036+
* not necessary and used for logging purposes.
1037+
*
1038+
* @param error The error message to display.
1039+
*
1040+
* @param isTransient When isTransient is false, new attempts to install will automatically result in
1041+
* same error in dart before the request is passed to Android.
1042+
*/
10341043
@SuppressWarnings("unused")
10351044
@UiThread
10361045
public void dynamicFeatureInstallFailure(
1037-
@NonNull String moduleName, int loadingUnitId, @NonNull String error, boolean trans) {
1046+
int loadingUnitId, String moduleName, @NonNull String error, boolean isTransient) {
10381047
ensureRunningOnMainThread();
1039-
nativeDynamicFeatureInstallFailure(moduleName, loadingUnitId, error, trans);
1048+
nativeDynamicFeatureInstallFailure(loadingUnitId, moduleName, error, isTransient);
10401049
}
10411050

10421051
private native void nativeDynamicFeatureInstallFailure(
1043-
@NonNull String moduleName, int loadingUnitId, @NonNull String error, boolean trans);
1052+
int loadingUnitId, String moduleName, @NonNull String error, boolean isTransient);
10441053

10451054
// ----- End Dynamic Features Support ----
10461055

0 commit comments

Comments
 (0)