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

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

Issue 2729623007: Don't cancel download when dismissing the notification (Closed)
Patch Set: rebase Created 3 years, 9 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.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.app.DownloadManager; 8 import android.app.DownloadManager;
9 import android.app.Notification; 9 import android.app.Notification;
10 import android.app.NotificationManager; 10 import android.app.NotificationManager;
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 boolean cancelActualDownload = LibraryLoader.isInitialized() 354 boolean cancelActualDownload = LibraryLoader.isInitialized()
355 && Profile.getLastUsedProfile().hasOffTheRecordProfile(); 355 && Profile.getLastUsedProfile().hasOffTheRecordProfile();
356 356
357 List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceH elper.getEntries(); 357 List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceH elper.getEntries();
358 for (DownloadSharedPreferenceEntry entry : entries) { 358 for (DownloadSharedPreferenceEntry entry : entries) {
359 if (!entry.isOffTheRecord) continue; 359 if (!entry.isOffTheRecord) continue;
360 360
361 notifyDownloadCanceled(entry.downloadGuid); 361 notifyDownloadCanceled(entry.downloadGuid);
362 if (cancelActualDownload) { 362 if (cancelActualDownload) {
363 DownloadServiceDelegate delegate = getServiceDelegate(entry.item Type); 363 DownloadServiceDelegate delegate = getServiceDelegate(entry.item Type);
364 delegate.cancelDownload(entry.downloadGuid, entry.isOffTheRecord , false); 364 delegate.cancelDownload(entry.downloadGuid, entry.isOffTheRecord );
365 delegate.destroyServiceDelegate(); 365 delegate.destroyServiceDelegate();
366 } 366 }
367 for (Observer observer : mObservers) observer.onDownloadCanceled(ent ry.downloadGuid); 367 for (Observer observer : mObservers) observer.onDownloadCanceled(ent ry.downloadGuid);
368 } 368 }
369 } 369 }
370 370
371 /** 371 /**
372 * Track in-progress downloads here and, if on an Android version greater or equal to O, make 372 * Track in-progress downloads here and, if on an Android version greater or equal to O, make
373 * this a foreground service. 373 * this a foreground service.
374 * @param downloadGuid The guid of the download that has been started and sh ould be tracked. 374 * @param downloadGuid The guid of the download that has been started and sh ould be tracked.
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 builder.addAction(R.drawable.ic_get_app_white_24dp, 628 builder.addAction(R.drawable.ic_get_app_white_24dp,
629 mContext.getResources().getString(R.string.download_notification _resume_button), 629 mContext.getResources().getString(R.string.download_notification _resume_button),
630 buildPendingIntent(resumeIntent, entry.notificationId)); 630 buildPendingIntent(resumeIntent, entry.notificationId));
631 631
632 Intent cancelIntent = buildActionIntent(mContext, ACTION_DOWNLOAD_CANCEL , 632 Intent cancelIntent = buildActionIntent(mContext, ACTION_DOWNLOAD_CANCEL ,
633 entry.downloadGuid, entry.isOffTheRecord, entry.isOfflinePage()) ; 633 entry.downloadGuid, entry.isOffTheRecord, entry.isOfflinePage()) ;
634 builder.addAction(R.drawable.btn_close_white, 634 builder.addAction(R.drawable.btn_close_white,
635 mContext.getResources().getString(R.string.download_notification _cancel_button), 635 mContext.getResources().getString(R.string.download_notification _cancel_button),
636 buildPendingIntent(cancelIntent, entry.notificationId)); 636 buildPendingIntent(cancelIntent, entry.notificationId));
637 637
638 Intent dismissIntent = new Intent(cancelIntent);
639 dismissIntent.putExtra(EXTRA_NOTIFICATION_DISMISSED, true);
640 builder.setDeleteIntent(buildPendingIntent(dismissIntent, entry.notifica tionId));
641
642 updateNotification(entry.notificationId, builder.build(), downloadGuid, 638 updateNotification(entry.notificationId, builder.build(), downloadGuid,
643 entry.isOfflinePage(), 639 entry.isOfflinePage(),
644 new DownloadSharedPreferenceEntry(entry.notificationId, entry.is OffTheRecord, 640 new DownloadSharedPreferenceEntry(entry.notificationId, entry.is OffTheRecord,
645 entry.canDownloadWhileMetered, entry.downloadGuid, entry .fileName, 641 entry.canDownloadWhileMetered, entry.downloadGuid, entry .fileName,
646 entry.itemType, isAutoResumable)); 642 entry.itemType, isAutoResumable));
647 stopTrackingInProgressDownload(downloadGuid); 643 stopTrackingInProgressDownload(downloadGuid);
648 } 644 }
649 645
650 /** 646 /**
651 * Add a download successful notification. 647 * Add a download successful notification.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 new DownloadSharedPreferenceEntry(entry.notificationId, entr y.isOffTheRecord, 839 new DownloadSharedPreferenceEntry(entry.notificationId, entr y.isOffTheRecord,
844 canDownloadWhileMetered, entry.downloadGuid, entry.f ileName, 840 canDownloadWhileMetered, entry.downloadGuid, entry.f ileName,
845 entry.itemType, true)); 841 entry.itemType, true));
846 } else if (ACTION_DOWNLOAD_RESUME_ALL.equals(intent.getAction()) 842 } else if (ACTION_DOWNLOAD_RESUME_ALL.equals(intent.getAction())
847 && (mDownloadSharedPreferenceHelper.getEntries().isEmpty() 843 && (mDownloadSharedPreferenceHelper.getEntries().isEmpty()
848 || DownloadManagerService.hasDownloadManagerService())) { 844 || DownloadManagerService.hasDownloadManagerService())) {
849 hideSummaryNotificationIfNecessary(); 845 hideSummaryNotificationIfNecessary();
850 return; 846 return;
851 } else if (ACTION_DOWNLOAD_OPEN.equals(intent.getAction())) { 847 } else if (ACTION_DOWNLOAD_OPEN.equals(intent.getAction())) {
852 // TODO(fgorski): Do we even need to do anything special here, befor e we launch Chrome? 848 // TODO(fgorski): Do we even need to do anything special here, befor e we launch Chrome?
849 } else if (ACTION_DOWNLOAD_CANCEL.equals(intent.getAction())
850 && IntentUtils.safeGetBooleanExtra(intent, EXTRA_NOTIFICATION_DI SMISSED, false)) {
851 // User canceled a download by dismissing its notification from earl ier versions, ignore
852 // it. TODO(qinmin): remove this else-if block after M60.
853 return;
853 } 854 }
854 855
855 BrowserParts parts = new EmptyBrowserParts() { 856 BrowserParts parts = new EmptyBrowserParts() {
856 @Override 857 @Override
857 public boolean shouldStartGpuProcess() { 858 public boolean shouldStartGpuProcess() {
858 return false; 859 return false;
859 } 860 }
860 861
861 @Override 862 @Override
862 public void finishNativeInitialization() { 863 public void finishNativeInitialization() {
863 int itemType = entry != null ? entry.itemType 864 int itemType = entry != null ? entry.itemType
864 : (ACTION_DOWNLOAD_OPEN.equals(intent.getAction()) 865 : (ACTION_DOWNLOAD_OPEN.equals(intent.getAction())
865 ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLIN E_PAGE 866 ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLIN E_PAGE
866 : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLO AD); 867 : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLO AD);
867 DownloadServiceDelegate downloadServiceDelegate = 868 DownloadServiceDelegate downloadServiceDelegate =
868 ACTION_DOWNLOAD_OPEN.equals(intent.getAction()) ? null 869 ACTION_DOWNLOAD_OPEN.equals(intent.getAction()) ? null
869 : getServiceDelegate(itemType); 870 : getServiceDelegate(itemType);
870 if (ACTION_DOWNLOAD_CANCEL.equals(intent.getAction())) { 871 if (ACTION_DOWNLOAD_CANCEL.equals(intent.getAction())) {
871 // TODO(qinmin): Alternatively, we can delete the downlo aded content on 872 // TODO(qinmin): Alternatively, we can delete the downlo aded content on
872 // SD card, and remove the download ID from the SharedPr eferences so we 873 // SD card, and remove the download ID from the SharedPr eferences so we
873 // don't need to restart the browser process. http://crb ug.com/579643. 874 // don't need to restart the browser process. http://crb ug.com/579643.
874 cancelNotification(entry.notificationId, entry.downloadG uid); 875 cancelNotification(entry.notificationId, entry.downloadG uid);
875 downloadServiceDelegate.cancelDownload(entry.downloadGui d, 876 downloadServiceDelegate.cancelDownload(entry.downloadGui d,
876 entry.isOffTheRecord, IntentUtils.safeGetBoolean Extra( 877 entry.isOffTheRecord);
877 intent, EXTRA_NOTIFICATION_DISMISSED, fa lse));
878 for (Observer observer : mObservers) { 878 for (Observer observer : mObservers) {
879 observer.onDownloadCanceled(entry.downloadGuid); 879 observer.onDownloadCanceled(entry.downloadGuid);
880 } 880 }
881 } else if (ACTION_DOWNLOAD_PAUSE.equals(intent.getAction())) { 881 } else if (ACTION_DOWNLOAD_PAUSE.equals(intent.getAction())) {
882 downloadServiceDelegate.pauseDownload(entry.downloadGuid , 882 downloadServiceDelegate.pauseDownload(entry.downloadGuid ,
883 entry.isOffTheRecord); 883 entry.isOffTheRecord);
884 } else if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) { 884 } else if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) {
885 notifyDownloadPending(entry.downloadGuid, entry.fileName , 885 notifyDownloadPending(entry.downloadGuid, entry.fileName ,
886 entry.isOffTheRecord, entry.canDownloadWhileMete red, 886 entry.isOffTheRecord, entry.canDownloadWhileMete red,
887 entry.isOfflinePage()); 887 entry.isOfflinePage());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 String downloadGuid = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNL OAD_GUID); 926 String downloadGuid = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNL OAD_GUID);
927 boolean isOffTheRecord = 927 boolean isOffTheRecord =
928 IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFF_THE_RECORD, false); 928 IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFF_THE_RECORD, false);
929 int itemType = IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFFLINE_ PAGE, false) 929 int itemType = IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFFLINE_ PAGE, false)
930 ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE 930 ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE
931 : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD; 931 : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD;
932 if (itemType != DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) return ; 932 if (itemType != DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) return ;
933 933
934 // Pass information directly to the DownloadManagerService. 934 // Pass information directly to the DownloadManagerService.
935 if (TextUtils.equals(action, ACTION_DOWNLOAD_CANCEL)) { 935 if (TextUtils.equals(action, ACTION_DOWNLOAD_CANCEL)) {
936 getServiceDelegate(itemType).cancelDownload(downloadGuid, isOffTheRe cord, false); 936 getServiceDelegate(itemType).cancelDownload(downloadGuid, isOffTheRe cord);
937 } else if (TextUtils.equals(action, ACTION_DOWNLOAD_PAUSE)) { 937 } else if (TextUtils.equals(action, ACTION_DOWNLOAD_PAUSE)) {
938 getServiceDelegate(itemType).pauseDownload(downloadGuid, isOffTheRec ord); 938 getServiceDelegate(itemType).pauseDownload(downloadGuid, isOffTheRec ord);
939 } else if (TextUtils.equals(action, ACTION_DOWNLOAD_RESUME)) { 939 } else if (TextUtils.equals(action, ACTION_DOWNLOAD_RESUME)) {
940 DownloadInfo info = new DownloadInfo.Builder() 940 DownloadInfo info = new DownloadInfo.Builder()
941 .setDownloadGuid(downloadGuid) 941 .setDownloadGuid(downloadGuid)
942 .setIsOffTheRecord(isOffTheRecord) 942 .setIsOffTheRecord(isOffTheRecord)
943 .build(); 943 .build();
944 getServiceDelegate(itemType).resumeDownload(new DownloadItem(false, info), true); 944 getServiceDelegate(itemType).resumeDownload(new DownloadItem(false, info), true);
945 } 945 }
946 } 946 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 return context.getString(R.string.remaining_duration_minutes, minute s); 1097 return context.getString(R.string.remaining_duration_minutes, minute s);
1098 } else if (minutes > 0) { 1098 } else if (minutes > 0) {
1099 return context.getString(R.string.remaining_duration_one_minute); 1099 return context.getString(R.string.remaining_duration_one_minute);
1100 } else if (seconds == 1) { 1100 } else if (seconds == 1) {
1101 return context.getString(R.string.remaining_duration_one_second); 1101 return context.getString(R.string.remaining_duration_one_second);
1102 } else { 1102 } else {
1103 return context.getString(R.string.remaining_duration_seconds, second s); 1103 return context.getString(R.string.remaining_duration_seconds, second s);
1104 } 1104 }
1105 } 1105 }
1106 } 1106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698