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

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

Issue 2219393004: Adds an observer for the request coordinator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resumeAPI
Patch Set: Fix nits. Created 4 years, 4 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 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/offline_pages/background/request_queue_store.h" 10 #include "components/offline_pages/background/request_queue_store.h"
(...skipping 21 matching lines...) Expand all
32 const SavePageRequest& request, 32 const SavePageRequest& request,
33 RequestQueueStore::UpdateStatus status) { 33 RequestQueueStore::UpdateStatus status) {
34 RequestQueue::AddRequestResult result = 34 RequestQueue::AddRequestResult result =
35 (status == RequestQueueStore::UpdateStatus::UPDATED) 35 (status == RequestQueueStore::UpdateStatus::UPDATED)
36 ? RequestQueue::AddRequestResult::SUCCESS 36 ? RequestQueue::AddRequestResult::SUCCESS
37 : RequestQueue::AddRequestResult::STORE_FAILURE; 37 : RequestQueue::AddRequestResult::STORE_FAILURE;
38 callback.Run(result, request); 38 callback.Run(result, request);
39 } 39 }
40 40
41 // Completes the update request call. 41 // Completes the update request call.
42 // TODO(petewil): Move callers to the UpdateMultipleRequestDone callback
42 void UpdateRequestDone(const RequestQueue::UpdateRequestCallback& callback, 43 void UpdateRequestDone(const RequestQueue::UpdateRequestCallback& callback,
43 RequestQueueStore::UpdateStatus status) { 44 RequestQueueStore::UpdateStatus status) {
44 RequestQueue::UpdateRequestResult result = 45 RequestQueue::UpdateRequestResult result =
45 (status == RequestQueueStore::UpdateStatus::UPDATED) 46 (status == RequestQueueStore::UpdateStatus::UPDATED)
46 ? RequestQueue::UpdateRequestResult::SUCCESS 47 ? RequestQueue::UpdateRequestResult::SUCCESS
47 : RequestQueue::UpdateRequestResult::STORE_FAILURE; 48 : RequestQueue::UpdateRequestResult::STORE_FAILURE;
48 callback.Run(result); 49 callback.Run(result);
49 } 50 }
50 51
52 // Handles updating multiple requests at the same time.
53 void UpdateMultipleRequestsDone(
54 const RequestQueue::UpdateMultipleRequestsCallback& callback,
55 const RequestQueue::UpdateMultipleRequestResults& results,
56 const std::vector<SavePageRequest>& requests) {
57 callback.Run(results, requests);
58 }
51 59
52 // Completes the remove request call. 60 // Completes the remove request call.
53 void RemoveRequestsDone( 61 void RemoveRequestsDone(
54 const RequestQueue::RemoveRequestsCallback& callback, 62 const RequestQueue::RemoveRequestsCallback& callback,
55 const RequestQueue::UpdateMultipleRequestResults& results) { 63 const RequestQueue::UpdateMultipleRequestResults& results,
56 callback.Run(results); 64 const std::vector<SavePageRequest>& requests) {
65 callback.Run(results, requests);
57 } 66 }
58 67
59 } // namespace 68 } // namespace
60 69
61 RequestQueue::RequestQueue(std::unique_ptr<RequestQueueStore> store) 70 RequestQueue::RequestQueue(std::unique_ptr<RequestQueueStore> store)
62 : store_(std::move(store)), weak_ptr_factory_(this) {} 71 : store_(std::move(store)), weak_ptr_factory_(this) {}
63 72
64 RequestQueue::~RequestQueue() {} 73 RequestQueue::~RequestQueue() {}
65 74
66 void RequestQueue::GetRequests(const GetRequestsCallback& callback) { 75 void RequestQueue::GetRequests(const GetRequestsCallback& callback) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 135 }
127 136
128 void RequestQueue::RemoveRequests(const std::vector<int64_t>& request_ids, 137 void RequestQueue::RemoveRequests(const std::vector<int64_t>& request_ids,
129 const RemoveRequestsCallback& callback) { 138 const RemoveRequestsCallback& callback) {
130 store_->RemoveRequests(request_ids, base::Bind(RemoveRequestsDone, callback)); 139 store_->RemoveRequests(request_ids, base::Bind(RemoveRequestsDone, callback));
131 } 140 }
132 141
133 void RequestQueue::ChangeRequestsState( 142 void RequestQueue::ChangeRequestsState(
134 const std::vector<int64_t>& request_ids, 143 const std::vector<int64_t>& request_ids,
135 const SavePageRequest::RequestState new_state, 144 const SavePageRequest::RequestState new_state,
136 const UpdateRequestCallback& callback) { 145 const UpdateMultipleRequestsCallback& callback) {
137 store_->ChangeRequestsState(request_ids, new_state, 146 store_->ChangeRequestsState(request_ids, new_state,
138 base::Bind(UpdateRequestDone, callback)); 147 base::Bind(UpdateMultipleRequestsDone, callback));
139 } 148 }
140 149
141 void RequestQueue::PurgeRequests(const PurgeRequestsCallback& callback) {} 150 void RequestQueue::PurgeRequests(const PurgeRequestsCallback& callback) {}
142 151
143 } // namespace offline_pages 152 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698