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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/ui/SpaceDisplay.java

Issue 2540813002: [Download Home] Use fewer AsyncTasks (Closed)
Patch Set: Remove accidental thing Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadActivityTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/download/ui/SpaceDisplay.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/SpaceDisplay.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/SpaceDisplay.java
index dec67a4a29dd538856166b4f0bb90aabf5f750ec..9eb7542ebef6edc1e459c36bad2e0273efad4e15 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/SpaceDisplay.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/SpaceDisplay.java
@@ -22,6 +22,7 @@ import org.chromium.chrome.R;
import java.io.File;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.RejectedExecutionException;
/** A View that manages the display of space used by the downloads. */
public class SpaceDisplay extends RecyclerView.AdapterDataObserver {
@@ -108,6 +109,7 @@ public class SpaceDisplay extends RecyclerView.AdapterDataObserver {
private TextView mSpaceUsedByOtherAppsTextView;
private TextView mSpaceFreeTextView;
private ProgressBar mSpaceBar;
+ private long mFreeBytes;
SpaceDisplay(final ViewGroup parent, DownloadHistoryAdapter historyAdapter) {
mHistoryAdapter = historyAdapter;
@@ -131,13 +133,22 @@ public class SpaceDisplay extends RecyclerView.AdapterDataObserver {
}
// Determine how much space is free now, then update the display.
- mFreeBytesTask = new StorageSizeTask(false) {
- @Override
- protected void onPostExecute(Long bytes) {
- update();
+ if (mFreeBytesTask == null) {
+ mFreeBytesTask = new StorageSizeTask(false) {
+ @Override
+ protected void onPostExecute(Long bytes) {
+ mFreeBytes = bytes.longValue();
+ mFreeBytesTask = null;
+ update();
+ }
+ };
+
+ try {
+ mFreeBytesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ } catch (RejectedExecutionException e) {
+ mFreeBytesTask = null;
}
- };
- mFreeBytesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
}
@VisibleForTesting
@@ -147,17 +158,15 @@ public class SpaceDisplay extends RecyclerView.AdapterDataObserver {
private void update() {
long fileSystemBytes = 0;
- long freeBytes = 0;
try {
fileSystemBytes = mFileSystemBytesTask.get();
- freeBytes = mFreeBytesTask.get();
} catch (ExecutionException | InterruptedException e) {
// Can't do anything here.
}
// Indicate how much space has been used by everything on the device via the progress bar.
- long bytesUsedTotal = Math.max(0, fileSystemBytes - freeBytes);
+ long bytesUsedTotal = Math.max(0, fileSystemBytes - mFreeBytes);
long bytesUsedByDownloads = Math.max(0, mHistoryAdapter.getTotalDownloadSize());
long bytesUsedByOtherApps = Math.max(0, bytesUsedTotal - bytesUsedByDownloads);
@@ -166,7 +175,7 @@ public class SpaceDisplay extends RecyclerView.AdapterDataObserver {
getStringForBytes(USED_STRINGS, bytesUsedByDownloads));
mSpaceUsedByOtherAppsTextView.setText(
getStringForBytes(OTHER_STRINGS, bytesUsedByOtherApps));
- mSpaceFreeTextView.setText(getStringForBytes(FREE_STRINGS, freeBytes));
+ mSpaceFreeTextView.setText(getStringForBytes(FREE_STRINGS, mFreeBytes));
// Set a minimum size for the download size so that it shows up in the progress bar.
long onePercentOfSystem = fileSystemBytes == 0 ? 0 : fileSystemBytes / 100;
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadActivityTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698