| Index: components/offline_pages/core/prefetch/prefetch_dispatcher_impl.cc
|
| diff --git a/components/offline_pages/core/prefetch/prefetch_dispatcher_impl.cc b/components/offline_pages/core/prefetch/prefetch_dispatcher_impl.cc
|
| index bad8687c24ab51a2db3a3ae9e64151db24924d2a..5952f2b3fd826e4edaa58290ebfec259b93f6f78 100644
|
| --- a/components/offline_pages/core/prefetch/prefetch_dispatcher_impl.cc
|
| +++ b/components/offline_pages/core/prefetch/prefetch_dispatcher_impl.cc
|
| @@ -4,13 +4,23 @@
|
|
|
| #include "components/offline_pages/core/prefetch/prefetch_dispatcher_impl.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/memory/ptr_util.h"
|
| +#include "base/task_runner.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "components/offline_pages/core/prefetch/add_unique_urls_task.h"
|
| #include "components/offline_pages/core/prefetch/prefetch_service.h"
|
| #include "url/gurl.h"
|
|
|
| namespace offline_pages {
|
|
|
| +namespace {
|
| +void DeleteBackgroundTaskHelper(
|
| + std::unique_ptr<PrefetchDispatcher::ScopedBackgroundTask> task) {
|
| + task.reset();
|
| +}
|
| +} // namespace
|
| +
|
| PrefetchDispatcherImpl::PrefetchDispatcherImpl() = default;
|
|
|
| PrefetchDispatcherImpl::~PrefetchDispatcherImpl() = default;
|
| @@ -39,11 +49,23 @@ void PrefetchDispatcherImpl::RemovePrefetchURLsByClientId(
|
|
|
| void PrefetchDispatcherImpl::BeginBackgroundTask(
|
| std::unique_ptr<ScopedBackgroundTask> task) {
|
| - NOTIMPLEMENTED();
|
| + task_ = std::move(task);
|
| }
|
|
|
| -void PrefetchDispatcherImpl::StopBackgroundTask(ScopedBackgroundTask* task) {
|
| - NOTIMPLEMENTED();
|
| +void PrefetchDispatcherImpl::StopBackgroundTask() {
|
| + DisposeTask();
|
| +}
|
| +
|
| +void PrefetchDispatcherImpl::RequestFinishBackgroundTaskForTest() {
|
| + DisposeTask();
|
| +}
|
| +
|
| +void PrefetchDispatcherImpl::DisposeTask() {
|
| + DCHECK(task_);
|
| + // Delay the deletion till the caller finishes.
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DeleteBackgroundTaskHelper, base::Passed(std::move(task_))));
|
| }
|
|
|
| } // namespace offline_pages
|
|
|