Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java

Issue 2681033002: Add new UMA to record the bytes wasted due to download resumption (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.download; 5 package org.chromium.chrome.browser.download;
6 6
7 import android.app.DownloadManager; 7 import android.app.DownloadManager;
8 import android.content.ActivityNotFoundException; 8 import android.content.ActivityNotFoundException;
9 import android.content.BroadcastReceiver; 9 import android.content.BroadcastReceiver;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 private static final String TAG = "DownloadService"; 74 private static final String TAG = "DownloadService";
75 private static final String DOWNLOAD_DIRECTORY = "Download"; 75 private static final String DOWNLOAD_DIRECTORY = "Download";
76 protected static final String PENDING_OMA_DOWNLOADS = "PendingOMADownloads"; 76 protected static final String PENDING_OMA_DOWNLOADS = "PendingOMADownloads";
77 private static final String UNKNOWN_MIME_TYPE = "application/unknown"; 77 private static final String UNKNOWN_MIME_TYPE = "application/unknown";
78 private static final String DOWNLOAD_UMA_ENTRY = "DownloadUmaEntry"; 78 private static final String DOWNLOAD_UMA_ENTRY = "DownloadUmaEntry";
79 private static final long UPDATE_DELAY_MILLIS = 1000; 79 private static final long UPDATE_DELAY_MILLIS = 1000;
80 // Wait 10 seconds to resume all downloads, so that we won't impact tab load ing. 80 // Wait 10 seconds to resume all downloads, so that we won't impact tab load ing.
81 private static final long RESUME_DELAY_MILLIS = 10000; 81 private static final long RESUME_DELAY_MILLIS = 10000;
82 private static final int UNKNOWN_DOWNLOAD_STATUS = -1; 82 private static final int UNKNOWN_DOWNLOAD_STATUS = -1;
83 public static final long UNKNOWN_BYTES_RECEIVED = -1;
83 private static final String PREF_IS_DOWNLOAD_HOME_ENABLED = 84 private static final String PREF_IS_DOWNLOAD_HOME_ENABLED =
84 "org.chromium.chrome.browser.download.IS_DOWNLOAD_HOME_ENABLED"; 85 "org.chromium.chrome.browser.download.IS_DOWNLOAD_HOME_ENABLED";
85 86
86 // Values for the histogram MobileDownloadResumptionCount. 87 // Values for the histogram MobileDownloadResumptionCount.
87 private static final int UMA_DOWNLOAD_RESUMPTION_MANUAL_PAUSE = 0; 88 private static final int UMA_DOWNLOAD_RESUMPTION_MANUAL_PAUSE = 0;
88 private static final int UMA_DOWNLOAD_RESUMPTION_BROWSER_KILLED = 1; 89 private static final int UMA_DOWNLOAD_RESUMPTION_BROWSER_KILLED = 1;
89 private static final int UMA_DOWNLOAD_RESUMPTION_CLICKED = 2; 90 private static final int UMA_DOWNLOAD_RESUMPTION_CLICKED = 2;
90 private static final int UMA_DOWNLOAD_RESUMPTION_FAILED = 3; 91 private static final int UMA_DOWNLOAD_RESUMPTION_FAILED = 3;
91 private static final int UMA_DOWNLOAD_RESUMPTION_AUTO_STARTED = 4; 92 private static final int UMA_DOWNLOAD_RESUMPTION_AUTO_STARTED = 4;
92 private static final int UMA_DOWNLOAD_RESUMPTION_COUNT = 5; 93 private static final int UMA_DOWNLOAD_RESUMPTION_COUNT = 5;
93 94
95 private static final int GB_IN_KILO_BYTES = 1000 * 1000;
Ilya Sherman 2017/02/08 02:11:19 Are you sure that you want 1000 * 1000 and not 102
qinmin 2017/02/09 01:05:10 Switched to use 1024 * 1024. However, we don't rea
96
94 // Set will be more expensive to initialize, so use an ArrayList here. 97 // Set will be more expensive to initialize, so use an ArrayList here.
95 private static final List<String> MIME_TYPES_TO_OPEN = new ArrayList<String> (Arrays.asList( 98 private static final List<String> MIME_TYPES_TO_OPEN = new ArrayList<String> (Arrays.asList(
96 OMADownloadHandler.OMA_DOWNLOAD_DESCRIPTOR_MIME, 99 OMADownloadHandler.OMA_DOWNLOAD_DESCRIPTOR_MIME,
97 "application/pdf", 100 "application/pdf",
98 "application/x-x509-ca-cert", 101 "application/x-x509-ca-cert",
99 "application/x-x509-user-cert", 102 "application/x-x509-user-cert",
100 "application/x-x509-server-cert", 103 "application/x-x509-server-cert",
101 "application/x-pkcs12", 104 "application/x-pkcs12",
102 "application/application/x-pem-file", 105 "application/application/x-pem-file",
103 "application/pkix-cert", 106 "application/pkix-cert",
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 * Updates the progress of a download. 719 * Updates the progress of a download.
717 * 720 *
718 * @param downloadItem Information about the download. 721 * @param downloadItem Information about the download.
719 * @param downloadStatus Status of the download. 722 * @param downloadStatus Status of the download.
720 */ 723 */
721 private void updateDownloadProgress(DownloadItem downloadItem, int downloadS tatus) { 724 private void updateDownloadProgress(DownloadItem downloadItem, int downloadS tatus) {
722 boolean isSupportedMimeType = (downloadStatus == DOWNLOAD_STATUS_COMPLET E) 725 boolean isSupportedMimeType = (downloadStatus == DOWNLOAD_STATUS_COMPLET E)
723 ? isSupportedMimeType(downloadItem.getDownloadInfo().getMimeType ()) : false; 726 ? isSupportedMimeType(downloadItem.getDownloadInfo().getMimeType ()) : false;
724 String id = downloadItem.getId(); 727 String id = downloadItem.getId();
725 DownloadProgress progress = mDownloadProgressMap.get(id); 728 DownloadProgress progress = mDownloadProgressMap.get(id);
729 long bytesReceived = downloadItem.getDownloadInfo().getBytesReceived();
726 if (progress == null) { 730 if (progress == null) {
727 if (!downloadItem.getDownloadInfo().isPaused()) { 731 if (!downloadItem.getDownloadInfo().isPaused()) {
728 long startTime = System.currentTimeMillis(); 732 long startTime = System.currentTimeMillis();
729 progress = new DownloadProgress( 733 progress = new DownloadProgress(
730 startTime, isActiveNetworkMetered(mContext), downloadIte m, downloadStatus); 734 startTime, isActiveNetworkMetered(mContext), downloadIte m, downloadStatus);
731 progress.mIsUpdated = true; 735 progress.mIsUpdated = true;
732 progress.mIsSupportedMimeType = isSupportedMimeType; 736 progress.mIsSupportedMimeType = isSupportedMimeType;
733 mDownloadProgressMap.put(id, progress); 737 mDownloadProgressMap.put(id, progress);
734 if (getUmaStatsEntry(downloadItem.getId()) == null) { 738 DownloadUmaStatsEntry entry = getUmaStatsEntry(downloadItem.getI d());
739 if (entry == null) {
735 addUmaStatsEntry(new DownloadUmaStatsEntry( 740 addUmaStatsEntry(new DownloadUmaStatsEntry(
736 downloadItem.getId(), startTime, 0, false, false)); 741 downloadItem.getId(), startTime, 0, false, false, by tesReceived, 0));
742 } else if (updateBytesReceived(entry, bytesReceived)) {
743 storeUmaEntries();
737 } 744 }
738 } 745 }
739 return; 746 return;
740 } 747 }
741 748
742 progress.mDownloadStatus = downloadStatus; 749 progress.mDownloadStatus = downloadStatus;
743 progress.mDownloadItem = downloadItem; 750 progress.mDownloadItem = downloadItem;
744 progress.mIsUpdated = true; 751 progress.mIsUpdated = true;
745 progress.mIsAutoResumable = mAutoResumableDownloadIds.contains(id); 752 progress.mIsAutoResumable = mAutoResumableDownloadIds.contains(id);
746 progress.mIsSupportedMimeType = isSupportedMimeType; 753 progress.mIsSupportedMimeType = isSupportedMimeType;
747 DownloadUmaStatsEntry entry; 754 DownloadUmaStatsEntry entry;
748 switch (downloadStatus) { 755 switch (downloadStatus) {
749 case DOWNLOAD_STATUS_COMPLETE: 756 case DOWNLOAD_STATUS_COMPLETE:
750 case DOWNLOAD_STATUS_FAILED: 757 case DOWNLOAD_STATUS_FAILED:
751 case DOWNLOAD_STATUS_CANCELLED: 758 case DOWNLOAD_STATUS_CANCELLED:
752 recordDownloadFinishedUMA(downloadStatus, downloadItem.getId(), 759 recordDownloadFinishedUMA(downloadStatus, downloadItem.getId(),
753 downloadItem.getDownloadInfo().getBytesReceived()); 760 downloadItem.getDownloadInfo().getBytesReceived());
754 break; 761 break;
755 case DOWNLOAD_STATUS_INTERRUPTED: 762 case DOWNLOAD_STATUS_INTERRUPTED:
756 entry = getUmaStatsEntry(downloadItem.getId()); 763 entry = getUmaStatsEntry(downloadItem.getId());
757 entry.numInterruptions++; 764 entry.numInterruptions++;
765 updateBytesReceived(entry, bytesReceived);
758 storeUmaEntries(); 766 storeUmaEntries();
759 break; 767 break;
760 case DOWNLOAD_STATUS_IN_PROGRESS: 768 case DOWNLOAD_STATUS_IN_PROGRESS:
761 entry = getUmaStatsEntry(downloadItem.getId()); 769 entry = getUmaStatsEntry(downloadItem.getId());
762 if (entry.isPaused != downloadItem.getDownloadInfo().isPaused()) { 770 if (entry.isPaused != downloadItem.getDownloadInfo().isPaused()
771 || updateBytesReceived(entry, bytesReceived)) {
763 entry.isPaused = downloadItem.getDownloadInfo().isPaused(); 772 entry.isPaused = downloadItem.getDownloadInfo().isPaused();
764 storeUmaEntries(); 773 storeUmaEntries();
765 } 774 }
766 break; 775 break;
767 default: 776 default:
768 assert false; 777 assert false;
769 } 778 }
770 } 779 }
771 780
772 /** 781 /**
782 * Helper method to update the received bytes and wasted bytes for UMA repor ting.
783 * @param entry UMA entry to update.
784 * @param bytesReceived The current received bytes.
785 * @return true if the UMA stats is updated, or false otherwise.
786 */
787 private boolean updateBytesReceived(DownloadUmaStatsEntry entry, long bytesR eceived) {
788 if (bytesReceived == UNKNOWN_BYTES_RECEIVED || bytesReceived == entry.la stBytesReceived) {
789 return false;
790 }
791 if (bytesReceived < entry.lastBytesReceived) {
792 entry.bytesWasted += entry.lastBytesReceived - bytesReceived;
793 }
794 entry.lastBytesReceived = bytesReceived;
795 return true;
796 }
797 /**
773 * Sets the download handler for OMA downloads, for testing purpose. 798 * Sets the download handler for OMA downloads, for testing purpose.
774 * 799 *
775 * @param omaDownloadHandler Download handler for OMA contents. 800 * @param omaDownloadHandler Download handler for OMA contents.
776 */ 801 */
777 @VisibleForTesting 802 @VisibleForTesting
778 protected void setOMADownloadHandler(OMADownloadHandler omaDownloadHandler) { 803 protected void setOMADownloadHandler(OMADownloadHandler omaDownloadHandler) {
779 mOMADownloadHandler = omaDownloadHandler; 804 mOMADownloadHandler = omaDownloadHandler;
780 } 805 }
781 806
782 @Override 807 @Override
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 } 938 }
914 return true; 939 return true;
915 } 940 }
916 941
917 @Override 942 @Override
918 protected void onPostExecute(Boolean result) { 943 protected void onPostExecute(Boolean result) {
919 boolean isPendingOMADownload = mOMADownloadHandler.isPendingOMADownl oad( 944 boolean isPendingOMADownload = mOMADownloadHandler.isPendingOMADownl oad(
920 mDownloadItem.getSystemDownloadId()); 945 mDownloadItem.getSystemDownloadId());
921 if (!result) { 946 if (!result) {
922 onDownloadFailed(mDownloadItem.getDownloadInfo().getFileName(), mFailureReason); 947 onDownloadFailed(mDownloadItem.getDownloadInfo().getFileName(), mFailureReason);
923 recordDownloadCompletionStats(true, DOWNLOAD_STATUS_FAILED, 0, 0 , 0); 948 recordDownloadCompletionStats(true, DOWNLOAD_STATUS_FAILED, 0, 0 , 0, 0);
924 if (isPendingOMADownload) { 949 if (isPendingOMADownload) {
925 mOMADownloadHandler.onDownloadFailed( 950 mOMADownloadHandler.onDownloadFailed(
926 mDownloadItem.getDownloadInfo(), mDownloadItem.getSy stemDownloadId(), 951 mDownloadItem.getDownloadInfo(), mDownloadItem.getSy stemDownloadId(),
927 DownloadManager.ERROR_UNKNOWN, null); 952 DownloadManager.ERROR_UNKNOWN, null);
928 } 953 }
929 return; 954 return;
930 } 955 }
931 DownloadUtils.showDownloadStartToast(mContext); 956 DownloadUtils.showDownloadStartToast(mContext);
932 if (isPendingOMADownload) { 957 if (isPendingOMADownload) {
933 // A new downloadId is generated, needs to update the OMADownloa dHandler 958 // A new downloadId is generated, needs to update the OMADownloa dHandler
934 // about this. 959 // about this.
935 mOMADownloadHandler.updateDownloadInfo( 960 mOMADownloadHandler.updateDownloadInfo(
936 mDownloadItem.getSystemDownloadId(), mDownloadId); 961 mDownloadItem.getSystemDownloadId(), mDownloadId);
937 // TODO(qinmin): use a file instead of shared prefs to save the 962 // TODO(qinmin): use a file instead of shared prefs to save the
938 // OMA information in case chrome is killed. This will allow us to 963 // OMA information in case chrome is killed. This will allow us to
939 // save more information like cookies and user agent. 964 // save more information like cookies and user agent.
940 String notifyUri = mOMADownloadHandler.getInstallNotifyInfo(mDow nloadId); 965 String notifyUri = mOMADownloadHandler.getInstallNotifyInfo(mDow nloadId);
941 if (!TextUtils.isEmpty(notifyUri)) { 966 if (!TextUtils.isEmpty(notifyUri)) {
942 OMAEntry entry = new OMAEntry(mDownloadId, notifyUri); 967 OMAEntry entry = new OMAEntry(mDownloadId, notifyUri);
943 addOMADownloadToSharedPrefs(entry.generateSharedPrefsString( )); 968 addOMADownloadToSharedPrefs(entry.generateSharedPrefsString( ));
944 } 969 }
945 } 970 }
946 if (mSystemDownloadIdMap.size() == 0) { 971 if (mSystemDownloadIdMap.size() == 0) {
947 mContext.registerReceiver(DownloadManagerService.this, 972 mContext.registerReceiver(DownloadManagerService.this,
948 new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLET E)); 973 new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLET E));
949 } 974 }
950 addUmaStatsEntry(new DownloadUmaStatsEntry( 975 addUmaStatsEntry(new DownloadUmaStatsEntry(
951 String.valueOf(mDownloadId), mStartTime, 0, false, true)); 976 String.valueOf(mDownloadId), mStartTime, 0, false, true, 0, 0));
952 mDownloadItem.setSystemDownloadId(mDownloadId); 977 mDownloadItem.setSystemDownloadId(mDownloadId);
953 mDownloadItem.setStartTime(mStartTime); 978 mDownloadItem.setStartTime(mStartTime);
954 mSystemDownloadIdMap.put(mDownloadId, mDownloadItem); 979 mSystemDownloadIdMap.put(mDownloadId, mDownloadItem);
955 } 980 }
956 } 981 }
957 982
958 /** 983 /**
959 * Determines if the download should be immediately opened after 984 * Determines if the download should be immediately opened after
960 * downloading. 985 * downloading.
961 * 986 *
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 @Override 1189 @Override
1165 public void pauseDownload(String downloadGuid, boolean isOffTheRecord) { 1190 public void pauseDownload(String downloadGuid, boolean isOffTheRecord) {
1166 nativePauseDownload(getNativeDownloadManagerService(), downloadGuid, isO ffTheRecord); 1191 nativePauseDownload(getNativeDownloadManagerService(), downloadGuid, isO ffTheRecord);
1167 DownloadProgress progress = mDownloadProgressMap.get(downloadGuid); 1192 DownloadProgress progress = mDownloadProgressMap.get(downloadGuid);
1168 // Calling pause will stop listening to the download item. Update its pr ogress now. 1193 // Calling pause will stop listening to the download item. Update its pr ogress now.
1169 // If download is already completed, canceled or failed, there is no nee d to update the 1194 // If download is already completed, canceled or failed, there is no nee d to update the
1170 // download notification. 1195 // download notification.
1171 if (progress != null && (progress.mDownloadStatus == DOWNLOAD_STATUS_INT ERRUPTED 1196 if (progress != null && (progress.mDownloadStatus == DOWNLOAD_STATUS_INT ERRUPTED
1172 || progress.mDownloadStatus == DOWNLOAD_STATUS_IN_PROGRESS)) { 1197 || progress.mDownloadStatus == DOWNLOAD_STATUS_IN_PROGRESS)) {
1173 DownloadInfo info = DownloadInfo.Builder.fromDownloadInfo( 1198 DownloadInfo info = DownloadInfo.Builder.fromDownloadInfo(
1174 progress.mDownloadItem.getDownloadInfo()).setIsPaused(true). build(); 1199 progress.mDownloadItem.getDownloadInfo()).setIsPaused(true)
1200 .setBytesReceived(UNKNOWN_BYTES_RECEIVED).build();
1175 onDownloadUpdated(info); 1201 onDownloadUpdated(info);
1176 } 1202 }
1177 } 1203 }
1178 1204
1179 @Override 1205 @Override
1180 public void destroyServiceDelegate() { 1206 public void destroyServiceDelegate() {
1181 // Lifecycle of DownloadManagerService allows for this call to be ignore d. 1207 // Lifecycle of DownloadManagerService allows for this call to be ignore d.
1182 } 1208 }
1183 1209
1184 /** 1210 /**
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1297
1272 /** 1298 /**
1273 * Helper method to record the metrics when a download completes. 1299 * Helper method to record the metrics when a download completes.
1274 * @param useDownloadManager Whether the download goes through Android Downl oadManager. 1300 * @param useDownloadManager Whether the download goes through Android Downl oadManager.
1275 * @param status Download completion status. 1301 * @param status Download completion status.
1276 * @param totalDuration Total time in milliseconds to download the file. 1302 * @param totalDuration Total time in milliseconds to download the file.
1277 * @param bytesDownloaded Total bytes downloaded. 1303 * @param bytesDownloaded Total bytes downloaded.
1278 * @param numInterruptions Number of interruptions during the download. 1304 * @param numInterruptions Number of interruptions during the download.
1279 */ 1305 */
1280 private void recordDownloadCompletionStats(boolean useDownloadManager, int s tatus, 1306 private void recordDownloadCompletionStats(boolean useDownloadManager, int s tatus,
1281 long totalDuration, long bytesDownloaded, int numInterruptions) { 1307 long totalDuration, long bytesDownloaded, int numInterruptions, long bytesWasted) {
1282 switch (status) { 1308 switch (status) {
1283 case DOWNLOAD_STATUS_COMPLETE: 1309 case DOWNLOAD_STATUS_COMPLETE:
1284 if (useDownloadManager) { 1310 if (useDownloadManager) {
1285 RecordHistogram.recordLongTimesHistogram( 1311 RecordHistogram.recordLongTimesHistogram(
1286 "MobileDownload.DownloadTime.DownloadManager.Success ", 1312 "MobileDownload.DownloadTime.DownloadManager.Success ",
1287 totalDuration, TimeUnit.MILLISECONDS); 1313 totalDuration, TimeUnit.MILLISECONDS);
1288 RecordHistogram.recordCount1000Histogram( 1314 RecordHistogram.recordCount1000Histogram(
1289 "MobileDownload.BytesDownloaded.DownloadManager.Succ ess", 1315 "MobileDownload.BytesDownloaded.DownloadManager.Succ ess",
1290 (int) (bytesDownloaded / 1024)); 1316 (int) (bytesDownloaded / 1024));
1291 } else { 1317 } else {
1292 RecordHistogram.recordLongTimesHistogram( 1318 RecordHistogram.recordLongTimesHistogram(
1293 "MobileDownload.DownloadTime.ChromeNetworkStack.Succ ess", 1319 "MobileDownload.DownloadTime.ChromeNetworkStack.Succ ess",
1294 totalDuration, TimeUnit.MILLISECONDS); 1320 totalDuration, TimeUnit.MILLISECONDS);
1295 RecordHistogram.recordCount1000Histogram( 1321 RecordHistogram.recordCount1000Histogram(
1296 "MobileDownload.BytesDownloaded.ChromeNetworkStack.S uccess", 1322 "MobileDownload.BytesDownloaded.ChromeNetworkStack.S uccess",
1297 (int) (bytesDownloaded / 1024)); 1323 (int) (bytesDownloaded / 1024));
1298 RecordHistogram.recordCountHistogram( 1324 RecordHistogram.recordCountHistogram(
1299 "MobileDownload.InterruptionsCount.ChromeNetworkStac k.Success", 1325 "MobileDownload.InterruptionsCount.ChromeNetworkStac k.Success",
1300 numInterruptions); 1326 numInterruptions);
1327 recordBytesWasted(
1328 "MobileDownload.BytesWasted.ChromeNetworkStack.Succe ss", bytesWasted);
1301 } 1329 }
1302 break; 1330 break;
1303 case DOWNLOAD_STATUS_FAILED: 1331 case DOWNLOAD_STATUS_FAILED:
1304 if (useDownloadManager) { 1332 if (useDownloadManager) {
1305 RecordHistogram.recordLongTimesHistogram( 1333 RecordHistogram.recordLongTimesHistogram(
1306 "MobileDownload.DownloadTime.DownloadManager.Failure ", 1334 "MobileDownload.DownloadTime.DownloadManager.Failure ",
1307 totalDuration, TimeUnit.MILLISECONDS); 1335 totalDuration, TimeUnit.MILLISECONDS);
1308 RecordHistogram.recordCount1000Histogram( 1336 RecordHistogram.recordCount1000Histogram(
1309 "MobileDownload.BytesDownloaded.DownloadManager.Fail ure", 1337 "MobileDownload.BytesDownloaded.DownloadManager.Fail ure",
1310 (int) (bytesDownloaded / 1024)); 1338 (int) (bytesDownloaded / 1024));
1311 } else { 1339 } else {
1312 RecordHistogram.recordLongTimesHistogram( 1340 RecordHistogram.recordLongTimesHistogram(
1313 "MobileDownload.DownloadTime.ChromeNetworkStack.Fail ure", 1341 "MobileDownload.DownloadTime.ChromeNetworkStack.Fail ure",
1314 totalDuration, TimeUnit.MILLISECONDS); 1342 totalDuration, TimeUnit.MILLISECONDS);
1315 RecordHistogram.recordCount1000Histogram( 1343 RecordHistogram.recordCount1000Histogram(
1316 "MobileDownload.BytesDownloaded.ChromeNetworkStack.F ailure", 1344 "MobileDownload.BytesDownloaded.ChromeNetworkStack.F ailure",
1317 (int) (bytesDownloaded / 1024)); 1345 (int) (bytesDownloaded / 1024));
1318 RecordHistogram.recordCountHistogram( 1346 RecordHistogram.recordCountHistogram(
1319 "MobileDownload.InterruptionsCount.ChromeNetworkStac k.Failure", 1347 "MobileDownload.InterruptionsCount.ChromeNetworkStac k.Failure",
1320 numInterruptions); 1348 numInterruptions);
1349 recordBytesWasted(
1350 "MobileDownload.BytesWasted.ChromeNetworkStack.Failu re", bytesWasted);
1321 } 1351 }
1322 break; 1352 break;
1323 case DOWNLOAD_STATUS_CANCELLED: 1353 case DOWNLOAD_STATUS_CANCELLED:
1324 if (!useDownloadManager) { 1354 if (!useDownloadManager) {
1325 RecordHistogram.recordLongTimesHistogram( 1355 RecordHistogram.recordLongTimesHistogram(
1326 "MobileDownload.DownloadTime.ChromeNetworkStack.Canc el", 1356 "MobileDownload.DownloadTime.ChromeNetworkStack.Canc el",
1327 totalDuration, TimeUnit.MILLISECONDS); 1357 totalDuration, TimeUnit.MILLISECONDS);
1328 RecordHistogram.recordCountHistogram( 1358 RecordHistogram.recordCountHistogram(
1329 "MobileDownload.InterruptionsCount.ChromeNetworkStac k.Cancel", 1359 "MobileDownload.InterruptionsCount.ChromeNetworkStac k.Cancel",
1330 numInterruptions); 1360 numInterruptions);
1361 recordBytesWasted(
1362 "MobileDownload.BytesWasted.ChromeNetworkStack.Cance l", bytesWasted);
1331 } 1363 }
1332 break; 1364 break;
1333 default: 1365 default:
1334 break; 1366 break;
1335 } 1367 }
1336 } 1368 }
1337 1369
1370 /**
1371 * Helper method to record the bytes wasted metrics when a download complete s.
1372 * @param name Histogram name
1373 * @param bytesWasted Bytes wasted during download.
1374 */
1375 private void recordBytesWasted(String name, long bytesWasted) {
1376 RecordHistogram.recordCustomCountHistogram(
1377 name, (int) (bytesWasted / 1024), 1, GB_IN_KILO_BYTES, 50);
1378 }
1379
1338 @Override 1380 @Override
1339 public void onQueryCompleted( 1381 public void onQueryCompleted(
1340 DownloadManagerDelegate.DownloadQueryResult result, boolean showNoti fication) { 1382 DownloadManagerDelegate.DownloadQueryResult result, boolean showNoti fication) {
1341 if (result.downloadStatus == DOWNLOAD_STATUS_IN_PROGRESS) return; 1383 if (result.downloadStatus == DOWNLOAD_STATUS_IN_PROGRESS) return;
1342 if (showNotification) { 1384 if (showNotification) {
1343 switch (result.downloadStatus) { 1385 switch (result.downloadStatus) {
1344 case DOWNLOAD_STATUS_COMPLETE: 1386 case DOWNLOAD_STATUS_COMPLETE:
1345 if (shouldOpenAfterDownload(result.item.getDownloadInfo()) 1387 if (shouldOpenAfterDownload(result.item.getDownloadInfo())
1346 && result.canResolve) { 1388 && result.canResolve) {
1347 handleAutoOpenAfterDownload(result.item); 1389 handleAutoOpenAfterDownload(result.item);
1348 } else { 1390 } else {
1349 mDownloadSnackbarController.onDownloadSucceeded( 1391 mDownloadSnackbarController.onDownloadSucceeded(
1350 result.item.getDownloadInfo(), 1392 result.item.getDownloadInfo(),
1351 DownloadSnackbarController.INVALID_NOTIFICATION_ ID, 1393 DownloadSnackbarController.INVALID_NOTIFICATION_ ID,
1352 result.item.getSystemDownloadId(), result.canRes olve); 1394 result.item.getSystemDownloadId(), result.canRes olve);
1353 } 1395 }
1354 break; 1396 break;
1355 case DOWNLOAD_STATUS_FAILED: 1397 case DOWNLOAD_STATUS_FAILED:
1356 onDownloadFailed( 1398 onDownloadFailed(
1357 result.item.getDownloadInfo().getFileName(), result. failureReason); 1399 result.item.getDownloadInfo().getFileName(), result. failureReason);
1358 break; 1400 break;
1359 default: 1401 default:
1360 break; 1402 break;
1361 } 1403 }
1362 } 1404 }
1363 recordDownloadCompletionStats(true, result.downloadStatus, 1405 recordDownloadCompletionStats(true, result.downloadStatus,
1364 result.downloadTimeInMilliseconds, result.bytesDownloaded, 0); 1406 result.downloadTimeInMilliseconds, result.bytesDownloaded, 0, 0) ;
1365 removeUmaStatsEntry(result.item.getId()); 1407 removeUmaStatsEntry(result.item.getId());
1366 } 1408 }
1367 1409
1368 /** 1410 /**
1369 * Called by tests to disable listening to network connection changes. 1411 * Called by tests to disable listening to network connection changes.
1370 */ 1412 */
1371 @VisibleForTesting 1413 @VisibleForTesting
1372 static void disableNetworkListenerForTest() { 1414 static void disableNetworkListenerForTest() {
1373 sIsNetworkListenerDisabled = true; 1415 sIsNetworkListenerDisabled = true;
1374 } 1416 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 /** 1560 /**
1519 * Helper method to record the download completion UMA and remove the Shared Preferences entry. 1561 * Helper method to record the download completion UMA and remove the Shared Preferences entry.
1520 */ 1562 */
1521 private void recordDownloadFinishedUMA( 1563 private void recordDownloadFinishedUMA(
1522 int downloadStatus, String entryId, long bytesDownloaded) { 1564 int downloadStatus, String entryId, long bytesDownloaded) {
1523 DownloadUmaStatsEntry entry = getUmaStatsEntry(entryId); 1565 DownloadUmaStatsEntry entry = getUmaStatsEntry(entryId);
1524 if (entry == null) return; 1566 if (entry == null) return;
1525 long currentTime = System.currentTimeMillis(); 1567 long currentTime = System.currentTimeMillis();
1526 long totalTime = Math.max(0, currentTime - entry.downloadStartTime); 1568 long totalTime = Math.max(0, currentTime - entry.downloadStartTime);
1527 recordDownloadCompletionStats( 1569 recordDownloadCompletionStats(
1528 false, downloadStatus, totalTime, bytesDownloaded, entry.numInte rruptions); 1570 false, downloadStatus, totalTime, bytesDownloaded, entry.numInte rruptions,
1571 entry.bytesWasted);
1529 removeUmaStatsEntry(entryId); 1572 removeUmaStatsEntry(entryId);
1530 } 1573 }
1531 1574
1532 /** 1575 /**
1533 * Parse the DownloadUmaStatsEntry from the shared preference. 1576 * Parse the DownloadUmaStatsEntry from the shared preference.
1534 */ 1577 */
1535 private void parseUMAStatsEntriesFromSharedPrefs() { 1578 private void parseUMAStatsEntriesFromSharedPrefs() {
1536 if (mSharedPrefs.contains(DOWNLOAD_UMA_ENTRY)) { 1579 if (mSharedPrefs.contains(DOWNLOAD_UMA_ENTRY)) {
1537 Set<String> entries = 1580 Set<String> entries =
1538 DownloadManagerService.getStoredDownloadInfo(mSharedPrefs, D OWNLOAD_UMA_ENTRY); 1581 DownloadManagerService.getStoredDownloadInfo(mSharedPrefs, D OWNLOAD_UMA_ENTRY);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 boolean isNotificationDismissed); 1744 boolean isNotificationDismissed);
1702 private native void nativePauseDownload(long nativeDownloadManagerService, S tring downloadGuid, 1745 private native void nativePauseDownload(long nativeDownloadManagerService, S tring downloadGuid,
1703 boolean isOffTheRecord); 1746 boolean isOffTheRecord);
1704 private native void nativeRemoveDownload(long nativeDownloadManagerService, String downloadGuid, 1747 private native void nativeRemoveDownload(long nativeDownloadManagerService, String downloadGuid,
1705 boolean isOffTheRecord); 1748 boolean isOffTheRecord);
1706 private native void nativeGetAllDownloads( 1749 private native void nativeGetAllDownloads(
1707 long nativeDownloadManagerService, boolean isOffTheRecord); 1750 long nativeDownloadManagerService, boolean isOffTheRecord);
1708 private native void nativeCheckForExternallyRemovedDownloads( 1751 private native void nativeCheckForExternallyRemovedDownloads(
1709 long nativeDownloadManagerService, boolean isOffTheRecord); 1752 long nativeDownloadManagerService, boolean isOffTheRecord);
1710 } 1753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698