| Index: base/message_loop/message_loop.h
|
| diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
|
| index fd7596a79204ed89291f32b2f9135108a73b2882..b20baf03559dd8c7094d6f6bab6b65b5226c4ab7 100644
|
| --- a/base/message_loop/message_loop.h
|
| +++ b/base/message_loop/message_loop.h
|
| @@ -109,12 +109,44 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
|
| #endif // defined(OS_ANDROID)
|
| };
|
|
|
| + // Init options.
|
| + struct BASE_EXPORT InitOptions {
|
| + using MessagePumpFactory = Callback<scoped_ptr<MessagePump>()>;
|
| + InitOptions();
|
| + ~InitOptions();
|
| +
|
| + // Specify the type of message loop.
|
| + // This is ignored if message_pump_factory.is_null() is false.
|
| + MessageLoop::Type message_loop_type;
|
| +
|
| + // Specify timer slack for the message loop.
|
| + TimerSlack timer_slack;
|
| +
|
| + // Used to create the MessagePump for the MessageLoop.
|
| + // If message_pump_factory.is_null() is true, then a MessagePump appropriate
|
| + // for |message_loop_type| is created. Setting this forces the
|
| + // MessageLoop::Type to TYPE_CUSTOM.
|
| + MessagePumpFactory message_pump_factory;
|
| + };
|
| +
|
| + // Creates a MessageLoop with |options|. It is valid to create a new
|
| + // message loop on a different thread from the final 'current' thread,
|
| + // and then pass it to the final thread where the message loop actually
|
| + // runs. The caller must call Init method on the final 'current'
|
| + // thread before calling Run to start running tasks on the message loop.
|
| + //
|
| // Normally, it is not necessary to instantiate a MessageLoop. Instead, it
|
| // is typical to make use of the current thread's MessageLoop instance.
|
| + explicit MessageLoop(const InitOptions& options);
|
| +
|
| + // Creates a MessageLoop of |type| for the current thread. Usually this
|
| + // constructor is used only for testing. No need to call Init if the
|
| + // message loop is constructed this way.
|
| explicit MessageLoop(Type type = TYPE_DEFAULT);
|
| - // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must
|
| - // be non-NULL.
|
| - explicit MessageLoop(scoped_ptr<base::MessagePump> pump);
|
| + // Creates a TYPE_CUSTOM MessageLoop for the current thread with the
|
| + // supplied MessagePump, which must be non-NULL. Usually used only for
|
| + // testing. No need to call Init if the message loop is constructed this way.
|
| + explicit MessageLoop(scoped_ptr<MessagePump> pump);
|
| ~MessageLoop() override;
|
|
|
| // Returns the MessageLoop object for the current thread, or null if none.
|
| @@ -147,6 +179,9 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
|
| virtual ~DestructionObserver();
|
| };
|
|
|
| + // Configure various members and bind this message loop to the current thread.
|
| + void Init();
|
| +
|
| // Add a DestructionObserver, which will start receiving notifications
|
| // immediately.
|
| void AddDestructionObserver(DestructionObserver* destruction_observer);
|
| @@ -394,10 +429,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
|
| // Returns true if the message loop is "idle". Provided for testing.
|
| bool IsIdleForTesting();
|
|
|
| - // Wakes up the message pump. Can be called on any thread. The caller is
|
| - // responsible for synchronizing ScheduleWork() calls.
|
| - void ScheduleWork();
|
| -
|
| // Returns the TaskAnnotator which is used to add debug information to posted
|
| // tasks.
|
| debug::TaskAnnotator* task_annotator() { return &task_annotator_; }
|
| @@ -411,9 +442,12 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
|
|
|
| private:
|
| friend class RunLoop;
|
| + friend class internal::IncomingTaskQueue;
|
| + friend class ScheduleWorkTest;
|
|
|
| - // Configures various members for the two constructors.
|
| - void Init();
|
| + // Wakes up the message pump. Can be called on any thread. The caller is
|
| + // responsible for synchronizing ScheduleWork() calls.
|
| + void ScheduleWork();
|
|
|
| // Invokes the actual run loop using the message pump.
|
| void RunHandler();
|
| @@ -490,6 +524,8 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
|
| bool os_modal_loop_;
|
| #endif
|
|
|
| + scoped_ptr<InitOptions> init_options_;
|
| +
|
| std::string thread_name_;
|
| // A profiling histogram showing the counts of various messages and events.
|
| HistogramBase* message_histogram_;
|
|
|