| 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 |
| 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_ |
| OLD | NEW |