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

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

Issue 2568613002: Reconcile the request queue on startup. (Closed)
Patch Set: compile fix 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
« no previous file with comments | « components/offline_pages/core/background/request_queue.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/core/background/request_queue.h" 5 #include "components/offline_pages/core/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/core/background/add_request_task.h" 12 #include "components/offline_pages/core/background/add_request_task.h"
13 #include "components/offline_pages/core/background/change_requests_state_task.h" 13 #include "components/offline_pages/core/background/change_requests_state_task.h"
14 #include "components/offline_pages/core/background/get_requests_task.h" 14 #include "components/offline_pages/core/background/get_requests_task.h"
15 #include "components/offline_pages/core/background/initialize_store_task.h" 15 #include "components/offline_pages/core/background/initialize_store_task.h"
16 #include "components/offline_pages/core/background/mark_attempt_aborted_task.h" 16 #include "components/offline_pages/core/background/mark_attempt_aborted_task.h"
17 #include "components/offline_pages/core/background/mark_attempt_completed_task.h " 17 #include "components/offline_pages/core/background/mark_attempt_completed_task.h "
18 #include "components/offline_pages/core/background/mark_attempt_started_task.h" 18 #include "components/offline_pages/core/background/mark_attempt_started_task.h"
19 #include "components/offline_pages/core/background/pick_request_task.h" 19 #include "components/offline_pages/core/background/pick_request_task.h"
20 #include "components/offline_pages/core/background/reconcile_task.h"
20 #include "components/offline_pages/core/background/remove_requests_task.h" 21 #include "components/offline_pages/core/background/remove_requests_task.h"
21 #include "components/offline_pages/core/background/request_queue_store.h" 22 #include "components/offline_pages/core/background/request_queue_store.h"
22 #include "components/offline_pages/core/background/save_page_request.h" 23 #include "components/offline_pages/core/background/save_page_request.h"
23 24
24 namespace offline_pages { 25 namespace offline_pages {
25 26
26 namespace { 27 namespace {
27 // Completes the get requests call. 28 // Completes the get requests call.
28 void GetRequestsDone(const RequestQueue::GetRequestsCallback& callback, 29 void GetRequestsDone(const RequestQueue::GetRequestsCallback& callback,
29 bool success, 30 bool success,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Using the PickerContext, create a picker task. 132 // Using the PickerContext, create a picker task.
132 std::unique_ptr<Task> task(new PickRequestTask( 133 std::unique_ptr<Task> task(new PickRequestTask(
133 store_.get(), policy, picked_callback, not_picked_callback, 134 store_.get(), policy, picked_callback, not_picked_callback,
134 request_count_callback, conditions, disabled_requests)); 135 request_count_callback, conditions, disabled_requests));
135 136
136 // Queue up the picking task, it will call one of the callbacks when it 137 // Queue up the picking task, it will call one of the callbacks when it
137 // completes. 138 // completes.
138 task_queue_.AddTask(std::move(task)); 139 task_queue_.AddTask(std::move(task));
139 } 140 }
140 141
142 void RequestQueue::ReconcileRequests(const UpdateCallback& callback) {
143 std::unique_ptr<Task> task(new ReconcileTask(store_.get(), callback));
144
145 // Queue up the reconcile task.
146 task_queue_.AddTask(std::move(task));
147 }
148
141 void RequestQueue::CleanupRequestQueue() { 149 void RequestQueue::CleanupRequestQueue() {
142 // Create a cleanup task. 150 // Create a cleanup task.
143 std::unique_ptr<Task> task(cleanup_factory_->CreateCleanupTask(store_.get())); 151 std::unique_ptr<Task> task(cleanup_factory_->CreateCleanupTask(store_.get()));
144 152
145 // Queue up the cleanup task. 153 // Queue up the cleanup task.
146 task_queue_.AddTask(std::move(task)); 154 task_queue_.AddTask(std::move(task));
147 } 155 }
148 156
149 void RequestQueue::Initialize() { 157 void RequestQueue::Initialize() {
150 std::unique_ptr<Task> task(new InitializeStoreTask( 158 std::unique_ptr<Task> task(new InitializeStoreTask(
151 store_.get(), base::Bind(&RequestQueue::InitializeStoreDone, 159 store_.get(), base::Bind(&RequestQueue::InitializeStoreDone,
152 weak_ptr_factory_.GetWeakPtr()))); 160 weak_ptr_factory_.GetWeakPtr())));
153 task_queue_.AddTask(std::move(task)); 161 task_queue_.AddTask(std::move(task));
154 } 162 }
155 163
156 void RequestQueue::InitializeStoreDone(bool success) { 164 void RequestQueue::InitializeStoreDone(bool success) {
157 // TODO(fgorski): Result can be ignored for now. Report UMA in future. 165 // TODO(fgorski): Result can be ignored for now. Report UMA in future.
158 // No need to pass the result up to RequestCoordinator. 166 // No need to pass the result up to RequestCoordinator.
159 } 167 }
160 168
161 } // namespace offline_pages 169 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/core/background/request_queue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698