Skip to content

Commit

Permalink
[Offline pages on the NTP] Add UMA for offline-available NTP tiles
Browse files Browse the repository at this point in the history
BUG=565219

Review URL: https://codereview.chromium.org/1721753002

Cr-Commit-Position: refs/heads/master@{#377033}
  • Loading branch information
treib authored and Commit bot committed Feb 23, 2016
1 parent fd72466 commit cc4e35d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface MostVisitedItemManager {
private MostVisitedItemManager mManager;
private String mTitle;
private String mUrl;
private boolean mOfflineAvailable;
private int mIndex;
private int mTileType;
private View mView;
Expand All @@ -59,12 +60,15 @@ public interface MostVisitedItemManager {
* @param manager The NewTabPageManager used to handle clicks and context menu events.
* @param title The title of the page.
* @param url The URL of the page.
* @param offlineAvailable Whether there is an offline copy of the URL available.
* @param index The index of this item in the list of most visited items.
*/
public MostVisitedItem(MostVisitedItemManager manager, String title, String url, int index) {
public MostVisitedItem(MostVisitedItemManager manager, String title, String url,
boolean offlineAvailable, int index) {
mManager = manager;
mTitle = title;
mUrl = url;
mOfflineAvailable = offlineAvailable;
mIndex = index;
mTileType = MostVisitedTileType.NONE;
}
Expand Down Expand Up @@ -101,6 +105,13 @@ public String getTitle() {
return mTitle;
}

/**
* @return Whether this item is available offline.
*/
public boolean isOfflineAvailable() {
return mOfflineAvailable;
}

/**
* @return The index of this MostVisitedItem in the list of MostVisitedItems.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,16 @@ public void onLoadingComplete(MostVisitedItem[] items) {
}
mMostVisitedSites.recordTileTypeMetrics(tileTypes);

if (isNtpOfflinePagesEnabled()) {
final int maxNumTiles = 12;
for (int i = 0; i < items.length; i++) {
if (items[i].isOfflineAvailable()) {
RecordHistogram.recordEnumeratedHistogram(
"NewTabPage.TileOfflineAvailable", i, maxNumTiles);
}
}
}

SyncSessionsMetrics.recordYoungestForeignTabAgeOnNTP();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,15 @@ public void onMostVisitedURLsAvailable(String[] titles, String[] urls) {
for (int i = 0; i < titles.length; i++) {
final String url = urls[i];
final String title = titles[i];
boolean offlineAvailable = mManager.isOfflineAvailable(url);

// Look for an existing item to reuse.
MostVisitedItem item = null;
for (int j = 0; j < oldItemCount; j++) {
MostVisitedItem oldItem = oldItems[j];
if (oldItem != null && TextUtils.equals(url, oldItem.getUrl())
&& TextUtils.equals(title, oldItem.getTitle())) {
&& TextUtils.equals(title, oldItem.getTitle())
&& offlineAvailable == oldItem.isOfflineAvailable()) {
item = oldItem;
item.setIndex(i);
oldItems[j] = null;
Expand All @@ -799,10 +801,9 @@ public void onMostVisitedURLsAvailable(String[] titles, String[] urls) {

// If nothing can be reused, create a new item.
if (item == null) {
String displayTitle = getTitleForDisplay(title, url);
item = new MostVisitedItem(mManager, title, url, i);
View view = mMostVisitedDesign.createMostVisitedItemView(inflater, url,
displayTitle, item, isInitialLoad);
item = new MostVisitedItem(mManager, title, url, offlineAvailable, i);
View view =
mMostVisitedDesign.createMostVisitedItemView(inflater, item, isInitialLoad);
item.initView(view);
}

Expand Down Expand Up @@ -963,17 +964,16 @@ public void onLargeIconAvailable(Bitmap icon, int fallbackColor) {
}
}

public View createMostVisitedItemView(LayoutInflater inflater, final String url,
String displayTitle, MostVisitedItem item,
final boolean isInitialLoad) {
public View createMostVisitedItemView(
LayoutInflater inflater, MostVisitedItem item, boolean isInitialLoad) {
final MostVisitedItemView view = (MostVisitedItemView) inflater.inflate(
R.layout.most_visited_item, mMostVisitedLayout, false);
view.setTitle(displayTitle);
view.setOfflineAvailable(mManager.isOfflineAvailable(url));
view.setTitle(getTitleForDisplay(item.getTitle(), item.getUrl()));
view.setOfflineAvailable(item.isOfflineAvailable());

LargeIconCallback iconCallback = new LargeIconCallbackImpl(item, isInitialLoad);
if (isInitialLoad) mPendingLoadTasks++;
mManager.getLargeIconForUrl(url, mMinIconSize, iconCallback);
mManager.getLargeIconForUrl(item.getUrl(), mMinIconSize, iconCallback);

return view;
}
Expand Down
9 changes: 9 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31342,6 +31342,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="NewTabPage.TileOfflineAvailable">
<owner>treib@chromium.org</owner>
<summary>
The number of times a tile was available offline, per tile index - compare
to the NewTabPage.SuggestionsImpression.* histograms. This is recorded when
the NTP finishes loading. Only measured on Android.
</summary>
</histogram>

<histogram name="NewTabPage.TileType" enum="MostVisitedTileType">
<owner>newt@chromium.org</owner>
<summary>
Expand Down

0 comments on commit cc4e35d

Please sign in to comment.