mirror of
https://github.com/samsonjs/media.git
synced 2026-04-26 14:57:47 +00:00
Reorder DownloadManager methods into a more natural order
- Start before stop - Release near bottom - Private after public ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=195570480
This commit is contained in:
parent
c5e8f6ff9e
commit
f2cef12367
1 changed files with 53 additions and 53 deletions
|
|
@ -178,52 +178,6 @@ public final class DownloadManager {
|
||||||
logd("Created");
|
logd("Created");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops all of the tasks and releases resources. If the action file isn't up to date, waits for
|
|
||||||
* the changes to be written. The manager must not be accessed after this method has been called.
|
|
||||||
*/
|
|
||||||
public void release() {
|
|
||||||
if (released) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
released = true;
|
|
||||||
for (int i = 0; i < tasks.size(); i++) {
|
|
||||||
tasks.get(i).stop();
|
|
||||||
}
|
|
||||||
final ConditionVariable fileIOFinishedCondition = new ConditionVariable();
|
|
||||||
fileIOHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
fileIOFinishedCondition.open();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
fileIOFinishedCondition.block();
|
|
||||||
fileIOThread.quit();
|
|
||||||
logd("Released");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Stops all of the download tasks. Call {@link #startDownloads()} to restart tasks. */
|
|
||||||
public void stopDownloads() {
|
|
||||||
Assertions.checkState(!released);
|
|
||||||
if (!downloadsStopped) {
|
|
||||||
downloadsStopped = true;
|
|
||||||
for (int i = 0; i < activeDownloadTasks.size(); i++) {
|
|
||||||
activeDownloadTasks.get(i).stop();
|
|
||||||
}
|
|
||||||
logd("Downloads are stopping");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Starts the download tasks. */
|
|
||||||
public void startDownloads() {
|
|
||||||
Assertions.checkState(!released);
|
|
||||||
if (downloadsStopped) {
|
|
||||||
downloadsStopped = false;
|
|
||||||
maybeStartTasks();
|
|
||||||
logd("Downloads are started");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a {@link Listener}.
|
* Adds a {@link Listener}.
|
||||||
*
|
*
|
||||||
|
|
@ -242,6 +196,28 @@ public final class DownloadManager {
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Starts the download tasks. */
|
||||||
|
public void startDownloads() {
|
||||||
|
Assertions.checkState(!released);
|
||||||
|
if (downloadsStopped) {
|
||||||
|
downloadsStopped = false;
|
||||||
|
maybeStartTasks();
|
||||||
|
logd("Downloads are started");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stops all of the download tasks. Call {@link #startDownloads()} to restart tasks. */
|
||||||
|
public void stopDownloads() {
|
||||||
|
Assertions.checkState(!released);
|
||||||
|
if (!downloadsStopped) {
|
||||||
|
downloadsStopped = true;
|
||||||
|
for (int i = 0; i < activeDownloadTasks.size(); i++) {
|
||||||
|
activeDownloadTasks.get(i).stop();
|
||||||
|
}
|
||||||
|
logd("Downloads are stopping");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserializes an action from {@code actionData}, and calls {@link
|
* Deserializes an action from {@code actionData}, and calls {@link
|
||||||
* #handleAction(DownloadAction)}.
|
* #handleAction(DownloadAction)}.
|
||||||
|
|
@ -275,13 +251,6 @@ public final class DownloadManager {
|
||||||
return task.id;
|
return task.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task addTaskForAction(DownloadAction action) {
|
|
||||||
Task task = new Task(nextTaskId++, this, action, minRetryCount);
|
|
||||||
tasks.add(task);
|
|
||||||
logd("Task is added", task);
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the current number of tasks. */
|
/** Returns the current number of tasks. */
|
||||||
public int getTaskCount() {
|
public int getTaskCount() {
|
||||||
Assertions.checkState(!released);
|
Assertions.checkState(!released);
|
||||||
|
|
@ -324,6 +293,37 @@ public final class DownloadManager {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops all of the tasks and releases resources. If the action file isn't up to date, waits for
|
||||||
|
* the changes to be written. The manager must not be accessed after this method has been called.
|
||||||
|
*/
|
||||||
|
public void release() {
|
||||||
|
if (released) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
released = true;
|
||||||
|
for (int i = 0; i < tasks.size(); i++) {
|
||||||
|
tasks.get(i).stop();
|
||||||
|
}
|
||||||
|
final ConditionVariable fileIOFinishedCondition = new ConditionVariable();
|
||||||
|
fileIOHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
fileIOFinishedCondition.open();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileIOFinishedCondition.block();
|
||||||
|
fileIOThread.quit();
|
||||||
|
logd("Released");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task addTaskForAction(DownloadAction action) {
|
||||||
|
Task task = new Task(nextTaskId++, this, action, minRetryCount);
|
||||||
|
tasks.add(task);
|
||||||
|
logd("Task is added", task);
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates through the task queue and starts any task if all of the following are true:
|
* Iterates through the task queue and starts any task if all of the following are true:
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue