| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 namespace android { | 39 namespace android { |
| 40 | 40 |
| 41 class JavaMessageHandlerFactory; | 41 class JavaMessageHandlerFactory; |
| 42 | 42 |
| 43 } // namespace android | 43 } // namespace android |
| 44 } // namespace base | 44 } // namespace base |
| 45 #endif // defined(OS_ANDROID) | 45 #endif // defined(OS_ANDROID) |
| 46 | 46 |
| 47 namespace base { | 47 namespace base { |
| 48 | 48 |
| 49 class HistogramBase; | |
| 50 class RunLoop; | 49 class RunLoop; |
| 51 class ThreadTaskRunnerHandle; | 50 class ThreadTaskRunnerHandle; |
| 52 class WaitableEvent; | 51 class WaitableEvent; |
| 53 | 52 |
| 54 // A MessageLoop is used to process events for a particular thread. There is | 53 // A MessageLoop is used to process events for a particular thread. There is |
| 55 // at most one MessageLoop instance per thread. | 54 // at most one MessageLoop instance per thread. |
| 56 // | 55 // |
| 57 // Events include at a minimum Task instances submitted to the MessageLoop's | 56 // Events include at a minimum Task instances submitted to the MessageLoop's |
| 58 // TaskRunner. Depending on the type of message pump used by the MessageLoop | 57 // TaskRunner. Depending on the type of message pump used by the MessageLoop |
| 59 // other events such as UI messages may be processed. On Windows APC calls (as | 58 // other events such as UI messages may be processed. On Windows APC calls (as |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 explicit MessageLoop(Type type = TYPE_DEFAULT); | 121 explicit MessageLoop(Type type = TYPE_DEFAULT); |
| 123 // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must | 122 // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must |
| 124 // be non-NULL. | 123 // be non-NULL. |
| 125 explicit MessageLoop(std::unique_ptr<MessagePump> pump); | 124 explicit MessageLoop(std::unique_ptr<MessagePump> pump); |
| 126 | 125 |
| 127 ~MessageLoop() override; | 126 ~MessageLoop() override; |
| 128 | 127 |
| 129 // Returns the MessageLoop object for the current thread, or null if none. | 128 // Returns the MessageLoop object for the current thread, or null if none. |
| 130 static MessageLoop* current(); | 129 static MessageLoop* current(); |
| 131 | 130 |
| 132 static void EnableHistogrammer(bool enable_histogrammer); | |
| 133 | |
| 134 typedef std::unique_ptr<MessagePump>(MessagePumpFactory)(); | 131 typedef std::unique_ptr<MessagePump>(MessagePumpFactory)(); |
| 135 // Uses the given base::MessagePumpForUIFactory to override the default | 132 // Uses the given base::MessagePumpForUIFactory to override the default |
| 136 // MessagePump implementation for 'TYPE_UI'. Returns true if the factory | 133 // MessagePump implementation for 'TYPE_UI'. Returns true if the factory |
| 137 // was successfully registered. | 134 // was successfully registered. |
| 138 static bool InitMessagePumpForUIFactory(MessagePumpFactory* factory); | 135 static bool InitMessagePumpForUIFactory(MessagePumpFactory* factory); |
| 139 | 136 |
| 140 // Creates the default MessagePump based on |type|. Caller owns return | 137 // Creates the default MessagePump based on |type|. Caller owns return |
| 141 // value. | 138 // value. |
| 142 static std::unique_ptr<MessagePump> CreateMessagePumpForType(Type type); | 139 static std::unique_ptr<MessagePump> CreateMessagePumpForType(Type type); |
| 143 | 140 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 bool DeletePendingTasks(); | 387 bool DeletePendingTasks(); |
| 391 | 388 |
| 392 // Loads tasks from the incoming queue to |work_queue_| if the latter is | 389 // Loads tasks from the incoming queue to |work_queue_| if the latter is |
| 393 // empty. | 390 // empty. |
| 394 void ReloadWorkQueue(); | 391 void ReloadWorkQueue(); |
| 395 | 392 |
| 396 // Wakes up the message pump. Can be called on any thread. The caller is | 393 // Wakes up the message pump. Can be called on any thread. The caller is |
| 397 // responsible for synchronizing ScheduleWork() calls. | 394 // responsible for synchronizing ScheduleWork() calls. |
| 398 void ScheduleWork(); | 395 void ScheduleWork(); |
| 399 | 396 |
| 400 // Start recording histogram info about events and action IF it was enabled | |
| 401 // and IF the statistics recorder can accept a registration of our histogram. | |
| 402 void StartHistogrammer(); | |
| 403 | |
| 404 // Add occurrence of event to our histogram, so that we can see what is being | |
| 405 // done in a specific MessageLoop instance (i.e., specific thread). | |
| 406 // If message_histogram_ is NULL, this is a no-op. | |
| 407 void HistogramEvent(int event); | |
| 408 | |
| 409 // Notify observers that a nested message loop is starting. | 397 // Notify observers that a nested message loop is starting. |
| 410 void NotifyBeginNestedLoop(); | 398 void NotifyBeginNestedLoop(); |
| 411 | 399 |
| 412 // MessagePump::Delegate methods: | 400 // MessagePump::Delegate methods: |
| 413 bool DoWork() override; | 401 bool DoWork() override; |
| 414 bool DoDelayedWork(TimeTicks* next_delayed_work_time) override; | 402 bool DoDelayedWork(TimeTicks* next_delayed_work_time) override; |
| 415 bool DoIdleWork() override; | 403 bool DoIdleWork() override; |
| 416 | 404 |
| 417 const Type type_; | 405 const Type type_; |
| 418 | 406 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 446 ObserverList<NestingObserver> nesting_observers_; | 434 ObserverList<NestingObserver> nesting_observers_; |
| 447 | 435 |
| 448 // A recursion block that prevents accidentally running additional tasks when | 436 // A recursion block that prevents accidentally running additional tasks when |
| 449 // insider a (accidentally induced?) nested message pump. | 437 // insider a (accidentally induced?) nested message pump. |
| 450 bool nestable_tasks_allowed_; | 438 bool nestable_tasks_allowed_; |
| 451 | 439 |
| 452 // pump_factory_.Run() is called to create a message pump for this loop | 440 // pump_factory_.Run() is called to create a message pump for this loop |
| 453 // if type_ is TYPE_CUSTOM and pump_ is null. | 441 // if type_ is TYPE_CUSTOM and pump_ is null. |
| 454 MessagePumpFactoryCallback pump_factory_; | 442 MessagePumpFactoryCallback pump_factory_; |
| 455 | 443 |
| 456 // A profiling histogram showing the counts of various messages and events. | |
| 457 HistogramBase* message_histogram_; | |
| 458 | |
| 459 RunLoop* run_loop_; | 444 RunLoop* run_loop_; |
| 460 | 445 |
| 461 ObserverList<TaskObserver> task_observers_; | 446 ObserverList<TaskObserver> task_observers_; |
| 462 | 447 |
| 463 debug::TaskAnnotator task_annotator_; | 448 debug::TaskAnnotator task_annotator_; |
| 464 | 449 |
| 465 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; | 450 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
| 466 | 451 |
| 467 // A task runner which we haven't bound to a thread yet. | 452 // A task runner which we haven't bound to a thread yet. |
| 468 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 453 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 600 |
| 616 // Do not add any member variables to MessageLoopForIO! This is important b/c | 601 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 617 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 602 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 618 // data that you need should be stored on the MessageLoop's pump_ instance. | 603 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 619 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 604 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 620 "MessageLoopForIO should not have extra member variables"); | 605 "MessageLoopForIO should not have extra member variables"); |
| 621 | 606 |
| 622 } // namespace base | 607 } // namespace base |
| 623 | 608 |
| 624 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 609 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |