Skip to content

Commit

Permalink
Add trace events to MV tiles.
Browse files Browse the repository at this point in the history
Bug: 1277723
Change-Id: I6313e16d7fd2214187c19d3e48f6d5d975ac643c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3321932
Reviewed-by: Xi Han <hanxi@chromium.org>
Reviewed-by: Cathy Li <chili@chromium.org>
Reviewed-by: ssid <ssid@chromium.org>
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#949572}
  • Loading branch information
spdonghao authored and Chromium LUCI CQ committed Dec 8, 2021
1 parent 97d187a commit 4a6248c
Showing 1 changed file with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.TraceEvent;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.explore_sites.ExploreSitesBridge;
Expand Down Expand Up @@ -97,27 +98,29 @@ public TileRenderer(
*/
public void renderTileSection(
List<Tile> sectionTiles, ViewGroup parent, TileGroup.TileSetupDelegate setupDelegate) {
// Map the old tile views by url so they can be reused later.
Map<SiteSuggestion, SuggestionsTileView> oldTileViews = new HashMap<>();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
SuggestionsTileView tileView = (SuggestionsTileView) parent.getChildAt(i);
oldTileViews.put(tileView.getData(), tileView);
}
try (TraceEvent e = TraceEvent.scoped("TileRenderer.renderTileSection")) {
// Map the old tile views by url so they can be reused later.
Map<SiteSuggestion, SuggestionsTileView> oldTileViews = new HashMap<>();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
SuggestionsTileView tileView = (SuggestionsTileView) parent.getChildAt(i);
oldTileViews.put(tileView.getData(), tileView);
}

// Remove all views from the layout because even if they are reused later they'll have to be
// added back in the correct order.
parent.removeAllViews();
// Remove all views from the layout because even if they are reused later they'll have
// to be added back in the correct order.
parent.removeAllViews();

for (Tile tile : sectionTiles) {
SuggestionsTileView tileView = oldTileViews.get(tile.getData());
if (tileView == null || tileView.getIconView() == null
|| tileView.getIconView().getDrawable() == null
|| tile.getSource() == TileSource.EXPLORE) {
tileView = buildTileView(tile, parent, setupDelegate);
}
for (Tile tile : sectionTiles) {
SuggestionsTileView tileView = oldTileViews.get(tile.getData());
if (tileView == null || tileView.getIconView() == null
|| tileView.getIconView().getDrawable() == null
|| tile.getSource() == TileSource.EXPLORE) {
tileView = buildTileView(tile, parent, setupDelegate);
}

parent.addView(tileView);
parent.addView(tileView);
}
}
}

Expand Down

0 comments on commit 4a6248c

Please sign in to comment.