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

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: CR feedback per DougArnett 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 21 matching lines...) Expand all
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 41 // In case the |request_ids| is empty, the result will be true, but the count
42 // of deleted pages will be empty. 42 // of deleted pages will be 0.
43 int count = 0; 43 int count = 0;
44 RequestsMap::iterator iter; 44 RequestsMap::iterator iter;
45 for (auto request_id : request_ids) { 45 for (auto request_id : request_ids) {
46 iter = requests_.find(request_id); 46 iter = requests_.find(request_id);
47 if (iter != requests_.end()) { 47 if (iter != requests_.end()) {
48 requests_.erase(iter); 48 requests_.erase(iter);
49 ++count; 49 ++count;
50 } 50 }
51 } 51 }
52 52
53 base::ThreadTaskRunnerHandle::Get()->PostTask( 53 base::ThreadTaskRunnerHandle::Get()->PostTask(
54 FROM_HERE, base::Bind(callback, true, count)); 54 FROM_HERE, base::Bind(callback, true, count));
55 } 55 }
56 56
57 void RequestQueueInMemoryStore::RemoveRequestsByClientId(
58 const std::vector<ClientId>& client_ids,
59 const RemoveCallback& callback) {
60 // In case the |client_ids| is empty, the result will be true, but the count
Dmitry Titov 2016/08/01 19:37:31 If this comment is moved to .h file, it'll be easi
Pete Williamson 2016/08/01 23:23:07 Done.
61 // of deleted pages will be 0.
62 int count = 0;
63
64 // Once for each client id in our list
65 for (auto client_id : client_ids) {
66 // Check it against each request in the store.
67 for (auto iter = requests_.begin();
68 iter != requests_.end();
69 ++iter) {
70 // Check against each incoming client ID, and delete if we have a match.
71 if ((*iter).second.client_id() == client_id) {
72 requests_.erase(iter);
73 // This delete will invalidate the iterator, so move on to the next
74 // entry.
75 ++count;
76 break;
77 }
78 }
79 }
80
81 base::ThreadTaskRunnerHandle::Get()->PostTask(
82 FROM_HERE, base::Bind(callback, true, count));
83 }
84
57 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { 85 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {
58 requests_.clear(); 86 requests_.clear();
59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
60 base::Bind(callback, true)); 88 base::Bind(callback, true));
61 } 89 }
62 90
63 } // namespace offline_pages 91 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698