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

Unified Diff: components/offline_pages/background/mark_attempt_started_task.cc

Issue 2416083002: [Offline pages] Introduction of MarkAttemptStartedTask with tests (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/mark_attempt_started_task.cc
diff --git a/components/offline_pages/background/mark_attempt_started_task.cc b/components/offline_pages/background/mark_attempt_started_task.cc
new file mode 100644
index 0000000000000000000000000000000000000000..83fb3a1f2da858ca9810f40839743bad0709213f
--- /dev/null
+++ b/components/offline_pages/background/mark_attempt_started_task.cc
@@ -0,0 +1,58 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/offline_pages/background/mark_attempt_started_task.h"
+
+#include <vector>
+
+#include "base/bind.h"
+#include "base/time/time.h"
+
+namespace offline_pages {
+
+MarkAttemptStartedTask::MarkAttemptStartedTask(
+ RequestQueueStore* store,
+ int64_t request_id,
+ const RequestQueueStore::UpdateCallback& callback)
+ : store_(store),
+ request_id_(request_id),
+ callback_(callback),
+ weak_ptr_factory_(this) {}
+
+MarkAttemptStartedTask::~MarkAttemptStartedTask() {}
+
+void MarkAttemptStartedTask::Run() {
+ ReadRequest();
+}
+
+void MarkAttemptStartedTask::ReadRequest() {
+ std::vector<int64_t> request_ids{request_id_};
+ store_->GetRequestsByIds(
+ request_ids, base::Bind(&MarkAttemptStartedTask::MarkAttemptStarted,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void MarkAttemptStartedTask::MarkAttemptStarted(
+ std::unique_ptr<UpdateRequestsResult> read_result) {
+ if (read_result->store_state != StoreState::LOADED ||
+ read_result->item_statuses.front().second != ItemActionStatus::SUCCESS ||
+ read_result->updated_items.size() != 1) {
+ CompleteWithResult(std::move(read_result));
+ return;
+ }
+
+ // 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
+ 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
+ store_->UpdateRequests(read_result->updated_items,
+ base::Bind(&MarkAttemptStartedTask::CompleteWithResult,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void MarkAttemptStartedTask::CompleteWithResult(
+ std::unique_ptr<UpdateRequestsResult> result) {
+ callback_.Run(std::move(result));
+ TaskComplete();
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698