| 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.DownloadManager; | 7 import android.app.DownloadManager; |
| 8 import android.content.ActivityNotFoundException; | 8 import android.content.ActivityNotFoundException; |
| 9 import android.content.BroadcastReceiver; | 9 import android.content.BroadcastReceiver; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 */ | 218 */ |
| 219 String generateSharedPrefsString() { | 219 String generateSharedPrefsString() { |
| 220 return String.valueOf(mDownloadId) + "," + mInstallNotifyURI; | 220 return String.valueOf(mDownloadId) + "," + mInstallNotifyURI; |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 /** | 224 /** |
| 225 * Creates DownloadManagerService. | 225 * Creates DownloadManagerService. |
| 226 */ | 226 */ |
| 227 @SuppressFBWarnings("LI_LAZY_INIT") // Findbugs doesn't see this is only UI
thread. | 227 @SuppressFBWarnings("LI_LAZY_INIT") // Findbugs doesn't see this is only UI
thread. |
| 228 public static DownloadManagerService getDownloadManagerService(Context conte
xt) { | 228 public static DownloadManagerService getDownloadManagerService() { |
| 229 ThreadUtils.assertOnUiThread(); | 229 ThreadUtils.assertOnUiThread(); |
| 230 context = context.getApplicationContext(); | 230 Context appContext = ContextUtils.getApplicationContext(); |
| 231 if (sDownloadManagerService == null) { | 231 if (sDownloadManagerService == null) { |
| 232 sDownloadManagerService = new DownloadManagerService(context, | 232 sDownloadManagerService = new DownloadManagerService(appContext, |
| 233 new SystemDownloadNotifier(context), new Handler(), UPDATE_
DELAY_MILLIS); | 233 new SystemDownloadNotifier(appContext), new Handler(), UPDAT
E_DELAY_MILLIS); |
| 234 } | 234 } |
| 235 return sDownloadManagerService; | 235 return sDownloadManagerService; |
| 236 } | 236 } |
| 237 | 237 |
| 238 public static boolean hasDownloadManagerService() { | 238 public static boolean hasDownloadManagerService() { |
| 239 ThreadUtils.assertOnUiThread(); | 239 ThreadUtils.assertOnUiThread(); |
| 240 return sDownloadManagerService != null; | 240 return sDownloadManagerService != null; |
| 241 } | 241 } |
| 242 | 242 |
| 243 /** | 243 /** |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 @Override | 1116 @Override |
| 1117 protected void onPostExecute(Intent intent) { | 1117 protected void onPostExecute(Intent intent) { |
| 1118 if (intent == null | 1118 if (intent == null |
| 1119 || !ExternalNavigationDelegateImpl.resolveIntent(intent,
true) | 1119 || !ExternalNavigationDelegateImpl.resolveIntent(intent,
true) |
| 1120 || !DownloadUtils.fireOpenIntentForDownload(context, int
ent)) { | 1120 || !DownloadUtils.fireOpenIntentForDownload(context, int
ent)) { |
| 1121 openDownloadsPage(context); | 1121 openDownloadsPage(context); |
| 1122 } else { | 1122 } else { |
| 1123 DownloadManagerService service = | 1123 DownloadManagerService service = |
| 1124 DownloadManagerService.getDownloadManagerService(con
text); | 1124 DownloadManagerService.getDownloadManagerService(); |
| 1125 service.updateLastAccessTime(downloadGuid, isOffTheRecord); | 1125 service.updateLastAccessTime(downloadGuid, isOffTheRecord); |
| 1126 } | 1126 } |
| 1127 } | 1127 } |
| 1128 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 1128 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 /** | 1131 /** |
| 1132 * Called when a download fails. | 1132 * Called when a download fails. |
| 1133 * | 1133 * |
| 1134 * @param fileName Name of the download file. | 1134 * @param fileName Name of the download file. |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 } | 1713 } |
| 1714 | 1714 |
| 1715 /** | 1715 /** |
| 1716 * Called when a download is canceled before download target is determined. | 1716 * Called when a download is canceled before download target is determined. |
| 1717 * | 1717 * |
| 1718 * @param fileName Name of the download file. | 1718 * @param fileName Name of the download file. |
| 1719 * @param reason Reason of failure reported by android DownloadManager. | 1719 * @param reason Reason of failure reported by android DownloadManager. |
| 1720 */ | 1720 */ |
| 1721 @CalledByNative | 1721 @CalledByNative |
| 1722 private static void onDownloadItemCanceled(String fileName, boolean isExtern
alStorageMissing) { | 1722 private static void onDownloadItemCanceled(String fileName, boolean isExtern
alStorageMissing) { |
| 1723 DownloadManagerService service = getDownloadManagerService( | 1723 DownloadManagerService service = getDownloadManagerService(); |
| 1724 ContextUtils.getApplicationContext()); | |
| 1725 int reason = isExternalStorageMissing ? DownloadManager.ERROR_DEVICE_NOT
_FOUND | 1724 int reason = isExternalStorageMissing ? DownloadManager.ERROR_DEVICE_NOT
_FOUND |
| 1726 : DownloadManager.ERROR_FILE_ALREADY_EXISTS; | 1725 : DownloadManager.ERROR_FILE_ALREADY_EXISTS; |
| 1727 service.onDownloadFailed(fileName, reason); | 1726 service.onDownloadFailed(fileName, reason); |
| 1728 } | 1727 } |
| 1729 | 1728 |
| 1730 /** | 1729 /** |
| 1731 * Get the message to display when a download fails. | 1730 * Get the message to display when a download fails. |
| 1732 * | 1731 * |
| 1733 * @param fileName Name of the download file. | 1732 * @param fileName Name of the download file. |
| 1734 * @param reason Reason of failure reported by android DownloadManager. | 1733 * @param reason Reason of failure reported by android DownloadManager. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 boolean isOffTheRecord); | 1843 boolean isOffTheRecord); |
| 1845 private native void nativeRemoveDownload(long nativeDownloadManagerService,
String downloadGuid, | 1844 private native void nativeRemoveDownload(long nativeDownloadManagerService,
String downloadGuid, |
| 1846 boolean isOffTheRecord); | 1845 boolean isOffTheRecord); |
| 1847 private native void nativeGetAllDownloads( | 1846 private native void nativeGetAllDownloads( |
| 1848 long nativeDownloadManagerService, boolean isOffTheRecord); | 1847 long nativeDownloadManagerService, boolean isOffTheRecord); |
| 1849 private native void nativeCheckForExternallyRemovedDownloads( | 1848 private native void nativeCheckForExternallyRemovedDownloads( |
| 1850 long nativeDownloadManagerService, boolean isOffTheRecord); | 1849 long nativeDownloadManagerService, boolean isOffTheRecord); |
| 1851 private native void nativeUpdateLastAccessTime( | 1850 private native void nativeUpdateLastAccessTime( |
| 1852 long nativeDownloadManagerService, String downloadGuid, boolean isOf
fTheRecord); | 1851 long nativeDownloadManagerService, String downloadGuid, boolean isOf
fTheRecord); |
| 1853 } | 1852 } |
| OLD | NEW |