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

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

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
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 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_TEST_TASK_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_TEST_TASK_H_
7
8 #include "components/offline_pages/core/task.h"
9
10 namespace offline_pages {
11
12 // Sample resource consumed by the task during execution. In this set of tests
13 // used to provide the capability to continue the task.
14 class ConsumedResource {
15 public:
16 ConsumedResource();
17 ~ConsumedResource();
18
19 void Step(const base::Closure& step_callback);
20 void CompleteStep();
21 bool HasNextStep() const { return !next_step_.is_null(); }
22
23 private:
24 base::Closure next_step_;
25 };
26
27 // Sample test task. This should not be used as a example of task implementation
28 // with respect to callback safety. Otherwise it captures the idea of splitting
29 // the work into multiple steps separated by potentially asynchronous calls
30 // spanning multiple threads.
31 //
32 // For an implementation example of a task that covers problems better is
33 // |offline_pages::ChangeRequestsStateTask|.
34 class TestTask : public Task {
35 public:
36 enum class TaskState { NOT_STARTED, STEP_1, STEP_2, COMPLETED };
37
38 explicit TestTask(ConsumedResource* resource);
39 TestTask(ConsumedResource* resource, bool leave_early);
40 ~TestTask() override;
41
42 // Run is Step 1 in our case.
43 void Run() override;
44
45 void Step2();
46
47 void LastStep();
48
49 TaskState state() const { return state_; }
50
51 private:
52 ConsumedResource* resource_;
53 TaskState state_;
54 bool leave_early_;
55 };
56
57 } // namespace offline_pages
58
59 #endif // COMPONENTS_OFFLINE_PAGES_CORE_TEST_TASK_H_
OLDNEW
« no previous file with comments | « components/offline_pages/core/task_unittest.cc ('k') | components/offline_pages/core/test_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698