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

Side by Side Diff: components/offline_pages/core/test_task.cc

Issue 2359933007: [Offline pages] Introduces TaskQueue to serialize tasks that asynchronously access SQLStore (Closed)
Patch Set: Addressing feedback from Dmitry 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
« no previous file with comments | « components/offline_pages/core/test_task.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/core/test_task.h"
6
7 #include "base/bind.h"
8
9 namespace offline_pages {
10
11 ConsumedResource::ConsumedResource() {}
12
13 ConsumedResource::~ConsumedResource() {}
14
15 void ConsumedResource::Step(const base::Closure& step_callback) {
16 next_step_ = step_callback;
17 }
18
19 void ConsumedResource::CompleteStep() {
20 base::Closure temp_ = next_step_;
21 next_step_.Reset();
22 temp_.Run();
23 }
24
25 TestTask::TestTask(ConsumedResource* resource)
26 : resource_(resource),
27 state_(TaskState::NOT_STARTED),
28 leave_early_(false) {}
29
30 TestTask::TestTask(ConsumedResource* resource, bool leave_early)
31 : resource_(resource),
32 state_(TaskState::NOT_STARTED),
33 leave_early_(leave_early) {}
34
35 TestTask::~TestTask() {}
36
37 // Run is Step 1 in our case.
38 void TestTask::Run() {
39 state_ = TaskState::STEP_1;
40 resource_->Step(base::Bind(&TestTask::Step2, base::Unretained(this)));
41 }
42
43 void TestTask::Step2() {
44 if (leave_early_) {
45 LastStep();
46 return;
47 }
48 state_ = TaskState::STEP_2;
49 resource_->Step(base::Bind(&TestTask::LastStep, base::Unretained(this)));
50 }
51
52 // This is step 3, but we conclude here.
53 void TestTask::LastStep() {
54 state_ = TaskState::COMPLETED;
55 TaskComplete();
56 }
57
58 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/core/test_task.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698