Chromium Code Reviews| 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..c08ef7455682e16706ebe981cddca0e647733f7b 100644 |
| --- a/base/message_loop/message_loop.h |
| +++ b/base/message_loop/message_loop.h |
| @@ -109,12 +109,33 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { |
| #endif // defined(OS_ANDROID) |
| }; |
| + using MessagePumpFactoryCallback = Callback<scoped_ptr<MessagePump>()>; |
| + |
| + // Creates a MessageLoop of |type|. If |type| is TYPE_CUSTOM |
| + // non-null |pump_factory| must be also given to create a message pump |
| + // for this message loop. Otherwise a default message pump for |
| + // the |type| is created. |
| + // |
| + // It is valid to create a new message loop on one thread, and then pass |
| + // it to the thread where the message loop actually runs. The message |
| + // loop's BindToCurrentThread() method must be called on the thread |
| + // the message loop runs on, before calling Run(). |
|
Nico
2015/04/27 22:49:34
I'm not sure how to best communicate what can be d
kinuko
2015/04/28 15:43:25
Yeah that might be less confusing. In the new CL
|
| + // |
| // Normally, it is not necessary to instantiate a MessageLoop. Instead, it |
| // is typical to make use of the current thread's MessageLoop instance. |
| + MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); |
| + |
| + // TODO(kinuko): Cleanup these non-default constructors in a follow-up CL |
| + // for crbug.com/465458. |
| + // 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. |
|
Nico
2015/04/27 22:49:34
s/Init/BindToCurrentThread/
(I still think it's w
kinuko
2015/04/28 15:43:25
Done.
|
| + explicit MessageLoop(scoped_ptr<MessagePump> pump); |
| + |
| ~MessageLoop() override; |
| // Returns the MessageLoop object for the current thread, or null if none. |
| @@ -147,6 +168,9 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { |
| virtual ~DestructionObserver(); |
| }; |
| + // Configure various members and bind this message loop to the current thread. |
| + void BindToCurrentThread(); |
| + |
| // Add a DestructionObserver, which will start receiving notifications |
| // immediately. |
| void AddDestructionObserver(DestructionObserver* destruction_observer); |
| @@ -394,10 +418,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 +431,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 +513,10 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { |
| bool os_modal_loop_; |
| #endif |
| + // pump_factory_.Run() is called to create a message pump for this loop |
| + // if type_ is TYPE_CUSTOM and pump_ is null. |
| + MessagePumpFactoryCallback pump_factory_; |
| + |
| std::string thread_name_; |
| // A profiling histogram showing the counts of various messages and events. |
| HistogramBase* message_histogram_; |