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

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

Issue 2373933003: [Offline pages] Updating RequestQueue::RemoveRequests to use a TaskQueue (Closed)
Patch Set: Addressing final feedback 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/remove_requests_task.cc
diff --git a/components/offline_pages/background/remove_requests_task.cc b/components/offline_pages/background/remove_requests_task.cc
new file mode 100644
index 0000000000000000000000000000000000000000..15d45fe6acf0d79125206e066699b064b1109df6
--- /dev/null
+++ b/components/offline_pages/background/remove_requests_task.cc
@@ -0,0 +1,52 @@
+// 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/remove_requests_task.h"
+
+#include "base/bind.h"
+
+namespace offline_pages {
+
+RemoveRequestsTask::RemoveRequestsTask(
+ RequestQueueStore* store,
+ const std::vector<int64_t>& request_ids,
+ const RequestQueueStore::UpdateCallback& callback)
+ : store_(store),
+ request_ids_(request_ids),
+ callback_(callback),
+ weak_ptr_factory_(this) {}
+
+RemoveRequestsTask::~RemoveRequestsTask() {}
+
+void RemoveRequestsTask::Run() {
+ RemoveRequests();
+}
+
+void RemoveRequestsTask::RemoveRequests() {
+ if (request_ids_.empty()) {
+ CompleteEarly(ItemActionStatus::NOT_FOUND);
+ return;
+ }
+
+ store_->RemoveRequests(request_ids_,
+ base::Bind(&RemoveRequestsTask::CompleteWithResult,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void RemoveRequestsTask::CompleteEarly(ItemActionStatus status) {
+ // TODO(fgorski): store_->state() once implemented
+ std::unique_ptr<UpdateRequestsResult> result(
+ new UpdateRequestsResult(StoreState::LOADED));
+ for (int64_t request_id : request_ids_)
+ result->item_statuses.push_back(std::make_pair(request_id, status));
+ CompleteWithResult(std::move(result));
+}
+
+void RemoveRequestsTask::CompleteWithResult(
+ std::unique_ptr<UpdateRequestsResult> result) {
+ callback_.Run(std::move(result));
+ TaskComplete();
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698