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

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

Issue 2795583002: Don't force the download notifier to unbind (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 private static final int STARTING_NOTIFICATION_ID = 1000000; 101 private static final int STARTING_NOTIFICATION_ID = 1000000;
102 private static final int MAX_RESUMPTION_ATTEMPT_LEFT = 5; 102 private static final int MAX_RESUMPTION_ATTEMPT_LEFT = 5;
103 @VisibleForTesting static final long SECONDS_PER_MINUTE = TimeUnit.MINUTES.t oSeconds(1); 103 @VisibleForTesting static final long SECONDS_PER_MINUTE = TimeUnit.MINUTES.t oSeconds(1);
104 @VisibleForTesting static final long SECONDS_PER_HOUR = TimeUnit.HOURS.toSec onds(1); 104 @VisibleForTesting static final long SECONDS_PER_HOUR = TimeUnit.HOURS.toSec onds(1);
105 @VisibleForTesting static final long SECONDS_PER_DAY = TimeUnit.DAYS.toSecon ds(1); 105 @VisibleForTesting static final long SECONDS_PER_DAY = TimeUnit.DAYS.toSecon ds(1);
106 106
107 private static final String KEY_AUTO_RESUMPTION_ATTEMPT_LEFT = "ResumptionAt temptLeft"; 107 private static final String KEY_AUTO_RESUMPTION_ATTEMPT_LEFT = "ResumptionAt temptLeft";
108 private static final String KEY_NEXT_DOWNLOAD_NOTIFICATION_ID = "NextDownloa dNotificationId"; 108 private static final String KEY_NEXT_DOWNLOAD_NOTIFICATION_ID = "NextDownloa dNotificationId";
109 109
110 /** 110 /**
111 * An Observer interface that allows other classes to know when this class w ants to shut itself 111 * An Observer interface that allows other classes to know when this class i s canceling
112 * down. This lets them unbind if necessary. 112 * downloads.
113 */ 113 */
114 public interface Observer { 114 public interface Observer {
115 /** Called when this service is about to start attempting to stop itself . */
116 void onServiceShutdownRequested();
117
118 /** 115 /**
119 * Called when a download was canceled from the notification. The imple menter is not 116 * Called when a download was canceled from the notification. The imple menter is not
120 * responsible for canceling the actual download (that should be trigger ed internally from 117 * responsible for canceling the actual download (that should be trigger ed internally from
121 * this class). The implementer is responsible for using this to do the ir own tracking 118 * this class). The implementer is responsible for using this to do the ir own tracking
122 * related to which downloads might be active in this service. File dow nloads don't trigger 119 * related to which downloads might be active in this service. File dow nloads don't trigger
123 * a cancel event when they are told to cancel downloads, so classes mig ht have no idea that 120 * a cancel event when they are told to cancel downloads, so classes mig ht have no idea that
124 * a download stopped otherwise. 121 * a download stopped otherwise.
125 * @param guid The guid of the download that was canceled. 122 * @param guid The guid of the download that was canceled.
126 */ 123 */
127 void onDownloadCanceled(String guid); 124 void onDownloadCanceled(String guid);
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // NotificationManager. The notification is not bound to this s ervice, so any call 632 // NotificationManager. The notification is not bound to this s ervice, so any call
636 // to stopForeground() won't affect the notification. 633 // to stopForeground() won't affect the notification.
637 cancelSummaryNotification(); 634 cancelSummaryNotification();
638 } 635 }
639 } else { 636 } else {
640 // If we don't have a valid summary, just guarantee that we aren't i n the foreground for 637 // If we don't have a valid summary, just guarantee that we aren't i n the foreground for
641 // safety. 638 // safety.
642 stopForegroundInternal(false); 639 stopForegroundInternal(false);
643 } 640 }
644 641
645 // Notify all observers that we are requesting a chance to shut down. T his will let any
646 // observers unbind from us if necessary.
647 for (Observer observer : mObservers) observer.onServiceShutdownRequested ();
648
649 // Stop the service which should start the destruction process. At this point we should be 642 // Stop the service which should start the destruction process. At this point we should be
650 // (1) a background service and (2) unbound from any clients. 643 // a background service. We might not be unbound from any clients. Whe n they unbind we
644 // will shut down. That is okay because they will only unbind from us w hen they are ok with
645 // us going away (e.g. we shouldn't be unbound while in the foreground).
651 stopSelf(); 646 stopSelf();
652 return true; 647 return true;
653 } 648 }
654 649
655 @Override 650 @Override
656 public IBinder onBind(Intent intent) { 651 public IBinder onBind(Intent intent) {
657 return mBinder; 652 return mBinder;
658 } 653 }
659 654
660 /** 655 /**
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 return context.getString(R.string.remaining_duration_minutes, minute s); 1363 return context.getString(R.string.remaining_duration_minutes, minute s);
1369 } else if (minutes > 0) { 1364 } else if (minutes > 0) {
1370 return context.getString(R.string.remaining_duration_one_minute); 1365 return context.getString(R.string.remaining_duration_one_minute);
1371 } else if (seconds == 1) { 1366 } else if (seconds == 1) {
1372 return context.getString(R.string.remaining_duration_one_second); 1367 return context.getString(R.string.remaining_duration_one_second);
1373 } else { 1368 } else {
1374 return context.getString(R.string.remaining_duration_seconds, second s); 1369 return context.getString(R.string.remaining_duration_seconds, second s);
1375 } 1370 }
1376 } 1371 }
1377 } 1372 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698