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 #include "content/public/browser/browser_main_runner.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 typedef base::Callback<int(void)> StartupTask; |
| 21 |
| 22 // This class runs startup tasks. The tasks are either run immediately inline, |
| 23 // or are queued one at a time on the UI thread's message loop. If the events |
| 24 // are queued, UI events that are received during startup will be acted upon |
| 25 // between startup tasks. The motivation for this is that, on targets where the |
| 26 // UI is already started, it allows us to keep the UI responsive during startup. |
| 27 // |
| 28 // Note that this differs from a SingleThreadedTaskRunner in that there may be |
| 29 // no opportunity to handle UI events between the tasks of a |
| 30 // SingleThreadedTaskRunner. |
| 31 |
| 32 class CONTENT_EXPORT StartupTaskRunner |
| 33 : public base::RefCounted<StartupTaskRunner> { |
| 34 |
| 35 public: |
| 36 |
| 37 // Constructor: Note that |startup_complete_callback| is optional. If it is |
| 38 // not null it will be called once all the startup tasks have run. |
| 39 StartupTaskRunner(bool browser_may_start_asynchronously, |
| 40 void (*const startup_complete_callback)(int result), |
| 41 scoped_refptr<base::SingleThreadTaskRunner> proxy); |
| 42 |
| 43 // Add a task to the queue of startup tasks to be run. |
| 44 virtual void AddTask(StartupTask& callback); |
| 45 |
| 46 // Start running the tasks. |
| 47 virtual void StartRunningTasks(); |
| 48 |
| 49 private: |
| 50 |
| 51 friend class base::RefCounted<StartupTaskRunner>; |
| 52 virtual ~StartupTaskRunner(); |
| 53 |
| 54 std::list<StartupTask> task_list_; |
| 55 void WrappedTask(); |
| 56 |
| 57 const bool asynchronous_startup_; |
| 58 void (*const startup_complete_callback_)(int result); |
| 59 scoped_refptr<base::SingleThreadTaskRunner> proxy_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(StartupTaskRunner); |
| 62 }; |
| 63 |
| 64 } // namespace content |
| 65 #endif // CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ |
OLD | NEW |