| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/offline_pages/background/remove_requests_task.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 | |
| 9 namespace offline_pages { | |
| 10 | |
| 11 RemoveRequestsTask::RemoveRequestsTask( | |
| 12 RequestQueueStore* store, | |
| 13 const std::vector<int64_t>& request_ids, | |
| 14 const RequestQueueStore::UpdateCallback& callback) | |
| 15 : store_(store), | |
| 16 request_ids_(request_ids), | |
| 17 callback_(callback), | |
| 18 weak_ptr_factory_(this) {} | |
| 19 | |
| 20 RemoveRequestsTask::~RemoveRequestsTask() {} | |
| 21 | |
| 22 void RemoveRequestsTask::Run() { | |
| 23 RemoveRequests(); | |
| 24 } | |
| 25 | |
| 26 void RemoveRequestsTask::RemoveRequests() { | |
| 27 if (request_ids_.empty()) { | |
| 28 CompleteEarly(ItemActionStatus::NOT_FOUND); | |
| 29 return; | |
| 30 } | |
| 31 | |
| 32 store_->RemoveRequests(request_ids_, | |
| 33 base::Bind(&RemoveRequestsTask::CompleteWithResult, | |
| 34 weak_ptr_factory_.GetWeakPtr())); | |
| 35 } | |
| 36 | |
| 37 void RemoveRequestsTask::CompleteEarly(ItemActionStatus status) { | |
| 38 // TODO(fgorski): store_->state() once implemented | |
| 39 std::unique_ptr<UpdateRequestsResult> result( | |
| 40 new UpdateRequestsResult(StoreState::LOADED)); | |
| 41 for (int64_t request_id : request_ids_) | |
| 42 result->item_statuses.push_back(std::make_pair(request_id, status)); | |
| 43 CompleteWithResult(std::move(result)); | |
| 44 } | |
| 45 | |
| 46 void RemoveRequestsTask::CompleteWithResult( | |
| 47 std::unique_ptr<UpdateRequestsResult> result) { | |
| 48 callback_.Run(std::move(result)); | |
| 49 TaskComplete(); | |
| 50 } | |
| 51 | |
| 52 } // namespace offline_pages | |
| OLD | NEW |