Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
|
Pete Williamson
2016/09/29 00:54:44
Would it be worthwhile to make it a good example?
fgorski
2016/09/29 17:37:37
No point in making this better as this is a test s
| |
| 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 class TestTask : public Task { | |
| 32 public: | |
| 33 enum class TaskState { NOT_STARTED, STEP_1, STEP_2, COMPLETED }; | |
| 34 | |
| 35 explicit TestTask(ConsumedResource* resource); | |
| 36 TestTask(ConsumedResource* resource, bool leave_early); | |
| 37 ~TestTask() override; | |
| 38 | |
| 39 // Run is Step 1 in our case. | |
| 40 void Run() override; | |
| 41 | |
| 42 void Step2(); | |
|
dougarnett
2016/09/29 15:40:05
Maybe good to promote the "step" terminology in th
fgorski
2016/09/29 17:37:37
No I don't believe that. I actually thought about
| |
| 43 | |
| 44 void LastStep(); | |
| 45 | |
| 46 TaskState state() const { return state_; } | |
| 47 | |
| 48 private: | |
| 49 ConsumedResource* resource_; | |
| 50 TaskState state_; | |
| 51 bool leave_early_; | |
| 52 }; | |
| 53 | |
| 54 } // namespace offline_pages | |
| 55 | |
| 56 #endif // COMPONENTS_OFFLINE_PAGES_CORE_TEST_TASK_H_ | |
| OLD | NEW |