Commit 86c6b722 authored by spdonghao's avatar spdonghao Committed by Chromium LUCI CQ

[Instant Start] 2 stages initializaton of MostVisitedListCoordinator.

Bug: 1061906
Change-Id: I83b3021e5f0428dc6d2f46b6c2ec4deef75aa8e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2623189Reviewed-by: default avatarCathy Li <chili@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844943}
parent 810527b8
...@@ -49,6 +49,7 @@ class MostVisitedListCoordinator implements TileGroup.Observer, TileGroup.TileSe ...@@ -49,6 +49,7 @@ class MostVisitedListCoordinator implements TileGroup.Observer, TileGroup.TileSe
private TileGroup mTileGroup; private TileGroup mTileGroup;
private TileRenderer mRenderer; private TileRenderer mRenderer;
private SuggestionsUiDelegate mSuggestionsUiDelegate; private SuggestionsUiDelegate mSuggestionsUiDelegate;
private boolean mInitializationComplete;
public MostVisitedListCoordinator(ChromeActivity activity, ViewGroup parent, public MostVisitedListCoordinator(ChromeActivity activity, ViewGroup parent,
PropertyModel propertyModel, Supplier<Tab> parentTabSupplier) { PropertyModel propertyModel, Supplier<Tab> parentTabSupplier) {
...@@ -60,16 +61,25 @@ class MostVisitedListCoordinator implements TileGroup.Observer, TileGroup.TileSe ...@@ -60,16 +61,25 @@ class MostVisitedListCoordinator implements TileGroup.Observer, TileGroup.TileSe
} }
public void initialize() { public void initialize() {
mRenderer =
new TileRenderer(mActivity, SuggestionsConfig.TileStyle.MODERN, TITLE_LINES, null);
}
public void initWithNative() {
Profile profile = Profile.getLastUsedRegularProfile(); Profile profile = Profile.getLastUsedRegularProfile();
SnackbarManager snackbarManager = mActivity.getSnackbarManager(); SnackbarManager snackbarManager = mActivity.getSnackbarManager();
if (mRenderer == null) { if (!mInitializationComplete) {
// This function is never called in incognito mode.
ImageFetcher imageFetcher = new ImageFetcher(profile); ImageFetcher imageFetcher = new ImageFetcher(profile);
mRenderer = new TileRenderer(
mActivity, SuggestionsConfig.TileStyle.MODERN, TITLE_LINES, imageFetcher);
mSuggestionsUiDelegate = new MostVisitedSuggestionsUiDelegate(profile, snackbarManager); mSuggestionsUiDelegate = new MostVisitedSuggestionsUiDelegate(profile, snackbarManager);
if (mRenderer == null) {
// This function is never called in incognito mode.
mRenderer = new TileRenderer(
mActivity, SuggestionsConfig.TileStyle.MODERN, TITLE_LINES, imageFetcher);
} else {
mRenderer.setImageFetcher(imageFetcher);
}
} }
OfflinePageBridge offlinePageBridge = OfflinePageBridge offlinePageBridge =
SuggestionsDependencyFactory.getInstance().getOfflinePageBridge(profile); SuggestionsDependencyFactory.getInstance().getOfflinePageBridge(profile);
TileGroupDelegateImpl tileGroupDelegate = TileGroupDelegateImpl tileGroupDelegate =
...@@ -77,6 +87,7 @@ class MostVisitedListCoordinator implements TileGroup.Observer, TileGroup.TileSe ...@@ -77,6 +87,7 @@ class MostVisitedListCoordinator implements TileGroup.Observer, TileGroup.TileSe
mTileGroup = new TileGroup(mRenderer, mSuggestionsUiDelegate, null, tileGroupDelegate, this, mTileGroup = new TileGroup(mRenderer, mSuggestionsUiDelegate, null, tileGroupDelegate, this,
offlinePageBridge); offlinePageBridge);
mTileGroup.startObserving(MAX_RESULTS); mTileGroup.startObserving(MAX_RESULTS);
mInitializationComplete = true;
} }
private void updateTileIcon(Tile tile) { private void updateTileIcon(Tile tile) {
......
...@@ -96,6 +96,7 @@ public class TasksSurfaceCoordinator implements TasksSurface { ...@@ -96,6 +96,7 @@ public class TasksSurfaceCoordinator implements TasksSurface {
LinearLayout mvTilesLayout = mView.findViewById(R.id.mv_tiles_layout); LinearLayout mvTilesLayout = mView.findViewById(R.id.mv_tiles_layout);
mMostVisitedList = new MostVisitedListCoordinator( mMostVisitedList = new MostVisitedListCoordinator(
activity, mvTilesLayout, mPropertyModel, parentTabSupplier); activity, mvTilesLayout, mPropertyModel, parentTabSupplier);
mMostVisitedList.initialize();
} }
} }
...@@ -104,7 +105,7 @@ public class TasksSurfaceCoordinator implements TasksSurface { ...@@ -104,7 +105,7 @@ public class TasksSurfaceCoordinator implements TasksSurface {
public void initialize() { public void initialize() {
assert LibraryLoader.getInstance().isInitialized(); assert LibraryLoader.getInstance().isInitialized();
if (mMostVisitedList != null) mMostVisitedList.initialize(); if (mMostVisitedList != null) mMostVisitedList.initWithNative();
mMediator.initialize(); mMediator.initialize();
} }
......
...@@ -48,9 +48,9 @@ public class TileRenderer { ...@@ -48,9 +48,9 @@ public class TileRenderer {
private static final String TAG = "TileRenderer"; private static final String TAG = "TileRenderer";
private final Resources mResources; private final Resources mResources;
private final ImageFetcher mImageFetcher;
private final RoundedIconGenerator mIconGenerator; private final RoundedIconGenerator mIconGenerator;
private final Resources.Theme mTheme; private final Resources.Theme mTheme;
private ImageFetcher mImageFetcher;
@TileStyle @TileStyle
private final int mStyle; private final int mStyle;
...@@ -121,6 +121,10 @@ public class TileRenderer { ...@@ -121,6 +121,10 @@ public class TileRenderer {
} }
} }
public void setImageFetcher(ImageFetcher imageFetcher) {
mImageFetcher = imageFetcher;
}
/** /**
* Record that a tile was clicked for IPH reasons. * Record that a tile was clicked for IPH reasons.
*/ */
...@@ -166,7 +170,7 @@ public class TileRenderer { ...@@ -166,7 +170,7 @@ public class TileRenderer {
// Note: It is important that the callbacks below don't keep a reference to the tile or // Note: It is important that the callbacks below don't keep a reference to the tile or
// modify them as there is no guarantee that the same tile would be used to update the view. // modify them as there is no guarantee that the same tile would be used to update the view.
if (tile.getSource() != TileSource.EXPLORE) { if (mImageFetcher != null && tile.getSource() != TileSource.EXPLORE) {
fetchIcon(tile.getData(), setupDelegate.createIconLoadCallback(tile)); fetchIcon(tile.getData(), setupDelegate.createIconLoadCallback(tile));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment