Commit f90a9b1f authored by David Trainor's avatar David Trainor Committed by Commit Bot

Add metrics to Download Home UI

Add histograms to the downloads home UI to track impact:
- Actions taken on specific list items.
- Actions taken on the home menu.
- Number of items selected when taking actions on the home menu.

BUG=777630

Change-Id: I1f81bcb18b4f814cf4c76b96aa1b736766c257a8
Reviewed-on: https://chromium-review.googlesource.com/821312Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: David Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524213}
parent 3d5b8d69
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.download.ui; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.download.ui;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
...@@ -19,6 +20,7 @@ import android.widget.LinearLayout; ...@@ -19,6 +20,7 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.download.DownloadUtils; import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.util.FeatureUtilities; import org.chromium.chrome.browser.util.FeatureUtilities;
...@@ -39,6 +41,20 @@ import java.util.Locale; ...@@ -39,6 +41,20 @@ import java.util.Locale;
*/ */
public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrapper> public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrapper>
implements ThumbnailProvider.ThumbnailRequest, ListMenuButton.Delegate { implements ThumbnailProvider.ThumbnailRequest, ListMenuButton.Delegate {
// Please treat this list as append only and keep it in sync with
// Android.DownloadManager.List.View.Actions in enums.xml.
@IntDef({VIEW_ACTION_OPEN, VIEW_ACTION_RESUME, VIEW_ACTION_PAUSE, VIEW_ACTION_CANCEL,
VIEW_ACTION_MENU_SHARE, VIEW_ACTION_MENU_DELETE})
public @interface ViewAction {}
private static final int VIEW_ACTION_OPEN = 0;
private static final int VIEW_ACTION_RESUME = 1;
private static final int VIEW_ACTION_PAUSE = 2;
private static final int VIEW_ACTION_CANCEL = 3;
private static final int VIEW_ACTION_MENU_SHARE = 4;
private static final int VIEW_ACTION_MENU_DELETE = 5;
private static final int VIEW_ACTION_BOUNDARY = 6;
private final int mMargin; private final int mMargin;
private final int mMarginSubsection; private final int mMarginSubsection;
private final int mIconBackgroundColor; private final int mIconBackgroundColor;
...@@ -107,8 +123,10 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap ...@@ -107,8 +123,10 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
@Override @Override
public void onItemSelected(Item item) { public void onItemSelected(Item item) {
if (item.getTextId() == R.string.share) { if (item.getTextId() == R.string.share) {
recordViewActionHistogram(VIEW_ACTION_MENU_SHARE);
mItem.share(); mItem.share();
} else if (item.getTextId() == R.string.delete) { } else if (item.getTextId() == R.string.delete) {
recordViewActionHistogram(VIEW_ACTION_MENU_DELETE);
mItem.startRemove(); mItem.startRemove();
} }
} }
...@@ -136,12 +154,17 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap ...@@ -136,12 +154,17 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
mMoreButton.setDelegate(this); mMoreButton.setDelegate(this);
mPauseResumeButton.setOnClickListener(view -> { mPauseResumeButton.setOnClickListener(view -> {
if (mItem.isPaused()) { if (mItem.isPaused()) {
recordViewActionHistogram(VIEW_ACTION_RESUME);
mItem.resume(); mItem.resume();
} else if (!mItem.isComplete()) { } else if (!mItem.isComplete()) {
recordViewActionHistogram(VIEW_ACTION_PAUSE);
mItem.pause(); mItem.pause();
} }
}); });
mCancelButton.setOnClickListener(view -> mItem.cancel()); mCancelButton.setOnClickListener(view -> {
recordViewActionHistogram(VIEW_ACTION_CANCEL);
mItem.cancel();
});
} }
@Override @Override
...@@ -272,7 +295,10 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap ...@@ -272,7 +295,10 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
@Override @Override
public void onClick() { public void onClick() {
if (mItem != null && mItem.isComplete()) mItem.open(); if (mItem != null && mItem.isComplete()) {
recordViewActionHistogram(VIEW_ACTION_OPEN);
mItem.open();
}
} }
@Override @Override
...@@ -338,4 +364,9 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap ...@@ -338,4 +364,9 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
mLayoutContainer.addView(mMoreButton); mLayoutContainer.addView(mMoreButton);
} }
} }
private static void recordViewActionHistogram(@ViewAction int action) {
RecordHistogram.recordEnumeratedHistogram(
"Android.DownloadManager.List.View.Action", action, VIEW_ACTION_BOUNDARY);
}
} }
...@@ -8,6 +8,7 @@ import android.app.Activity; ...@@ -8,6 +8,7 @@ import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.IntDef;
import android.support.graphics.drawable.VectorDrawableCompat; import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
...@@ -165,6 +166,20 @@ public class DownloadManagerUi ...@@ -165,6 +166,20 @@ public class DownloadManagerUi
} }
} }
// Please treat this list as append only and keep it in sync with
// Android.DownloadManager.Menu.Actions in enums.xml.
@IntDef({MENU_ACTION_CLOSE, MENU_ACTION_MULTI_DELETE, MENU_ACTION_MULTI_SHARE,
MENU_ACTION_SHOW_INFO, MENU_ACTION_HIDE_INFO, MENU_ACTION_SEARCH})
public @interface MenuAction {}
private static final int MENU_ACTION_CLOSE = 0;
private static final int MENU_ACTION_MULTI_DELETE = 1;
private static final int MENU_ACTION_MULTI_SHARE = 2;
private static final int MENU_ACTION_SHOW_INFO = 3;
private static final int MENU_ACTION_HIDE_INFO = 4;
private static final int MENU_ACTION_SEARCH = 5;
private static final int MENU_ACTION_BOUNDARY = 6;
private static BackendProvider sProviderForTests; private static BackendProvider sProviderForTests;
private final DownloadHistoryAdapter mHistoryAdapter; private final DownloadHistoryAdapter mHistoryAdapter;
...@@ -333,12 +348,18 @@ public class DownloadManagerUi ...@@ -333,12 +348,18 @@ public class DownloadManagerUi
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.close_menu_id && mIsSeparateActivity) { if (item.getItemId() == R.id.close_menu_id && mIsSeparateActivity) {
recordMenuActionHistogram(MENU_ACTION_CLOSE);
mActivity.finish(); mActivity.finish();
return true; return true;
} else if (item.getItemId() == R.id.selection_mode_delete_menu_id) { } else if (item.getItemId() == R.id.selection_mode_delete_menu_id) {
List<DownloadHistoryItemWrapper> items = List<DownloadHistoryItemWrapper> items =
mBackendProvider.getSelectionDelegate().getSelectedItems(); mBackendProvider.getSelectionDelegate().getSelectedItems();
mBackendProvider.getSelectionDelegate().clearSelection(); mBackendProvider.getSelectionDelegate().clearSelection();
recordMenuActionHistogram(MENU_ACTION_MULTI_DELETE);
RecordHistogram.recordCount100Histogram(
"Android.DownloadManager.Menu.Delete.SelectedCount", items.size());
deleteItems(items); deleteItems(items);
return true; return true;
} else if (item.getItemId() == R.id.selection_mode_share_menu_id) { } else if (item.getItemId() == R.id.selection_mode_share_menu_id) {
...@@ -348,12 +369,20 @@ public class DownloadManagerUi ...@@ -348,12 +369,20 @@ public class DownloadManagerUi
// startActivityForResult() and the selection would only be cleared // startActivityForResult() and the selection would only be cleared
// after receiving an OK response. See crbug.com/638916. // after receiving an OK response. See crbug.com/638916.
mBackendProvider.getSelectionDelegate().clearSelection(); mBackendProvider.getSelectionDelegate().clearSelection();
recordMenuActionHistogram(MENU_ACTION_MULTI_SHARE);
RecordHistogram.recordCount100Histogram(
"Android.DownloadManager.Menu.Share.SelectedCount", items.size());
startShareIntent(DownloadUtils.createShareIntent(items)); startShareIntent(DownloadUtils.createShareIntent(items));
return true; return true;
} else if (item.getItemId() == R.id.info_menu_id) { } else if (item.getItemId() == R.id.info_menu_id) {
enableStorageInfoHeader(!mHistoryAdapter.shouldShowStorageInfoHeader()); boolean showInfo = !mHistoryAdapter.shouldShowStorageInfoHeader();
recordMenuActionHistogram(showInfo ? MENU_ACTION_SHOW_INFO : MENU_ACTION_HIDE_INFO);
enableStorageInfoHeader(showInfo);
return true; return true;
} else if (item.getItemId() == R.id.search_menu_id) { } else if (item.getItemId() == R.id.search_menu_id) {
recordMenuActionHistogram(MENU_ACTION_SEARCH);
// The header should be removed as soon as a search is started. It will be added back in // The header should be removed as soon as a search is started. It will be added back in
// DownloadHistoryAdatper#filter() when the search is ended. // DownloadHistoryAdatper#filter() when the search is ended.
mHistoryAdapter.removeHeader(); mHistoryAdapter.removeHeader();
...@@ -514,4 +543,9 @@ public class DownloadManagerUi ...@@ -514,4 +543,9 @@ public class DownloadManagerUi
public static void setProviderForTests(BackendProvider provider) { public static void setProviderForTests(BackendProvider provider) {
sProviderForTests = provider; sProviderForTests = provider;
} }
private static void recordMenuActionHistogram(@MenuAction int action) {
RecordHistogram.recordEnumeratedHistogram(
"Android.DownloadManager.Menu.Action", action, MENU_ACTION_BOUNDARY);
}
} }
...@@ -537,6 +537,24 @@ uploading your change for review. These are checked by presubmit scripts. ...@@ -537,6 +537,24 @@ uploading your change for review. These are checked by presubmit scripts.
<int value="4" label="Not QUIC, destination different from origin"/> <int value="4" label="Not QUIC, destination different from origin"/>
</enum> </enum>
<enum name="Android.DownloadManager.List.View.Actions">
<int value="0" label="OPEN"/>
<int value="1" label="RESUME"/>
<int value="2" label="PAUSE"/>
<int value="3" label="CANCEL"/>
<int value="4" label="MENU_SHARE"/>
<int value="5" label="MENU_DELETE"/>
</enum>
<enum name="Android.DownloadManager.Menu.Actions">
<int value="0" label="CLOSE"/>
<int value="1" label="MULTI_DELETE"/>
<int value="2" label="MULTI_SHARE"/>
<int value="3" label="SHOW_INFO"/>
<int value="4" label="HIDE_INFO"/>
<int value="5" label="SEARCH"/>
</enum>
<enum name="AndroidActivityId"> <enum name="AndroidActivityId">
<int value="1" label="Unknown"/> <int value="1" label="Unknown"/>
<int value="2" label="Main"/> <int value="2" label="Main"/>
...@@ -925,6 +925,32 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -925,6 +925,32 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<summary>Recorded when a download is opened.</summary> <summary>Recorded when a download is opened.</summary>
</histogram> </histogram>
<histogram name="Android.DownloadManager.List.View.Action"
enum="Android.DownloadManager.List.View.Actions">
<owner>dtrainor@chromium.org</owner>
<summary>The count of Download Home list entry actions taken.</summary>
</histogram>
<histogram name="Android.DownloadManager.Menu.Action"
enum="Android.DownloadManager.Menu.Actions">
<owner>dtrainor@chromium.org</owner>
<summary>The count of Download Home top level menu actions taken.</summary>
</histogram>
<histogram name="Android.DownloadManager.Menu.Delete.SelectedCount">
<owner>dtrainor@chromium.org</owner>
<summary>
The number of items selected when performing a multi-delete action.
</summary>
</histogram>
<histogram name="Android.DownloadManager.Menu.Share.SelectedCount">
<owner>dtrainor@chromium.org</owner>
<summary>
The number of items selected when performing a multi-share action.
</summary>
</histogram>
<histogram name="Android.DownloadManager.NotificationInteraction" <histogram name="Android.DownloadManager.NotificationInteraction"
enum="DownloadNotificationInteractions"> enum="DownloadNotificationInteractions">
<owner>jming@chromium.org</owner> <owner>jming@chromium.org</owner>
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