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

Unified Diff: components/offline_pages/background/request_queue_in_memory_store.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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/request_queue_in_memory_store.cc
diff --git a/components/offline_pages/background/request_queue_in_memory_store.cc b/components/offline_pages/background/request_queue_in_memory_store.cc
index e6348e8f4c6f2ad7a57ae5caa417b00062dbc26c..d5355fdf7bfaa7dd1a0482f5813357d224cde840 100644
--- a/components/offline_pages/background/request_queue_in_memory_store.cc
+++ b/components/offline_pages/background/request_queue_in_memory_store.cc
@@ -40,41 +40,52 @@ void RequestQueueInMemoryStore::RemoveRequests(
const RemoveCallback& callback) {
RequestQueue::UpdateMultipleRequestResults results;
RequestQueue::UpdateRequestResult result;
+ std::vector<SavePageRequest> requests;
RequestsMap::iterator iter;
+
+ // If we find a request, mark it as succeeded, and put it in the request list.
+ // Otherwise mark it as failed.
for (auto request_id : request_ids) {
iter = requests_.find(request_id);
if (iter != requests_.end()) {
+ SavePageRequest request = iter->second;
requests_.erase(iter);
result = RequestQueue::UpdateRequestResult::SUCCESS;
+ requests.push_back(request);
} else {
result = RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST;
}
results.push_back(std::make_pair(request_id, result));
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, results));
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, results, requests));
}
void RequestQueueInMemoryStore::ChangeRequestsState(
const std::vector<int64_t>& request_ids,
const SavePageRequest::RequestState new_state,
- const UpdateCallback& callback) {
- int count = 0;
-
+ const UpdateMultipleRequestsCallback& callback) {
+ RequestQueue::UpdateMultipleRequestResults results;
+ std::vector<SavePageRequest> requests;
+ RequestQueue::UpdateRequestResult result;
for (int64_t request_id : request_ids) {
auto pair = requests_.find(request_id);
+ // If we find this request id, modify it, and return the modified request in
+ // the request list.
if (pair != requests_.end()) {
- ++count;
pair->second.set_request_state(new_state);
+ requests.push_back(pair->second);
+ result = RequestQueue::UpdateRequestResult::SUCCESS;
+ } else {
+ result = RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST;;
}
- }
- RequestQueueStore::UpdateStatus status =
- count > 0 ? UpdateStatus::UPDATED : UpdateStatus::FAILED;
+ results.push_back(std::make_pair(request_id, result));
+ }
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, status));
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, results, requests));
}
void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {

Powered by Google App Engine
This is Rietveld 408576698