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 11 matching lines...) Expand all Loading... |
22 import android.util.Pair; | 22 import android.util.Pair; |
23 | 23 |
24 import org.chromium.base.ContextUtils; | 24 import org.chromium.base.ContextUtils; |
25 import org.chromium.base.Log; | 25 import org.chromium.base.Log; |
26 import org.chromium.base.ThreadUtils; | 26 import org.chromium.base.ThreadUtils; |
27 import org.chromium.base.VisibleForTesting; | 27 import org.chromium.base.VisibleForTesting; |
28 import org.chromium.base.annotations.CalledByNative; | 28 import org.chromium.base.annotations.CalledByNative; |
29 import org.chromium.base.annotations.SuppressFBWarnings; | 29 import org.chromium.base.annotations.SuppressFBWarnings; |
30 import org.chromium.base.metrics.RecordHistogram; | 30 import org.chromium.base.metrics.RecordHistogram; |
31 import org.chromium.chrome.R; | 31 import org.chromium.chrome.R; |
| 32 import org.chromium.chrome.browser.download.ui.DownloadHistoryAdapter; |
32 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; | 33 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; |
33 import org.chromium.net.ConnectionType; | 34 import org.chromium.net.ConnectionType; |
34 import org.chromium.net.NetworkChangeNotifierAutoDetect; | 35 import org.chromium.net.NetworkChangeNotifierAutoDetect; |
35 import org.chromium.net.RegistrationPolicyAlwaysRegister; | 36 import org.chromium.net.RegistrationPolicyAlwaysRegister; |
36 import org.chromium.ui.widget.Toast; | 37 import org.chromium.ui.widget.Toast; |
37 | 38 |
38 import java.io.File; | 39 import java.io.File; |
39 import java.util.ArrayList; | 40 import java.util.ArrayList; |
40 import java.util.Arrays; | 41 import java.util.Arrays; |
41 import java.util.HashSet; | 42 import java.util.HashSet; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 private final AtomicBoolean mIsUIUpdateScheduled; | 117 private final AtomicBoolean mIsUIUpdateScheduled; |
117 private final Handler mHandler; | 118 private final Handler mHandler; |
118 private final Context mContext; | 119 private final Context mContext; |
119 | 120 |
120 private final LongSparseArray<DownloadItem> mSystemDownloadIdMap = | 121 private final LongSparseArray<DownloadItem> mSystemDownloadIdMap = |
121 new LongSparseArray<DownloadItem>(); | 122 new LongSparseArray<DownloadItem>(); |
122 // Using vector for thread safety. | 123 // Using vector for thread safety. |
123 @VisibleForTesting protected final Vector<String> mAutoResumableDownloadIds
= | 124 @VisibleForTesting protected final Vector<String> mAutoResumableDownloadIds
= |
124 new Vector<String>(); | 125 new Vector<String>(); |
125 private final List<DownloadUmaStatsEntry> mUmaEntries = new ArrayList<Downlo
adUmaStatsEntry>(); | 126 private final List<DownloadUmaStatsEntry> mUmaEntries = new ArrayList<Downlo
adUmaStatsEntry>(); |
| 127 private final DownloadHistoryAdapter mDownloadHistoryAdapter; |
| 128 |
126 private OMADownloadHandler mOMADownloadHandler; | 129 private OMADownloadHandler mOMADownloadHandler; |
127 private DownloadSnackbarController mDownloadSnackbarController; | 130 private DownloadSnackbarController mDownloadSnackbarController; |
128 private long mNativeDownloadManagerService; | 131 private long mNativeDownloadManagerService; |
129 private DownloadManagerDelegate mDownloadManagerDelegate; | 132 private DownloadManagerDelegate mDownloadManagerDelegate; |
130 private NetworkChangeNotifierAutoDetect mNetworkChangeNotifier; | 133 private NetworkChangeNotifierAutoDetect mNetworkChangeNotifier; |
131 | 134 |
132 /** | 135 /** |
133 * Class representing progress of a download. | 136 * Class representing progress of a download. |
134 */ | 137 */ |
135 private static class DownloadProgress { | 138 private static class DownloadProgress { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 long updateDelayInMillis) { | 228 long updateDelayInMillis) { |
226 mContext = context; | 229 mContext = context; |
227 mSharedPrefs = ContextUtils.getAppSharedPreferences(); | 230 mSharedPrefs = ContextUtils.getAppSharedPreferences(); |
228 mDownloadNotifier = downloadNotifier; | 231 mDownloadNotifier = downloadNotifier; |
229 mUpdateDelayInMillis = updateDelayInMillis; | 232 mUpdateDelayInMillis = updateDelayInMillis; |
230 mHandler = handler; | 233 mHandler = handler; |
231 mIsUIUpdateScheduled = new AtomicBoolean(false); | 234 mIsUIUpdateScheduled = new AtomicBoolean(false); |
232 mOMADownloadHandler = new OMADownloadHandler(context); | 235 mOMADownloadHandler = new OMADownloadHandler(context); |
233 mDownloadSnackbarController = new DownloadSnackbarController(context); | 236 mDownloadSnackbarController = new DownloadSnackbarController(context); |
234 mDownloadManagerDelegate = new DownloadManagerDelegate(mContext); | 237 mDownloadManagerDelegate = new DownloadManagerDelegate(mContext); |
| 238 mDownloadHistoryAdapter = new DownloadHistoryAdapter(); |
235 if (mSharedPrefs.contains(DEPRECATED_DOWNLOAD_NOTIFICATION_IDS)) { | 239 if (mSharedPrefs.contains(DEPRECATED_DOWNLOAD_NOTIFICATION_IDS)) { |
236 mSharedPrefs.edit().remove(DEPRECATED_DOWNLOAD_NOTIFICATION_IDS).app
ly(); | 240 mSharedPrefs.edit().remove(DEPRECATED_DOWNLOAD_NOTIFICATION_IDS).app
ly(); |
237 } | 241 } |
238 // Note that this technically leaks the native object, however, Download
ManagerService | 242 // Note that this technically leaks the native object, however, Download
ManagerService |
239 // is a singleton that lives forever and there's no clean shutdown of Ch
rome on Android. | 243 // is a singleton that lives forever and there's no clean shutdown of Ch
rome on Android. |
240 init(); | 244 init(); |
241 clearPendingOMADownloads(); | 245 clearPendingOMADownloads(); |
242 } | 246 } |
243 | 247 |
244 @VisibleForTesting | 248 @VisibleForTesting |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 private void parseUMAStatsEntriesFromSharedPrefs() { | 1446 private void parseUMAStatsEntriesFromSharedPrefs() { |
1443 if (mSharedPrefs.contains(DOWNLOAD_UMA_ENTRY)) { | 1447 if (mSharedPrefs.contains(DOWNLOAD_UMA_ENTRY)) { |
1444 Set<String> entries = | 1448 Set<String> entries = |
1445 DownloadManagerService.getStoredDownloadInfo(mSharedPrefs, D
OWNLOAD_UMA_ENTRY); | 1449 DownloadManagerService.getStoredDownloadInfo(mSharedPrefs, D
OWNLOAD_UMA_ENTRY); |
1446 for (String entryString : entries) { | 1450 for (String entryString : entries) { |
1447 mUmaEntries.add(DownloadUmaStatsEntry.parseFromString(entryStrin
g)); | 1451 mUmaEntries.add(DownloadUmaStatsEntry.parseFromString(entryStrin
g)); |
1448 } | 1452 } |
1449 } | 1453 } |
1450 } | 1454 } |
1451 | 1455 |
| 1456 /** |
| 1457 * Returns the Adapter that provides a view into the download history. |
| 1458 */ |
| 1459 public DownloadHistoryAdapter getDownloadHistoryAdapter() { |
| 1460 return mDownloadHistoryAdapter; |
| 1461 } |
| 1462 |
| 1463 /** |
| 1464 * Begins sending back information about all entries in the user's DownloadH
istory, with each |
| 1465 * individual DownloadItem's data passed back via |
| 1466 * {@link #onDownloadInfoAdded(String, String, String, String, long, long)}. |
| 1467 * |
| 1468 * This call will be delayed if the native side has not yet been initialized
. |
| 1469 */ |
| 1470 public void getAllDownloads() { |
| 1471 mDownloadHistoryAdapter.clear(); |
| 1472 nativeGetAllDownloads(getNativeDownloadManagerService()); |
| 1473 } |
| 1474 |
| 1475 @CalledByNative |
| 1476 private List<DownloadItem> createDownloadItemList() { |
| 1477 return new ArrayList<DownloadItem>(); |
| 1478 } |
| 1479 |
| 1480 @CalledByNative |
| 1481 private void addDownloadItemToList(List<DownloadItem> list, String guid, Str
ing filename, |
| 1482 String url, String mimeType, long startTimestamp, long totalBytes) { |
| 1483 DownloadInfo.Builder builder = new DownloadInfo.Builder() |
| 1484 .setDownloadGuid(guid) |
| 1485 .setFileName(filename) |
| 1486 .setUrl(url) |
| 1487 .setMimeType(mimeType) |
| 1488 .setContentLength(totalBytes); |
| 1489 DownloadItem downloadItem = new DownloadItem(false, builder.build()); |
| 1490 downloadItem.setStartTime(startTimestamp); |
| 1491 list.add(downloadItem); |
| 1492 } |
| 1493 |
| 1494 @CalledByNative |
| 1495 private void onAllDownloadsRetrieved(final List<DownloadItem> list) { |
| 1496 mDownloadHistoryAdapter.onAllDownloadsRetrieved(list); |
| 1497 } |
| 1498 |
1452 @Override | 1499 @Override |
1453 public void onMaxBandwidthChanged(double maxBandwidthMbps) {} | 1500 public void onMaxBandwidthChanged(double maxBandwidthMbps) {} |
1454 | 1501 |
1455 @Override | 1502 @Override |
1456 public void onNetworkConnect(int netId, int connectionType) {} | 1503 public void onNetworkConnect(int netId, int connectionType) {} |
1457 | 1504 |
1458 @Override | 1505 @Override |
1459 public void onNetworkSoonToDisconnect(int netId) {} | 1506 public void onNetworkSoonToDisconnect(int netId) {} |
1460 | 1507 |
1461 @Override | 1508 @Override |
1462 public void onNetworkDisconnect(int netId) {} | 1509 public void onNetworkDisconnect(int netId) {} |
1463 | 1510 |
1464 @Override | 1511 @Override |
1465 public void purgeActiveNetworkList(int[] activeNetIds) {} | 1512 public void purgeActiveNetworkList(int[] activeNetIds) {} |
1466 | 1513 |
1467 private native long nativeInit(); | 1514 private native long nativeInit(); |
1468 private native void nativeResumeDownload( | 1515 private native void nativeResumeDownload( |
1469 long nativeDownloadManagerService, String downloadGuid); | 1516 long nativeDownloadManagerService, String downloadGuid); |
1470 private native void nativeCancelDownload( | 1517 private native void nativeCancelDownload( |
1471 long nativeDownloadManagerService, String downloadGuid, boolean isOf
fTheRecord, | 1518 long nativeDownloadManagerService, String downloadGuid, boolean isOf
fTheRecord, |
1472 boolean isNotificationDismissed); | 1519 boolean isNotificationDismissed); |
1473 private native void nativePauseDownload(long nativeDownloadManagerService, S
tring downloadGuid); | 1520 private native void nativePauseDownload(long nativeDownloadManagerService, S
tring downloadGuid); |
| 1521 private native void nativeGetAllDownloads(long nativeDownloadManagerService)
; |
1474 } | 1522 } |
OLD | NEW |