Skip to content

Commit

Permalink
Add viewed download files metrics on Android.
Browse files Browse the repository at this point in the history
This CL adds the initial count for download files.

The metric is recorded when Android code loaded the history database
records.

Bug: 817220
Change-Id: I571ecbca2aacc3a2be863cdf36310b32569fabe1
Reviewed-on: https://chromium-review.googlesource.com/941519
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Mark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540328}
  • Loading branch information
Xing Liu authored and Commit Bot committed Mar 1, 2018
1 parent bae8a74 commit 27f6f3b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,17 @@ public static ColorStateList getIconForegroundColorList(Context context) {
context.getResources(), R.color.white_mode_tint);
}

/**
* Return if a download item is already viewed by the user. Will return false if the last
* access time is not available.
* @param item The download item.
* @return true if the item is viewed by the user.
*/
public static boolean isDownloadViewed(DownloadItem item) {
if (item == null || item.getDownloadInfo() == null) return false;
return item.getDownloadInfo().getLastAccessTime() != 0;
}

private static boolean isMimeTypeVideo(String mimeType) {
if (TextUtils.isEmpty(mimeType)) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.download.DownloadItem;
import org.chromium.chrome.browser.download.DownloadSharedPreferenceHelper;
import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.download.ui.BackendProvider.DownloadDelegate;
import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper.DownloadItemWrapper;
import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper.OfflineItemWrapper;
Expand Down Expand Up @@ -272,12 +273,16 @@ public void onAllDownloadsRetrieved(List<DownloadItem> result, boolean isOffTheR
assert list.size() == 0;

int[] itemCounts = new int[DownloadFilter.FILTER_BOUNDARY];
int[] viewedItemCounts = new int[DownloadFilter.FILTER_BOUNDARY];

for (DownloadItem item : result) {
DownloadItemWrapper wrapper = createDownloadItemWrapper(item);
if (addDownloadHistoryItemWrapper(wrapper)
&& wrapper.isVisibleToUser(DownloadFilter.FILTER_ALL)) {
itemCounts[wrapper.getFilterType()]++;

if (DownloadUtils.isDownloadViewed(wrapper.getItem()))
viewedItemCounts[wrapper.getFilterType()]++;
if (!isOffTheRecord && wrapper.getFilterType() == DownloadFilter.FILTER_OTHER) {
RecordHistogram.recordEnumeratedHistogram(
"Android.DownloadManager.OtherExtensions.InitialCount",
Expand All @@ -287,7 +292,7 @@ public void onAllDownloadsRetrieved(List<DownloadItem> result, boolean isOffTheR
}
}

if (!isOffTheRecord) recordDownloadCountHistograms(itemCounts);
if (!isOffTheRecord) recordDownloadCountHistograms(itemCounts, viewedItemCounts);

list.setIsInitialized();
onItemsRetrieved(isOffTheRecord
Expand Down Expand Up @@ -732,7 +737,7 @@ private DownloadItemWrapper createDownloadItemWrapper(DownloadItem item) {
return new DownloadItemWrapper(item, mBackendProvider, mParentComponent);
}

private void recordDownloadCountHistograms(int[] itemCounts) {
private void recordDownloadCountHistograms(int[] itemCounts, int[] viewedItemCounts) {
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Audio",
itemCounts[DownloadFilter.FILTER_AUDIO]);
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Document",
Expand All @@ -743,6 +748,17 @@ private void recordDownloadCountHistograms(int[] itemCounts) {
itemCounts[DownloadFilter.FILTER_OTHER]);
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Video",
itemCounts[DownloadFilter.FILTER_VIDEO]);

RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Viewed.Audio",
viewedItemCounts[DownloadFilter.FILTER_AUDIO]);
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Viewed.Document",
viewedItemCounts[DownloadFilter.FILTER_DOCUMENT]);
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Viewed.Image",
viewedItemCounts[DownloadFilter.FILTER_IMAGE]);
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Viewed.Other",
viewedItemCounts[DownloadFilter.FILTER_OTHER]);
RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Viewed.Video",
viewedItemCounts[DownloadFilter.FILTER_VIDEO]);
}

private void recordTotalDownloadCountHistogram() {
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 @@ -967,6 +967,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Android.DownloadManager.InitialCount.Viewed">
<owner>xingliu@chromium.org</owner>
<summary>
The number of non-incognito download items displayed that are already viewed
by the user at any time, recorded when the download UI is initialized.
</summary>
</histogram>

<histogram name="Android.DownloadManager.Item.OpenFailed"
enum="AndroidDownloadFilterType">
<owner>dfalcantara@chromium.org</owner>
Expand Down Expand Up @@ -103427,6 +103435,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<suffix name="Total"/>
<suffix name="Video"/>
<affected-histogram name="Android.DownloadManager.InitialCount"/>
<affected-histogram name="Android.DownloadManager.InitialCount.Viewed"/>
</histogram_suffixes>

<histogram_suffixes name="AndroidGATTEvents" separator=".">
Expand Down

0 comments on commit 27f6f3b

Please sign in to comment.