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

Side by Side Diff: components/offline_pages/core/prefetch/prefetch_dispatcher_impl.cc

Issue 2914703002: [Offline Prefetch] Backoff support for PrefetchBackgroundTask (Closed)
Patch Set: Fix test Created 3 years, 6 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "components/offline_pages/core/prefetch/prefetch_dispatcher_impl.h" 5 #include "components/offline_pages/core/prefetch/prefetch_dispatcher_impl.h"
6 6
7 #include "base/bind.h"
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h"
8 #include "components/offline_pages/core/prefetch/add_unique_urls_task.h" 11 #include "components/offline_pages/core/prefetch/add_unique_urls_task.h"
9 #include "components/offline_pages/core/prefetch/prefetch_service.h" 12 #include "components/offline_pages/core/prefetch/prefetch_service.h"
10 #include "url/gurl.h" 13 #include "url/gurl.h"
11 14
12 namespace offline_pages { 15 namespace offline_pages {
13 16
17 namespace {
18 void DeleteBackgroundTaskHelper(
19 std::unique_ptr<PrefetchDispatcher::ScopedBackgroundTask> task) {
20 task.reset();
21 }
22 } // namespace
23
14 PrefetchDispatcherImpl::PrefetchDispatcherImpl() = default; 24 PrefetchDispatcherImpl::PrefetchDispatcherImpl() = default;
15 25
16 PrefetchDispatcherImpl::~PrefetchDispatcherImpl() = default; 26 PrefetchDispatcherImpl::~PrefetchDispatcherImpl() = default;
17 27
18 void PrefetchDispatcherImpl::SetService(PrefetchService* service) { 28 void PrefetchDispatcherImpl::SetService(PrefetchService* service) {
19 CHECK(service); 29 CHECK(service);
20 service_ = service; 30 service_ = service;
21 } 31 }
22 32
23 void PrefetchDispatcherImpl::AddCandidatePrefetchURLs( 33 void PrefetchDispatcherImpl::AddCandidatePrefetchURLs(
24 const std::vector<PrefetchURL>& prefetch_urls) { 34 const std::vector<PrefetchURL>& prefetch_urls) {
25 std::unique_ptr<Task> add_task = base::MakeUnique<AddUniqueUrlsTask>( 35 std::unique_ptr<Task> add_task = base::MakeUnique<AddUniqueUrlsTask>(
26 service_->GetPrefetchStore(), prefetch_urls); 36 service_->GetPrefetchStore(), prefetch_urls);
27 task_queue_.AddTask(std::move(add_task)); 37 task_queue_.AddTask(std::move(add_task));
28 } 38 }
29 39
30 void PrefetchDispatcherImpl::RemoveAllUnprocessedPrefetchURLs( 40 void PrefetchDispatcherImpl::RemoveAllUnprocessedPrefetchURLs(
31 const std::string& name_space) { 41 const std::string& name_space) {
32 NOTIMPLEMENTED(); 42 NOTIMPLEMENTED();
33 } 43 }
34 44
35 void PrefetchDispatcherImpl::RemovePrefetchURLsByClientId( 45 void PrefetchDispatcherImpl::RemovePrefetchURLsByClientId(
36 const ClientId& client_id) { 46 const ClientId& client_id) {
37 NOTIMPLEMENTED(); 47 NOTIMPLEMENTED();
38 } 48 }
39 49
40 void PrefetchDispatcherImpl::BeginBackgroundTask( 50 void PrefetchDispatcherImpl::BeginBackgroundTask(
41 std::unique_ptr<ScopedBackgroundTask> task) { 51 std::unique_ptr<ScopedBackgroundTask> task) {
42 NOTIMPLEMENTED(); 52 task_ = std::move(task);
43 } 53 }
44 54
45 void PrefetchDispatcherImpl::StopBackgroundTask(ScopedBackgroundTask* task) { 55 void PrefetchDispatcherImpl::StopBackgroundTask() {
46 NOTIMPLEMENTED(); 56 DisposeTask();
57 }
58
59 void PrefetchDispatcherImpl::RequestFinishBackgroundTaskForTest() {
60 DisposeTask();
61 }
62
63 void PrefetchDispatcherImpl::DisposeTask() {
64 DCHECK(task_);
65 // Delay the deletion till the caller finishes.
66 base::ThreadTaskRunnerHandle::Get()->PostTask(
67 FROM_HERE,
68 base::Bind(&DeleteBackgroundTaskHelper, base::Passed(std::move(task_))));
47 } 69 }
48 70
49 } // namespace offline_pages 71 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698