| 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 <algorithm> |
| 7 #include <set> | 8 #include <set> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "components/offline_pages/background/save_page_request.h" | 13 #include "components/offline_pages/background/save_page_request.h" |
| 13 | 14 |
| 14 namespace offline_pages { | 15 namespace offline_pages { |
| 15 | 16 |
| 16 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {} | 17 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ++count; | 67 ++count; |
| 67 } else { | 68 } else { |
| 68 ++iter; | 69 ++iter; |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 base::ThreadTaskRunnerHandle::Get()->PostTask( | 73 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 73 FROM_HERE, base::Bind(callback, true, count)); | 74 FROM_HERE, base::Bind(callback, true, count)); |
| 74 } | 75 } |
| 75 | 76 |
| 77 void RequestQueueInMemoryStore::ChangeRequestsState( |
| 78 const std::vector<int64_t>& request_ids, |
| 79 const SavePageRequest::RequestState new_state, |
| 80 const UpdateCallback& callback) { |
| 81 int count = 0; |
| 82 |
| 83 for (int64_t request_id : request_ids) { |
| 84 auto pair = requests_.find(request_id); |
| 85 if (pair != requests_.end()) { |
| 86 ++count; |
| 87 pair->second.set_request_state(new_state); |
| 88 } |
| 89 } |
| 90 |
| 91 RequestQueueStore::UpdateStatus status = |
| 92 count > 0 ? UpdateStatus::UPDATED : UpdateStatus::FAILED; |
| 93 |
| 94 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 95 base::Bind(callback, status)); |
| 96 } |
| 97 |
| 76 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { | 98 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { |
| 77 requests_.clear(); | 99 requests_.clear(); |
| 78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 100 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 79 base::Bind(callback, true)); | 101 base::Bind(callback, true)); |
| 80 } | 102 } |
| 81 | 103 |
| 82 } // namespace offline_pages | 104 } // namespace offline_pages |
| OLD | NEW |