Skip to content

Commit

Permalink
[PriceTracking] Reset tabs on price annotations pref change
Browse files Browse the repository at this point in the history
When user updates the price annoatation preference, we should reset tabs
to reflect possible UI changes.

Bug: 1307943
Change-Id: I8e02560e1fdcce782f1d99333d3f8e99f0bd1940
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3564420
Reviewed-by: Yue Zhang <yuezhanggg@chromium.org>
Commit-Queue: Zhiyuan Cai <zhiyuancai@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988282}
  • Loading branch information
Zhiyuan Cai authored and Chromium LUCI CQ committed Apr 2, 2022
1 parent beced96 commit a23c4b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class PriceTrackingUtilities {
@VisibleForTesting
public static final String ALLOW_DISABLE_PRICE_ANNOTATIONS_PARAM =
"allow_disable_price_annotations";
@VisibleForTesting
public static final String TRACK_PRICES_ON_TABS =
ChromePreferenceKeys.PRICE_TRACKING_TRACK_PRICES_ON_TABS;
@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.DestroyObserver;
import org.chromium.chrome.browser.multiwindow.MultiWindowModeStateDispatcher;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.price_tracking.PriceDropNotificationManager;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
Expand Down Expand Up @@ -117,6 +118,7 @@ private class TabGroupManualSelectionMode {
private TabCreatorManager mTabCreatorManager;
private boolean mIsInitialized;
private PriceMessageService mPriceMessageService;
private SharedPreferencesManager.Observer mPriceAnnotationsPrefObserver;
private final ViewGroup mCoordinatorView;
private final ViewGroup mRootView;

Expand Down Expand Up @@ -293,6 +295,20 @@ public void finishedHiding() {}
mTabListCoordinator.registerItemType(TabProperties.UiType.LARGE_MESSAGE,
new LayoutViewBuilder(R.layout.large_message_card_item),
LargeMessageCardViewBinder::bind);

if (PriceTrackingUtilities.getPriceTrackingEnabled()) {
mPriceAnnotationsPrefObserver = key -> {
if (PriceTrackingUtilities.TRACK_PRICES_ON_TABS.equals(key)
&& !mTabModelSelector.isIncognitoSelected()
&& mTabModelSelector.isTabStateInitialized()) {
resetWithTabList(mTabModelSelector.getTabModelFilterProvider()
.getCurrentTabModelFilter(),
false, isShowingTabsInMRUOrder(mMode));
}
};
SharedPreferencesManager.getInstance().addObserver(
mPriceAnnotationsPrefObserver);
}
}
}

Expand Down Expand Up @@ -677,6 +693,9 @@ public void onDestroy() {
if (mTabAttributeCache != null) {
mTabAttributeCache.destroy();
}
if (mPriceAnnotationsPrefObserver != null) {
SharedPreferencesManager.getInstance().removeObserver(mPriceAnnotationsPrefObserver);
}
}

/**
Expand Down

0 comments on commit a23c4b1

Please sign in to comment.