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

Side by Side Diff: components/offline_pages/background/remove_requests_task.cc

Issue 2373933003: [Offline pages] Updating RequestQueue::RemoveRequests to use a TaskQueue (Closed)
Patch Set: Rebasing 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 unified diff | Download patch
OLDNEW
(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)
Pete Williamson 2016/09/30 18:03:53 Let's apply the renames from the other (TaskQueue
fgorski 2016/10/04 17:18:23 Acknowledged.
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 if (request_ids_.empty()) {
24 CompleteEarly(ItemActionStatus::NOT_FOUND);
25 return;
26 }
27
28 store_->RemoveRequests(request_ids_,
29 base::Bind(&RemoveRequestsTask::CompleteWithResult,
30 weak_ptr_factory_.GetWeakPtr()));
31 }
32
33 void RemoveRequestsTask::CompleteEarly(ItemActionStatus status) {
34 // TODO(fgorski): store_->state() once implemented
35 std::unique_ptr<UpdateRequestsResult> result(
36 new UpdateRequestsResult(StoreState::LOADED));
37 for (int64_t request_id : request_ids_)
38 result->item_statuses.push_back(std::make_pair(request_id, status));
39 CompleteWithResult(std::move(result));
40 }
41
42 void RemoveRequestsTask::CompleteWithResult(
43 std::unique_ptr<UpdateRequestsResult> result) {
44 callback_.Run(std::move(result));
45 Complete();
46 }
47
48 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698