Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 ++count; | 66 ++count; |
| 67 } else { | 67 } else { |
| 68 ++iter; | 68 ++iter; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 base::ThreadTaskRunnerHandle::Get()->PostTask( | 72 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 73 FROM_HERE, base::Bind(callback, true, count)); | 73 FROM_HERE, base::Bind(callback, true, count)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void RequestQueueInMemoryStore::PauseRequests( | |
| 77 const std::vector<int64_t>& request_ids, | |
| 78 const UpdateCallback& callback) { | |
| 79 UpdateStatus status = SetStateForRequestIds( | |
| 80 request_ids, SavePageRequest::RequestState::PAUSED); | |
| 81 | |
| 82 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 83 FROM_HERE, base::Bind(callback, status)); | |
| 84 } | |
| 85 | |
| 86 void RequestQueueInMemoryStore::ResumeRequests( | |
| 87 const std::vector<int64_t>& request_ids, | |
| 88 const UpdateCallback& callback) { | |
| 89 | |
| 90 UpdateStatus status = SetStateForRequestIds( | |
| 91 request_ids, SavePageRequest::RequestState::AVAILABLE); | |
| 92 | |
| 93 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 94 FROM_HERE, base::Bind(callback, status)); | |
| 95 } | |
| 96 | |
| 97 RequestQueueStore::UpdateStatus | |
| 98 RequestQueueInMemoryStore::SetStateForRequestIds( | |
| 99 const std::vector<int64_t>& request_ids, | |
| 100 SavePageRequest::RequestState newState) { | |
| 101 int count = 0; | |
| 102 | |
| 103 std::set<int64_t> request_id_set(request_ids.begin(), request_ids.end()); | |
| 104 for (auto iter = requests_.begin(); iter != requests_.end(); ++iter) { | |
|
Dmitry Titov
2016/08/09 21:01:43
I think requests_ is already a map from request_id
Pete Williamson
2016/08/10 01:34:10
Done.
| |
| 105 if (request_id_set.find(iter->second.request_id()) != | |
| 106 request_id_set.end()) { | |
| 107 // Set the state if the client ID matches. | |
| 108 iter->second.set_request_state(newState); | |
| 109 ++count; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 return count > 0 ? UpdateStatus::UPDATED : UpdateStatus::FAILED; | |
| 114 } | |
| 115 | |
| 76 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { | 116 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { |
| 77 requests_.clear(); | 117 requests_.clear(); |
| 78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 118 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 79 base::Bind(callback, true)); | 119 base::Bind(callback, true)); |
| 80 } | 120 } |
| 81 | 121 |
| 82 } // namespace offline_pages | 122 } // namespace offline_pages |
| OLD | NEW |