Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/offline_pages/background/request_queue_in_memory_store.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/thread_task_runner_handle.h" | |
| 10 #include "components/offline_pages/background/save_page_request.h" | |
| 11 | |
| 12 namespace offline_pages { | |
| 13 | |
| 14 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {} | |
| 15 | |
| 16 RequestQueueInMemoryStore::~RequestQueueInMemoryStore() {} | |
| 17 | |
| 18 void RequestQueueInMemoryStore::GetRequests( | |
|
Pete Williamson
2016/05/03 20:38:52
In the future, it might be nice to be able to sear
fgorski
2016/05/03 21:50:21
Acknowledged.
| |
| 19 const GetRequestsCallback& callback) { | |
| 20 std::vector<SavePageRequest> result; | |
| 21 for (const auto& id_request_pair : requests_) | |
| 22 result.push_back(id_request_pair.second); | |
| 23 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 24 FROM_HERE, base::Bind(callback, true, result)); | |
|
Pete Williamson
2016/05/03 20:38:52
Would it make sense to batch these? This seems li
fgorski
2016/05/03 21:50:21
What is there to batch here exactly?
This method m
Pete Williamson
2016/05/03 22:00:24
Ah, never mind, I missed that the result was a vec
dougarnett
2016/05/03 22:11:54
perhaps if "result" was named "results", it would
fgorski
2016/05/03 23:01:42
I see. I updated this to result_requests. I hope i
| |
| 25 } | |
| 26 | |
| 27 void RequestQueueInMemoryStore::AddOrUpdateRequest( | |
| 28 const SavePageRequest& request, | |
| 29 const UpdateCallback& callback) { | |
| 30 RequestsMap::iterator iter = requests_.find(request.request_id()); | |
| 31 if (iter != requests_.end()) | |
| 32 requests_.erase(iter); | |
| 33 requests_.insert(std::make_pair(request.request_id(), request)); | |
| 34 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
| 35 base::Bind(callback, true)); | |
| 36 } | |
| 37 | |
| 38 void RequestQueueInMemoryStore::RemoveRequests( | |
| 39 const std::vector<int64_t>& request_ids, | |
| 40 const UpdateCallback& callback) { | |
| 41 // We report true if the request ids is an empty list, or when we deleted at | |
| 42 // least one request. | |
|
Pete Williamson
2016/05/03 20:38:52
So how will the caller know when the list was empt
fgorski
2016/05/03 21:50:21
Done.
| |
| 43 bool result = request_ids.empty(); | |
| 44 | |
| 45 RequestsMap::iterator iter; | |
| 46 for (auto request_id : request_ids) { | |
| 47 iter = requests_.find(request_id); | |
| 48 if (iter != requests_.end()) { | |
| 49 requests_.erase(iter); | |
| 50 result = true; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
| 55 base::Bind(callback, result)); | |
| 56 } | |
| 57 | |
| 58 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { | |
| 59 // TODO(fgorski): use thread task runner handle to post the results back. | |
| 60 requests_.clear(); | |
| 61 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
| 62 base::Bind(callback, true)); | |
| 63 } | |
| 64 | |
| 65 } // namespace offline_pages | |
| OLD | NEW |