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

Side by Side Diff: components/offline_pages/background/request_queue_in_memory_store.cc

Issue 2228813003: Changes to fit better with the needs of the download manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 <set>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/location.h" 8 #include "base/location.h"
11 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/offline_pages/background/save_page_request.h" 10 #include "components/offline_pages/background/save_page_request.h"
13 11
14 namespace offline_pages { 12 namespace offline_pages {
15 13
16 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {} 14 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {}
17 15
18 RequestQueueInMemoryStore::~RequestQueueInMemoryStore() {} 16 RequestQueueInMemoryStore::~RequestQueueInMemoryStore() {}
(...skipping 28 matching lines...) Expand all
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
57 void RequestQueueInMemoryStore::RemoveRequestsByClientId(
58 const std::vector<ClientId>& client_ids,
59 const RemoveCallback& callback) {
60 int count = 0;
61
62 std::set<ClientId> client_id_set(client_ids.begin(), client_ids.end());
63 for (auto iter = requests_.begin(); iter != requests_.end(); ) {
64 if (client_id_set.find(iter->second.client_id()) != client_id_set.end()) {
65 requests_.erase(iter++);
66 ++count;
67 } else {
68 ++iter;
69 }
70 }
71
72 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 FROM_HERE, base::Bind(callback, true, count));
74 }
75
76 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { 55 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {
77 requests_.clear(); 56 requests_.clear();
78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 57 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
79 base::Bind(callback, true)); 58 base::Bind(callback, true));
80 } 59 }
81 60
82 } // namespace offline_pages 61 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698