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

Unified Diff: components/offline_pages/background/request_queue_in_memory_store.cc

Issue 2197573003: Provide API in RequestCoordinator to remove results by client ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment changes per feedback 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 defb87e311ffed9c84328e47b31764f9da3d00d9..32219a91616eef459ea08ab4fb7116258f781355 100644
--- a/components/offline_pages/background/request_queue_in_memory_store.cc
+++ b/components/offline_pages/background/request_queue_in_memory_store.cc
@@ -4,6 +4,8 @@
#include "components/offline_pages/background/request_queue_in_memory_store.h"
+#include <set>
+
#include "base/bind.h"
#include "base/location.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -38,8 +40,6 @@ void RequestQueueInMemoryStore::AddOrUpdateRequest(
void RequestQueueInMemoryStore::RemoveRequests(
const std::vector<int64_t>& request_ids,
const RemoveCallback& callback) {
- // In case the |request_ids| is empty, the result will be true, but the count
- // of deleted pages will be empty.
int count = 0;
RequestsMap::iterator iter;
for (auto request_id : request_ids) {
@@ -54,6 +54,25 @@ void RequestQueueInMemoryStore::RemoveRequests(
FROM_HERE, base::Bind(callback, true, count));
}
+void RequestQueueInMemoryStore::RemoveRequestsByClientId(
+ const std::vector<ClientId>& client_ids,
+ const RemoveCallback& callback) {
+ int count = 0;
+
+ std::set<ClientId> client_id_set(client_ids.begin(), client_ids.end());
+ for (auto iter = requests_.begin(); iter != requests_.end(); ) {
+ if (client_id_set.find(iter->second.client_id()) != client_id_set.end()) {
+ requests_.erase(iter++);
+ ++count;
+ } else {
+ ++iter;
+ }
+ }
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, true, count));
+}
+
void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {
requests_.clear();
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,

Powered by Google App Engine
This is Rietveld 408576698