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

Side by Side Diff: components/offline_pages/background/request_queue.cc

Issue 2543093002: Split the RequestPicker task into two separate tasks. (Closed)
Patch Set: ADD TODO 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/background/request_queue.h" 5 #include "components/offline_pages/background/request_queue.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/offline_pages/background/add_request_task.h" 12 #include "components/offline_pages/background/add_request_task.h"
13 #include "components/offline_pages/background/change_requests_state_task.h" 13 #include "components/offline_pages/background/change_requests_state_task.h"
14 #include "components/offline_pages/background/get_requests_task.h" 14 #include "components/offline_pages/background/get_requests_task.h"
15 #include "components/offline_pages/background/initialize_store_task.h" 15 #include "components/offline_pages/background/initialize_store_task.h"
16 #include "components/offline_pages/background/mark_attempt_aborted_task.h" 16 #include "components/offline_pages/background/mark_attempt_aborted_task.h"
17 #include "components/offline_pages/background/mark_attempt_completed_task.h" 17 #include "components/offline_pages/background/mark_attempt_completed_task.h"
18 #include "components/offline_pages/background/mark_attempt_started_task.h" 18 #include "components/offline_pages/background/mark_attempt_started_task.h"
19 #include "components/offline_pages/background/pick_request_task.h" 19 #include "components/offline_pages/background/pick_request_task.h"
20 #include "components/offline_pages/background/pick_request_task_factory.h"
21 #include "components/offline_pages/background/remove_requests_task.h" 20 #include "components/offline_pages/background/remove_requests_task.h"
22 #include "components/offline_pages/background/request_queue_store.h" 21 #include "components/offline_pages/background/request_queue_store.h"
23 #include "components/offline_pages/background/save_page_request.h" 22 #include "components/offline_pages/background/save_page_request.h"
24 23
25 namespace offline_pages { 24 namespace offline_pages {
26 25
27 namespace { 26 namespace {
28 // Completes the get requests call. 27 // Completes the get requests call.
29 void GetRequestsDone(const RequestQueue::GetRequestsCallback& callback, 28 void GetRequestsDone(const RequestQueue::GetRequestsCallback& callback,
30 bool success, 29 bool success,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 115 }
117 116
118 void RequestQueue::MarkAttemptCompleted(int64_t request_id, 117 void RequestQueue::MarkAttemptCompleted(int64_t request_id,
119 const UpdateCallback& callback) { 118 const UpdateCallback& callback) {
120 std::unique_ptr<Task> task( 119 std::unique_ptr<Task> task(
121 new MarkAttemptCompletedTask(store_.get(), request_id, callback)); 120 new MarkAttemptCompletedTask(store_.get(), request_id, callback));
122 task_queue_.AddTask(std::move(task)); 121 task_queue_.AddTask(std::move(task));
123 } 122 }
124 123
125 void RequestQueue::PickNextRequest( 124 void RequestQueue::PickNextRequest(
125 OfflinerPolicy* policy,
126 PickRequestTask::RequestPickedCallback picked_callback, 126 PickRequestTask::RequestPickedCallback picked_callback,
127 PickRequestTask::RequestNotPickedCallback not_picked_callback, 127 PickRequestTask::RequestNotPickedCallback not_picked_callback,
128 PickRequestTask::RequestCountCallback request_count_callback, 128 PickRequestTask::RequestCountCallback request_count_callback,
129 DeviceConditions& conditions, 129 DeviceConditions& conditions,
130 std::set<int64_t>& disabled_requests) { 130 std::set<int64_t>& disabled_requests) {
131 // Using the PickerContext, create a picker task. 131 // Using the PickerContext, create a picker task.
132 std::unique_ptr<Task> task(picker_factory_->CreatePickerTask( 132 std::unique_ptr<Task> task(new PickRequestTask(
133 store_.get(), picked_callback, not_picked_callback, 133 store_.get(), policy, picked_callback, not_picked_callback,
134 request_count_callback, conditions, disabled_requests)); 134 request_count_callback, conditions, disabled_requests));
135 135
136 // Queue up the picking task, it will call one of the callbacks when it 136 // Queue up the picking task, it will call one of the callbacks when it
137 // completes. 137 // completes.
138 task_queue_.AddTask(std::move(task)); 138 task_queue_.AddTask(std::move(task));
139 } 139 }
140 140
141 void RequestQueue::CleanupRequestQueue() {
142 // Create a cleanup task.
143 std::unique_ptr<Task> task(cleanup_factory_->CreateCleanupTask(store_.get()));
144
145 // Queue up the cleanup task.
146 task_queue_.AddTask(std::move(task));
147 }
148
141 void RequestQueue::Initialize() { 149 void RequestQueue::Initialize() {
142 std::unique_ptr<Task> task(new InitializeStoreTask( 150 std::unique_ptr<Task> task(new InitializeStoreTask(
143 store_.get(), base::Bind(&RequestQueue::InitializeStoreDone, 151 store_.get(), base::Bind(&RequestQueue::InitializeStoreDone,
144 weak_ptr_factory_.GetWeakPtr()))); 152 weak_ptr_factory_.GetWeakPtr())));
145 task_queue_.AddTask(std::move(task)); 153 task_queue_.AddTask(std::move(task));
146 } 154 }
147 155
148 void RequestQueue::InitializeStoreDone(bool success) { 156 void RequestQueue::InitializeStoreDone(bool success) {
149 // TODO(fgorski): Result can be ignored for now. Report UMA in future. 157 // TODO(fgorski): Result can be ignored for now. Report UMA in future.
150 // No need to pass the result up to RequestCoordinator. 158 // No need to pass the result up to RequestCoordinator.
151 } 159 }
152 160
153 } // namespace offline_pages 161 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_queue.h ('k') | components/offline_pages/background/request_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698