summaryrefslogtreecommitdiff
path: root/chromium/components/download/public/task
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/download/public/task')
-rw-r--r--chromium/components/download/public/task/download_task_types.h3
-rw-r--r--chromium/components/download/public/task/task_manager.h12
-rw-r--r--chromium/components/download/public/task/task_manager_impl.cc7
-rw-r--r--chromium/components/download/public/task/task_manager_unittest.cc28
4 files changed, 41 insertions, 9 deletions
diff --git a/chromium/components/download/public/task/download_task_types.h b/chromium/components/download/public/task/download_task_types.h
index 559ca796f2d..a979fb8cde0 100644
--- a/chromium/components/download/public/task/download_task_types.h
+++ b/chromium/components/download/public/task/download_task_types.h
@@ -18,6 +18,9 @@ enum class DownloadTaskType {
// Task to invoke the download auto-resumption handler.
DOWNLOAD_AUTO_RESUMPTION_TASK = 2,
+
+ // Task to start user scheduled downloads.
+ DOWNLOAD_LATER_TASK = 3,
};
} // namespace download
diff --git a/chromium/components/download/public/task/task_manager.h b/chromium/components/download/public/task/task_manager.h
index 0bfe8854d81..a61269a2800 100644
--- a/chromium/components/download/public/task/task_manager.h
+++ b/chromium/components/download/public/task/task_manager.h
@@ -57,11 +57,13 @@ class TaskManager {
virtual void OnStopScheduledTask(DownloadTaskType task_type) = 0;
// Should be called once the task is complete. The callback passed through
- // OnStartScheduledTask() will be run in order to notify that the task is done
- // and the system should reschedule the task with the original params if
- // |needs_reschedule| is true. If there are pending params for a new task, a
- // new task will be scheduled immediately and reschedule logic will not be
- // run.
+ // OnStartScheduledTask() will be run in order to notify that the task is
+ // done. If there are pending params for a new task, a new task will be
+ // scheduled immediately.
+ //
+ // Most caller should set |needs_reschedule| to false. The OS will reschedule
+ // the task with the original params but with a OS controlled back off time if
+ // |needs_reschedule| is true.
virtual void NotifyTaskFinished(DownloadTaskType task_type,
bool needs_reschedule) = 0;
diff --git a/chromium/components/download/public/task/task_manager_impl.cc b/chromium/components/download/public/task/task_manager_impl.cc
index ac40fba6360..772ac239658 100644
--- a/chromium/components/download/public/task/task_manager_impl.cc
+++ b/chromium/components/download/public/task/task_manager_impl.cc
@@ -49,11 +49,10 @@ void TaskManagerImpl::UnscheduleTask(DownloadTaskType task_type) {
void TaskManagerImpl::OnStartScheduledTask(DownloadTaskType task_type,
TaskFinishedCallback callback) {
- DCHECK(pending_task_params_.find(task_type) != pending_task_params_.end());
- current_task_params_[task_type] = pending_task_params_[task_type];
- pending_task_params_.erase(task_type);
+ if (pending_task_params_.find(task_type) != pending_task_params_.end())
+ current_task_params_[task_type] = pending_task_params_[task_type];
- DCHECK(!IsRunningTask(task_type));
+ pending_task_params_.erase(task_type);
task_finished_callbacks_[task_type] = std::move(callback);
}
diff --git a/chromium/components/download/public/task/task_manager_unittest.cc b/chromium/components/download/public/task/task_manager_unittest.cc
index 526fa54e42b..5aac8623135 100644
--- a/chromium/components/download/public/task/task_manager_unittest.cc
+++ b/chromium/components/download/public/task/task_manager_unittest.cc
@@ -224,6 +224,34 @@ TEST_F(TaskManagerImplTest, StopTaskWillClearTheCallback) {
task_runner_->RunUntilIdle();
}
+// Verifies that OnStartScheduledTask() can be called without preceding
+// ScheduleTask() calls.
+TEST_F(TaskManagerImplTest, StartTaskWithoutPendingParams) {
+ MockTaskWaiter waiter;
+ auto callback =
+ base::BindOnce(&MockTaskWaiter::TaskFinished, base::Unretained(&waiter));
+ task_manager_->OnStartScheduledTask(DownloadTaskType::DOWNLOAD_TASK,
+ std::move(callback));
+ EXPECT_CALL(waiter, TaskFinished(false)).Times(1);
+ task_manager_->NotifyTaskFinished(DownloadTaskType::DOWNLOAD_TASK, false);
+ task_runner_->RunUntilIdle();
+}
+
+// Verifies that OnStopScheduledTask() can be called without preceding
+// ScheduleTask() calls.
+TEST_F(TaskManagerImplTest, StopTaskWithoutPendingParams) {
+ MockTaskWaiter waiter;
+ EXPECT_CALL(waiter, TaskFinished(false)).Times(0);
+
+ auto callback =
+ base::BindOnce(&MockTaskWaiter::TaskFinished, base::Unretained(&waiter));
+ task_manager_->OnStartScheduledTask(DownloadTaskType::DOWNLOAD_TASK,
+ std::move(callback));
+ task_manager_->OnStopScheduledTask(DownloadTaskType::DOWNLOAD_TASK);
+
+ task_runner_->RunUntilIdle();
+}
+
TEST_F(TaskManagerImplTest, StopTaskWillSchedulePendingParams) {
auto params = CreateTaskParams();
task_manager_->ScheduleTask(DownloadTaskType::DOWNLOAD_TASK, params);