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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java

Issue 2058593002: Add UMA for studying download cancellation reasons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
index a049b680e2432d4f210e83b7fd83643878688971..f4add7f517b2058bff4411ab3e8afde0dab96c1a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
@@ -46,6 +46,7 @@ public class DownloadNotificationService extends Service {
static final String EXTRA_DOWNLOAD_NOTIFICATION_ID = "DownloadNotificationId";
static final String EXTRA_DOWNLOAD_GUID = "DownloadGuid";
static final String EXTRA_DOWNLOAD_FILE_NAME = "DownloadFileName";
+ static final String EXTRA_NOTIFICATION_DISMISSED = "NotificationDismissed";
static final String ACTION_DOWNLOAD_CANCEL =
"org.chromium.chrome.browser.download.DOWNLOAD_CANCEL";
static final String ACTION_DOWNLOAD_PAUSE =
@@ -162,12 +163,13 @@ public class DownloadNotificationService extends Service {
if (startTime > 0) builder.setWhen(startTime);
builder.addAction(R.drawable.bookmark_cancel_active,
mContext.getResources().getString(R.string.download_notification_cancel_button),
- buildPendingIntent(ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName));
+ buildPendingIntent(ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName,
+ false));
if (isResumable) {
builder.addAction(R.drawable.ic_vidcontrol_pause,
mContext.getResources().getString(R.string.download_notification_pause_button),
buildPendingIntent(ACTION_DOWNLOAD_PAUSE, notificationId, downloadGuid,
- fileName));
+ fileName, false));
}
updateNotification(notificationId, builder.build());
}
@@ -215,8 +217,10 @@ public class DownloadNotificationService extends Service {
android.R.drawable.ic_media_pause, entry.fileName,
mContext.getResources().getString(R.string.download_notification_paused));
PendingIntent cancelIntent = buildPendingIntent(ACTION_DOWNLOAD_CANCEL,
- entry.notificationId, entry.downloadGuid, entry.fileName);
- builder.setDeleteIntent(cancelIntent);
+ entry.notificationId, entry.downloadGuid, entry.fileName, false);
+ PendingIntent dismissIntent = buildPendingIntent(ACTION_DOWNLOAD_CANCEL,
+ entry.notificationId, entry.downloadGuid, entry.fileName, true);
+ builder.setDeleteIntent(dismissIntent);
builder.addAction(R.drawable.bookmark_cancel_active,
mContext.getResources().getString(R.string.download_notification_cancel_button),
cancelIntent);
@@ -225,7 +229,7 @@ public class DownloadNotificationService extends Service {
mContext.getResources().getString(
R.string.download_notification_resume_button),
buildPendingIntent(ACTION_DOWNLOAD_RESUME, entry.notificationId,
- entry.downloadGuid, entry.fileName));
+ entry.downloadGuid, entry.fileName, false));
}
updateNotification(entry.notificationId, builder.build());
// If download is not auto resumable, there is no need to keep it in SharedPreferences.
@@ -289,8 +293,17 @@ public class DownloadNotificationService extends Service {
}
}
+ /**
+ * Helper method to build a PendingIntent from the provided information.
+ * @param action Download action to perform.
+ * @param notificationId ID of the notification.
+ * @param downloadGuid GUID of the download.
+ * @param fileName Name of the download file.
+ * @param isNotificationDismissed Whether the intent is from dismissing the notification.
+ */
private PendingIntent buildPendingIntent(
- String action, int notificationId, String downloadGuid, String fileName) {
+ String action, int notificationId, String downloadGuid, String fileName,
+ boolean isNotificationDismissed) {
ComponentName component = new ComponentName(
mContext.getPackageName(), DownloadBroadcastReceiver.class.getName());
Intent intent = new Intent(action);
@@ -298,6 +311,7 @@ public class DownloadNotificationService extends Service {
intent.putExtra(EXTRA_DOWNLOAD_NOTIFICATION_ID, notificationId);
intent.putExtra(EXTRA_DOWNLOAD_GUID, downloadGuid);
intent.putExtra(EXTRA_DOWNLOAD_FILE_NAME, fileName);
+ intent.putExtra(EXTRA_NOTIFICATION_DISMISSED, isNotificationDismissed);
return PendingIntent.getBroadcast(
mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@@ -373,7 +387,8 @@ public class DownloadNotificationService extends Service {
// SD card, and remove the download ID from the SharedPreferences so we
// don't need to restart the browser process. http://crbug.com/579643.
cancelNotification(notificationId, guid);
- service.cancelDownload(guid);
+ service.cancelDownload(guid, IntentUtils.safeGetBooleanExtra(
+ intent, EXTRA_NOTIFICATION_DISMISSED, false));
break;
case ACTION_DOWNLOAD_PAUSE:
service.pauseDownload(guid);

Powered by Google App Engine
This is Rietveld 408576698