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

Side by Side 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 change (TODO) 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_in_memory_store.h" 5 #include "components/offline_pages/background/request_queue_in_memory_store.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/save_page_request.h" 10 #include "components/offline_pages/background/save_page_request.h"
(...skipping 20 matching lines...) Expand all
31 if (iter != requests_.end()) 31 if (iter != requests_.end())
32 requests_.erase(iter); 32 requests_.erase(iter);
33 requests_.insert(std::make_pair(request.request_id(), request)); 33 requests_.insert(std::make_pair(request.request_id(), request));
34 base::ThreadTaskRunnerHandle::Get()->PostTask( 34 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 FROM_HERE, base::Bind(callback, UpdateStatus::UPDATED)); 35 FROM_HERE, base::Bind(callback, UpdateStatus::UPDATED));
36 } 36 }
37 37
38 void RequestQueueInMemoryStore::RemoveRequests( 38 void RequestQueueInMemoryStore::RemoveRequests(
39 const std::vector<int64_t>& request_ids, 39 const std::vector<int64_t>& request_ids,
40 const RemoveCallback& callback) { 40 const RemoveCallback& callback) {
41 // In case the |request_ids| is empty, the result will be true, but the count
42 // of deleted pages will be empty.
43 int count = 0; 41 int count = 0;
44 RequestsMap::iterator iter; 42 RequestsMap::iterator iter;
45 for (auto request_id : request_ids) { 43 for (auto request_id : request_ids) {
46 iter = requests_.find(request_id); 44 iter = requests_.find(request_id);
47 if (iter != requests_.end()) { 45 if (iter != requests_.end()) {
48 requests_.erase(iter); 46 requests_.erase(iter);
49 ++count; 47 ++count;
50 } 48 }
51 } 49 }
52 50
53 base::ThreadTaskRunnerHandle::Get()->PostTask( 51 base::ThreadTaskRunnerHandle::Get()->PostTask(
54 FROM_HERE, base::Bind(callback, true, count)); 52 FROM_HERE, base::Bind(callback, true, count));
55 } 53 }
56 54
55 void RequestQueueInMemoryStore::RemoveRequestsByClientId(
56 const std::vector<ClientId>& client_ids,
57 const RemoveCallback& callback) {
58 int count = 0;
59
60 // Once for each client id in our list
61 for (auto client_id : client_ids) {
fgorski 2016/08/02 05:01:22 const auto&
Pete Williamson 2016/08/02 23:27:17 Done.
62 // Check it against each request in the store.
63 for (auto iter = requests_.begin();
64 iter != requests_.end();
65 ++iter) {
fgorski 2016/08/02 05:01:22 (I am aware this is only used for testing, but con
Pete Williamson 2016/08/02 23:27:17 OK, but I had to add operator< to ClientID to make
fgorski 2016/08/03 03:29:41 That is because it is backed by BST. Have you trie
Pete Williamson 2016/08/03 19:51:08 I think it might be faster as an ordered set - usi
66 // Check against each incoming client ID, and delete if we have a match.
67 if ((*iter).second.client_id() == client_id) {
68 requests_.erase(iter);
69 // This delete will invalidate the iterator, so move on to the next
70 // entry.
71 ++count;
72 break;
73 }
74 }
75 }
76
77 base::ThreadTaskRunnerHandle::Get()->PostTask(
78 FROM_HERE, base::Bind(callback, true, count));
79 }
80
57 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { 81 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {
58 requests_.clear(); 82 requests_.clear();
59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 83 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
60 base::Bind(callback, true)); 84 base::Bind(callback, true));
61 } 85 }
62 86
63 } // namespace offline_pages 87 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698