Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8522ce93879092745ceaf67b3f1a573330ebb1c6 |
| --- /dev/null |
| +++ b/components/offline_pages/background/request_queue_in_memory_store.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/offline_pages/background/request_queue_in_memory_store.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "components/offline_pages/background/save_page_request.h" |
| + |
| +namespace offline_pages { |
| + |
| +RequestQueueInMemoryStore::RequestQueueInMemoryStore() {} |
| + |
| +RequestQueueInMemoryStore::~RequestQueueInMemoryStore() {} |
| + |
| +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.
|
| + const GetRequestsCallback& callback) { |
| + std::vector<SavePageRequest> result; |
| + for (const auto& id_request_pair : requests_) |
| + result.push_back(id_request_pair.second); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + 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
|
| +} |
| + |
| +void RequestQueueInMemoryStore::AddOrUpdateRequest( |
| + const SavePageRequest& request, |
| + const UpdateCallback& callback) { |
| + RequestsMap::iterator iter = requests_.find(request.request_id()); |
| + if (iter != requests_.end()) |
| + requests_.erase(iter); |
| + requests_.insert(std::make_pair(request.request_id(), request)); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + base::Bind(callback, true)); |
| +} |
| + |
| +void RequestQueueInMemoryStore::RemoveRequests( |
| + const std::vector<int64_t>& request_ids, |
| + const UpdateCallback& callback) { |
| + // We report true if the request ids is an empty list, or when we deleted at |
| + // 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.
|
| + bool result = request_ids.empty(); |
| + |
| + RequestsMap::iterator iter; |
| + for (auto request_id : request_ids) { |
| + iter = requests_.find(request_id); |
| + if (iter != requests_.end()) { |
| + requests_.erase(iter); |
| + result = true; |
| + } |
| + } |
| + |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + base::Bind(callback, result)); |
| +} |
| + |
| +void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { |
| + // TODO(fgorski): use thread task runner handle to post the results back. |
| + requests_.clear(); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + base::Bind(callback, true)); |
| +} |
| + |
| +} // namespace offline_pages |