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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.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 | « chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java ('k') | no next file » | 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.content.ComponentName; 7 import android.content.ComponentName;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.ServiceConnection; 10 import android.content.ServiceConnection;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 mBoundService = service; 106 mBoundService = service;
107 } 107 }
108 108
109 /** 109 /**
110 * Handles all the pending notifications that hasn't been processed. 110 * Handles all the pending notifications that hasn't been processed.
111 */ 111 */
112 @VisibleForTesting 112 @VisibleForTesting
113 void handlePendingNotifications() { 113 void handlePendingNotifications() {
114 if (mPendingNotifications.isEmpty()) return; 114 if (mPendingNotifications.isEmpty()) return;
115 for (int i = 0; i < mPendingNotifications.size(); i++) { 115 for (int i = 0; i < mPendingNotifications.size(); i++) {
116 // If we lose the service mid-loop retrigger the service load and qu it.
117 if (mBoundService == null) {
118 startAndBindToServiceIfNeeded();
119 return;
120 }
121 updateDownloadNotification( 116 updateDownloadNotification(
122 mPendingNotifications.get(i), i == mPendingNotifications.siz e() - 1); 117 mPendingNotifications.get(i), i == mPendingNotifications.siz e() - 1);
123 } 118 }
124 mPendingNotifications.clear(); 119 mPendingNotifications.clear();
125 } 120 }
126 121
127 /** 122 /**
128 * Starts and binds to the download notification service if needed. 123 * Starts and binds to the download notification service if needed.
129 */ 124 */
130 private void startAndBindToServiceIfNeeded() { 125 private void startAndBindToServiceIfNeeded() {
(...skipping 20 matching lines...) Expand all
151 new Intent(mApplicationContext, DownloadNotificationService.clas s), mConnection, 146 new Intent(mApplicationContext, DownloadNotificationService.clas s), mConnection,
152 Context.BIND_AUTO_CREATE); 147 Context.BIND_AUTO_CREATE);
153 } 148 }
154 149
155 @VisibleForTesting 150 @VisibleForTesting
156 void unbindService() { 151 void unbindService() {
157 mApplicationContext.unbindService(mConnection); 152 mApplicationContext.unbindService(mConnection);
158 } 153 }
159 154
160 @Override 155 @Override
161 public void onServiceShutdownRequested() {
162 unbindServiceIfNeeded();
163 }
164
165 @Override
166 public void onDownloadCanceled(String guid) { 156 public void onDownloadCanceled(String guid) {
167 mActiveDownloads.remove(guid); 157 mActiveDownloads.remove(guid);
168 if (mActiveDownloads.isEmpty()) unbindServiceIfNeeded(); 158 if (mActiveDownloads.isEmpty()) unbindServiceIfNeeded();
169 } 159 }
170 160
171 @Override 161 @Override
172 public void notifyDownloadCanceled(String downloadGuid) { 162 public void notifyDownloadCanceled(String downloadGuid) {
173 DownloadInfo downloadInfo = new DownloadInfo.Builder() 163 DownloadInfo downloadInfo = new DownloadInfo.Builder()
174 .setDownloadGuid(downloadGuid) 164 .setDownloadGuid(downloadGuid)
175 .build(); 165 .build();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 default: 302 default:
313 assert false; 303 assert false;
314 } 304 }
315 305
316 // Don't need to expose the notification id to ignore. Cancel will auto matically call this 306 // Don't need to expose the notification id to ignore. Cancel will auto matically call this
317 // method as well and pass it in. 307 // method as well and pass it in.
318 if (mBoundService != null) mBoundService.hideSummaryNotificationIfNecess ary(-1); 308 if (mBoundService != null) mBoundService.hideSummaryNotificationIfNecess ary(-1);
319 if (autoRelease) unbindServiceIfNeeded(); 309 if (autoRelease) unbindServiceIfNeeded();
320 } 310 }
321 } 311 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698