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

Conversation

GaryQian
Copy link
Contributor

@GaryQian GaryQian commented Dec 17, 2020

Loosely based off of #21611

Adds IsUpdatable to AssetResolvers. Updatable resolvers may be replaced with newer versions with UpdateAssetResolvers.

@google-cla google-cla bot added the cla: yes label Dec 17, 2020
@GaryQian GaryQian changed the title [WIP] Add IsUpdatable to AssetResolver for Dynamic feature APKAssetResolver updating AssetResolver updating in AssetManager for Dynamic features Dec 21, 2020
@GaryQian GaryQian marked this pull request as ready for review December 21, 2020 21:28
if (old_resolver->IsUpdatable()) {
if (index < asset_resolvers.size()) {
// Push the replacement updated resolver in place of the old_resolver.
asset_manager->PushBack(std::move(asset_resolvers[index++]));
Copy link
Member

Choose a reason for hiding this comment

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

Will the asset_resolvers argument always contains exactly the same number of updatable resolvers in exactly the same order as the AssetManager's current resolver list?

I'm wondering if it would be simpler to add an API to AssetManager that would replace an AssetResolver of a given type with a new instance. There would need to be some way to identify which resolver is the APKAssetProvider - perhaps each AssetResolver subclass could return an enum indicating its type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hesitant to add too heavy of a solution, but I agree it would be less confusing to explicitly define which resolver type to update.

In most expected circumstances, the number of replacement resolvers would equal the number of updatable resolvers, but i'm not restricting it to be equal here since there is a reasonable course of action for extra resolvers or fewer resolvers. Restricting would necessitate API to reveal the number of updatable resolvers, which isn't necessary for what is trying to be accomplished here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be sufficient to have UpdateResolversByType accept a single AssetResolver instead of a vector. The only current use case for UpdateResolversByType is replacing the APK resolver, and the caller expects there to be exactly one of that type in the AssetManager's resolver list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@GaryQian GaryQian requested a review from xster December 22, 2020 19:50
@jason-simmons
Copy link
Member

The unit tests are failing on CI due to weak_ptr thread checks.

Copy link
Member

@jason-simmons jason-simmons left a comment

Choose a reason for hiding this comment

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

The mock in FlutterEnginePlatformViewTest.mm needs to be updated

bool updated = false;
std::deque<std::unique_ptr<AssetResolver>> new_resolvers;
for (auto& old_resolver : resolvers_) {
if (!updated && old_resolver->GetType() == type) {
Copy link
Member

Choose a reason for hiding this comment

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

This behavior is somewhat counterintuitive - if updated_asset_resolver is null, then all existing resolvers of the specified type will be removed. But if updated_asset_resolver is non-null, then only the first resolver of that type will be replaced.

Is it necessary to allow updated_asset_resolver to be null? If there is no use case for that, then I'd prefer to limit this API to just replacing the first resolver of the given type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made nullptr input into a no-op.

}
}
// Append resolver to the end if not used as a replacement.
if (!updated && updated_asset_resolver != nullptr) {
Copy link
Member

Choose a reason for hiding this comment

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

The updated_asset_resolver != nullptr check is no longer necessary

/// `updated_asset_resolver`. The matching AssetResolver is
/// removed and replaced with `updated_asset_resolvers`.
///
/// AssetResolvers should be updated when the exisitng resolver
Copy link
Member

Choose a reason for hiding this comment

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

typo: "existing"

(This also appears in the comments for UpdateAssetResolverByType in other classes)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants