Chromium Code Reviews| 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/mark_attempt_started_task.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/time/time.h" | |
| 11 | |
| 12 namespace offline_pages { | |
| 13 | |
| 14 MarkAttemptStartedTask::MarkAttemptStartedTask( | |
| 15 RequestQueueStore* store, | |
| 16 int64_t request_id, | |
| 17 const RequestQueueStore::UpdateCallback& callback) | |
| 18 : store_(store), | |
| 19 request_id_(request_id), | |
| 20 callback_(callback), | |
| 21 weak_ptr_factory_(this) {} | |
| 22 | |
| 23 MarkAttemptStartedTask::~MarkAttemptStartedTask() {} | |
| 24 | |
| 25 void MarkAttemptStartedTask::Run() { | |
| 26 ReadRequest(); | |
| 27 } | |
| 28 | |
| 29 void MarkAttemptStartedTask::ReadRequest() { | |
| 30 std::vector<int64_t> request_ids{request_id_}; | |
| 31 store_->GetRequestsByIds( | |
| 32 request_ids, base::Bind(&MarkAttemptStartedTask::MarkAttemptStarted, | |
| 33 weak_ptr_factory_.GetWeakPtr())); | |
| 34 } | |
| 35 | |
| 36 void MarkAttemptStartedTask::MarkAttemptStarted( | |
| 37 std::unique_ptr<UpdateRequestsResult> read_result) { | |
| 38 if (read_result->store_state != StoreState::LOADED || | |
| 39 read_result->item_statuses.front().second != ItemActionStatus::SUCCESS || | |
| 40 read_result->updated_items.size() != 1) { | |
| 41 CompleteWithResult(std::move(read_result)); | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 // TODO(petewil): Is there any extra verification we want to do here? | |
|
Pete Williamson
2016/10/14 17:02:35
I can't think of any verification for starting a t
fgorski
2016/10/14 20:37:19
This is up to the caller to check/decide/report. W
| |
| 46 read_result->updated_items[0].MarkAttemptStarted(base::Time::Now()); | |
|
Pete Williamson
2016/10/14 17:02:35
I'm a bit surprised that updated_items isn't const
fgorski
2016/10/14 20:37:18
We are given our own result, that we are consuming
| |
| 47 store_->UpdateRequests(read_result->updated_items, | |
| 48 base::Bind(&MarkAttemptStartedTask::CompleteWithResult, | |
| 49 weak_ptr_factory_.GetWeakPtr())); | |
| 50 } | |
| 51 | |
| 52 void MarkAttemptStartedTask::CompleteWithResult( | |
| 53 std::unique_ptr<UpdateRequestsResult> result) { | |
| 54 callback_.Run(std::move(result)); | |
| 55 TaskComplete(); | |
| 56 } | |
| 57 | |
| 58 } // namespace offline_pages | |
| OLD | NEW |