| OLD | NEW |
| 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.Notification; | 7 import android.app.Notification; |
| 8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
| 9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
| 10 import android.app.Service; | 10 import android.app.Service; |
| 11 import android.content.ComponentName; | 11 import android.content.ComponentName; |
| 12 import android.content.Context; | 12 import android.content.Context; |
| 13 import android.content.Intent; | 13 import android.content.Intent; |
| 14 import android.content.SharedPreferences; | 14 import android.content.SharedPreferences; |
| 15 import android.os.Binder; | 15 import android.os.Binder; |
| 16 import android.os.Build; | 16 import android.os.Build; |
| 17 import android.os.IBinder; | 17 import android.os.IBinder; |
| 18 import android.preference.PreferenceManager; | 18 import android.preference.PreferenceManager; |
| 19 import android.support.v4.app.NotificationCompat; | 19 import android.support.v4.app.NotificationCompat; |
| 20 import android.text.TextUtils; |
| 20 | 21 |
| 21 import org.chromium.base.Log; | 22 import org.chromium.base.Log; |
| 22 import org.chromium.base.VisibleForTesting; | 23 import org.chromium.base.VisibleForTesting; |
| 23 import org.chromium.base.library_loader.ProcessInitException; | 24 import org.chromium.base.library_loader.ProcessInitException; |
| 24 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
| 25 import org.chromium.chrome.browser.ChromeApplication; | 26 import org.chromium.chrome.browser.ChromeApplication; |
| 26 import org.chromium.chrome.browser.init.BrowserParts; | 27 import org.chromium.chrome.browser.init.BrowserParts; |
| 27 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 28 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 28 import org.chromium.chrome.browser.init.EmptyBrowserParts; | 29 import org.chromium.chrome.browser.init.EmptyBrowserParts; |
| 29 import org.chromium.chrome.browser.util.IntentUtils; | 30 import org.chromium.chrome.browser.util.IntentUtils; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 removeSharedPreferenceEntry(downloadGuid); | 236 removeSharedPreferenceEntry(downloadGuid); |
| 236 } | 237 } |
| 237 | 238 |
| 238 /** | 239 /** |
| 239 * Add a download failed notification. | 240 * Add a download failed notification. |
| 240 * @param notificationId Notification ID of the download. | 241 * @param notificationId Notification ID of the download. |
| 241 * @param downloadGuid GUID of the download. | 242 * @param downloadGuid GUID of the download. |
| 242 * @param fileName GUID of the download. | 243 * @param fileName GUID of the download. |
| 243 */ | 244 */ |
| 244 public void notifyDownloadFailed(int notificationId, String downloadGuid, St
ring fileName) { | 245 public void notifyDownloadFailed(int notificationId, String downloadGuid, St
ring fileName) { |
| 246 // If the download is not in history db, fileName could be empty. Get it
from |
| 247 // SharedPreferences. |
| 248 if (TextUtils.isEmpty(fileName)) { |
| 249 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEnt
ry(downloadGuid); |
| 250 if (entry == null) return; |
| 251 fileName = entry.fileName; |
| 252 } |
| 253 |
| 245 NotificationCompat.Builder builder = buildNotification( | 254 NotificationCompat.Builder builder = buildNotification( |
| 246 android.R.drawable.stat_sys_download_done, fileName, | 255 android.R.drawable.stat_sys_download_done, fileName, |
| 247 mContext.getResources().getString(R.string.download_notification
_failed)); | 256 mContext.getResources().getString(R.string.download_notification
_failed)); |
| 248 updateNotification(notificationId, builder.build()); | 257 updateNotification(notificationId, builder.build()); |
| 249 removeSharedPreferenceEntry(downloadGuid); | 258 removeSharedPreferenceEntry(downloadGuid); |
| 250 } | 259 } |
| 251 | 260 |
| 252 /** | 261 /** |
| 253 * Called to pause all the download notifications. | 262 * Called to pause all the download notifications. |
| 254 */ | 263 */ |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 */ | 505 */ |
| 497 private void storeDownloadSharedPreferenceEntries() { | 506 private void storeDownloadSharedPreferenceEntries() { |
| 498 Set<String> entries = new HashSet<String>(); | 507 Set<String> entries = new HashSet<String>(); |
| 499 for (int i = 0; i < mDownloadSharedPreferenceEntries.size(); ++i) { | 508 for (int i = 0; i < mDownloadSharedPreferenceEntries.size(); ++i) { |
| 500 entries.add(mDownloadSharedPreferenceEntries.get(i).getSharedPrefere
nceString()); | 509 entries.add(mDownloadSharedPreferenceEntries.get(i).getSharedPrefere
nceString()); |
| 501 } | 510 } |
| 502 DownloadManagerService.storeDownloadInfo( | 511 DownloadManagerService.storeDownloadInfo( |
| 503 mSharedPrefs, PENDING_DOWNLOAD_NOTIFICATIONS, entries); | 512 mSharedPrefs, PENDING_DOWNLOAD_NOTIFICATIONS, entries); |
| 504 } | 513 } |
| 505 } | 514 } |
| OLD | NEW |