OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ | |
6 #define CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ | |
7 | |
8 #include <list> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 | |
14 #include "build/build_config.h" | |
15 | |
16 namespace content { | |
17 | |
18 // This class runs startup tasks. The tasks are either run immediately inline, | |
19 // or are queued one at a time on the UI thread's message loop. If the events | |
20 // are queued, UI events that are received during startup will be acted upon | |
21 // between startup tasks. The motivation for this is that, on targets where the | |
22 // UI is already started, it allows us to keep the UI responsive during startup. | |
23 // | |
24 // Note that this differs from a SingleThreadedTaskRunner in that there may be | |
25 // no opportunity to handle UI events between the tasks of a | |
26 // SingleThreadedTaskRunner. | |
27 | |
28 class StartupTaskRunner : public base::RefCounted<StartupTaskRunner> { | |
29 public: | |
30 class Observer { | |
31 public: | |
32 virtual ~Observer() {} | |
33 // Called when all tasks have been run | |
34 virtual void AllStartupTasksRan() = 0; | |
jam
2013/07/24 06:45:24
see content api link about not having single-metho
aberent
2013/07/24 22:18:31
Done.
| |
35 }; | |
36 | |
37 enum StartupMode { | |
38 IMMEDIATE, | |
39 INCREMENTAL | |
40 }; | |
41 | |
42 // Constructor: Note that the observer is optional. The code will check for | |
43 // a NULL observer before attempting to call observer functions. | |
44 StartupTaskRunner(StartupMode mode, Observer* observer); | |
45 | |
46 // Add a task to the queue of startup tasks to be run. | |
47 virtual void AddTask(base::Closure& callback); | |
48 | |
49 // Set the task runner to use to run the tasks | |
50 virtual void SetProxy( | |
51 const scoped_refptr<base::SingleThreadTaskRunner>& proxy); | |
52 | |
53 // Start running the tasks. | |
54 virtual void StartRunningTasks(); | |
55 | |
56 private: | |
57 | |
58 friend class base::RefCounted<StartupTaskRunner>; | |
59 virtual ~StartupTaskRunner() {}; | |
60 | |
61 std::list<base::Closure> task_list_; | |
62 void WrappedTask(); | |
63 | |
64 StartupMode startup_mode_; | |
65 Observer* observer_; | |
66 scoped_refptr<base::SingleThreadTaskRunner> proxy_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(StartupTaskRunner); | |
jam
2013/07/24 06:45:24
see content api docs about interfaces vs concrete
aberent
2013/07/24 22:18:31
After looking at this I realized that I don't actu
| |
69 }; | |
70 | |
71 } // namespace content | |
72 #endif // CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ | |
OLD | NEW |