0

[ios] Re-fetch Parcel Tracking after resetting Magic Stack Ranking

When refreshing the Magic Stack, it is possible that the ShoppingService
request returns synchronously. In that case, it will likely attempt
to insert into the Magic Stack before the new ranking is fetched.
This not only will hit a DumpWithoutCrash if there was already a
parcel tracking card, but also is wrong from an overall Magic Stack
state standpoint. Thus, -fetchTrackedParcels is exposed publically
and called after -fetchLatestMagicStackRanking to ensure the previous
Magic Stack is cleared.

A new -reset MagicStackCollectionView API resets it with placeholders
upon a refresh to also clear past cards.

Bug: 342617531
Change-Id: I4554dd165484f0943c29628bbdd97853ea635ce2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5784202
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: Scott Yoder <scottyoder@google.com>
Cr-Commit-Position: refs/heads/main@{#1343660}
This commit is contained in:
Chris Lu
2024-08-19 19:34:26 +00:00
committed by Chromium LUCI CQ
parent 53f503e04c
commit db7f9042af
6 changed files with 36 additions and 21 deletions

@ -444,11 +444,15 @@
#pragma mark - Public methods
- (void)refresh {
[_magicStackCollectionView reset];
// Refresh in case there are new MVT to show.
[_mostVisitedTilesMediator refreshMostVisitedTiles];
[_safetyCheckMediator reset];
[_parcelTrackingMediator reset];
[_magicStackRankingModel fetchLatestMagicStackRanking];
// Fetch after resetting ranking since parcels could be returned
// synchronously.
[_parcelTrackingMediator fetchTrackedParcels];
}
#pragma mark - ContentSuggestionsCommands

@ -27,6 +27,9 @@ typedef UICollectionViewDiffableDataSource<NSString*, MagicStackModule*>
// Called when the module width has changed.
- (void)moduleWidthDidUpdate;
// Resets the Magic Stack.
- (void)reset;
@end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_MAGIC_STACK_MAGIC_STACK_COLLECTION_VIEW_H_

@ -91,6 +91,10 @@ typedef NSDiffableDataSourceSnapshot<NSString*, MagicStackModule*>
}
}
- (void)reset {
[self populateWithPlaceholders];
}
#pragma mark - MagicStackConsumer
- (void)populateItems:(NSArray<MagicStackModule*>*)items {

@ -127,7 +127,10 @@
#pragma mark - Public
- (void)fetchLatestMagicStackRanking {
[self fetchMagicStackModuleRankingFromSegmentationPlatform];
_magicStackOrderFromSegmentationReceived = NO;
_magicStackOrderFromSegmentation = nil;
_latestMagicStackConfigOrder = nil;
[self fetchMagicStackModuleRankingFromSegmentationPlatform];
}
- (void)logMagicStackEngagementForType:(ContentSuggestionsModuleType)type {
@ -199,6 +202,9 @@
MagicStackModule* item = _parcelTrackingMediator.parcelTrackingItemToShow;
NSArray<MagicStackModule*>* rank = [self latestMagicStackConfigRank];
NSUInteger index = [rank indexOfObject:item];
if (index == NSNotFound) {
return;
}
[self.delegate magicStackRankingModel:self didInsertItem:item atIndex:index];
}
@ -347,7 +353,6 @@
options.on_demand_execution = true;
}
ranking_fetch_start_time_ = base::TimeTicks::Now();
_magicStackOrderFromSegmentationReceived = NO;
_segmentationService->GetClassificationResult(
segmentation_platform::kIosModuleRankerKey, options, inputContext,
base::BindOnce(

@ -59,6 +59,9 @@ class PrefService;
// Resets the latest fetched tracked packages and re-fecthes if applicable.
- (void)reset;
// Fetches the latest tracked parcels.
- (void)fetchTrackedParcels;
// Returns the parcel tracking items to show.
- (ParcelTrackingItem*)parcelTrackingItemToShow;

@ -78,10 +78,21 @@
- (void)reset {
_parcelTrackingItems = nil;
if (IsIOSParcelTrackingEnabled() &&
_shoppingService->IsParcelTrackingEligible()) {
[self fetchTrackedParcels];
}
}
- (void)fetchTrackedParcels {
_parcelFetchTimeoutClosure.Cancel();
__weak ParcelTrackingMediator* weakSelf = self;
_parcelFetchTimeoutClosure.Reset(base::BindOnce(
^(bool success,
std::unique_ptr<std::vector<commerce::ParcelTrackingStatus>> parcels) {
ParcelTrackingMediator* strongSelf = weakSelf;
if (!strongSelf || !success || !strongSelf.delegate) {
return;
}
[strongSelf parcelStatusesSuccessfullyReceived:std::move(parcels)];
}));
_shoppingService->GetAllParcelStatuses(_parcelFetchTimeoutClosure.callback());
}
#pragma mark - Public
@ -165,21 +176,6 @@
#pragma mark - Private
- (void)fetchTrackedParcels {
_parcelFetchTimeoutClosure.Cancel();
__weak ParcelTrackingMediator* weakSelf = self;
_parcelFetchTimeoutClosure.Reset(base::BindOnce(
^(bool success,
std::unique_ptr<std::vector<commerce::ParcelTrackingStatus>> parcels) {
ParcelTrackingMediator* strongSelf = weakSelf;
if (!strongSelf || !success || !strongSelf.delegate) {
return;
}
[strongSelf parcelStatusesSuccessfullyReceived:std::move(parcels)];
}));
_shoppingService->GetAllParcelStatuses(_parcelFetchTimeoutClosure.callback());
}
// Handles a parcel tracking status fetch result from the
// commerce::ShoppingService.
- (void)parcelStatusesSuccessfullyReceived: