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_TASK_TASK_H_
6 #define COMPONENTS_OFFLINE_PAGES_TASK_TASK_H_
7 
8 #include "base/callback.h"
9 
10 namespace offline_pages {
11 
12 // A task which may run asynchronous steps. Its primary purpose is to implement
13 // operations to be inserted into a |TaskQueue|, however, tasks can also be run
14 // outside of a |TaskQueue|.
15 class Task {
16  public:
17   Task();
18   virtual ~Task();
19   Task(const Task&) = delete;
20   Task& operator=(const Task&) = delete;
21 
22   void Execute(base::OnceClosure complete_callback);
23 
24  protected:
25   // Entry point to the task. Called by |Execute()| to perform the task.
26   // Must call |TaskComplete()| as the final step.
27   virtual void Run() = 0;
28 
29   // Tasks must call |TaskComplete()| as their last step.
30   void TaskComplete();
31 
32   base::OnceClosure task_completion_callback_;
33   bool completed_ = false;
34   bool started_ = false;
35 };
36 
37 }  // namespace offline_pages
38 
39 #endif  // COMPONENTS_OFFLINE_PAGES_TASK_TASK_H_
40