| 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 <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // TYPE_IO | 121 // TYPE_IO |
| 122 // This type of ML also supports asynchronous IO. See also | 122 // This type of ML also supports asynchronous IO. See also |
| 123 // MessageLoopForIO. | 123 // MessageLoopForIO. |
| 124 // | 124 // |
| 125 // TYPE_JAVA | 125 // TYPE_JAVA |
| 126 // This type of ML is backed by a Java message handler which is responsible | 126 // This type of ML is backed by a Java message handler which is responsible |
| 127 // for running the tasks added to the ML. This is only for use on Android. | 127 // for running the tasks added to the ML. This is only for use on Android. |
| 128 // TYPE_JAVA behaves in essence like TYPE_UI, except during construction | 128 // TYPE_JAVA behaves in essence like TYPE_UI, except during construction |
| 129 // where it does not use the main thread specific pump factory. | 129 // where it does not use the main thread specific pump factory. |
| 130 // | 130 // |
| 131 // TYPE_CUSTOM |
| 132 // MessagePump was supplied to constructor. |
| 133 // |
| 131 enum Type { | 134 enum Type { |
| 132 TYPE_DEFAULT, | 135 TYPE_DEFAULT, |
| 133 TYPE_UI, | 136 TYPE_UI, |
| 137 TYPE_CUSTOM, |
| 134 #if defined(TOOLKIT_GTK) | 138 #if defined(TOOLKIT_GTK) |
| 135 TYPE_GPU, | 139 TYPE_GPU, |
| 136 #endif | 140 #endif |
| 137 TYPE_IO, | 141 TYPE_IO, |
| 138 #if defined(OS_ANDROID) | 142 #if defined(OS_ANDROID) |
| 139 TYPE_JAVA, | 143 TYPE_JAVA, |
| 140 #endif // defined(OS_ANDROID) | 144 #endif // defined(OS_ANDROID) |
| 141 }; | 145 }; |
| 142 | 146 |
| 143 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it | 147 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it |
| 144 // is typical to make use of the current thread's MessageLoop instance. | 148 // is typical to make use of the current thread's MessageLoop instance. |
| 145 explicit MessageLoop(Type type = TYPE_DEFAULT); | 149 explicit MessageLoop(Type type = TYPE_DEFAULT); |
| 150 // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must |
| 151 // be non-NULL. |
| 152 explicit MessageLoop(scoped_ptr<base::MessagePump> pump); |
| 146 virtual ~MessageLoop(); | 153 virtual ~MessageLoop(); |
| 147 | 154 |
| 148 // Returns the MessageLoop object for the current thread, or null if none. | 155 // Returns the MessageLoop object for the current thread, or null if none. |
| 149 static MessageLoop* current(); | 156 static MessageLoop* current(); |
| 150 | 157 |
| 151 static void EnableHistogrammer(bool enable_histogrammer); | 158 static void EnableHistogrammer(bool enable_histogrammer); |
| 152 | 159 |
| 153 typedef MessagePump* (MessagePumpFactory)(); | 160 typedef MessagePump* (MessagePumpFactory)(); |
| 154 // Uses the given base::MessagePumpForUIFactory to override the default | 161 // Uses the given base::MessagePumpForUIFactory to override the default |
| 155 // MessagePump implementation for 'TYPE_UI'. Returns true if the factory | 162 // MessagePump implementation for 'TYPE_UI'. Returns true if the factory |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 442 } |
| 436 #endif | 443 #endif |
| 437 #endif | 444 #endif |
| 438 | 445 |
| 439 scoped_ptr<MessagePump> pump_; | 446 scoped_ptr<MessagePump> pump_; |
| 440 | 447 |
| 441 private: | 448 private: |
| 442 friend class internal::IncomingTaskQueue; | 449 friend class internal::IncomingTaskQueue; |
| 443 friend class RunLoop; | 450 friend class RunLoop; |
| 444 | 451 |
| 452 // Configures various members for the two constructors. |
| 453 void Init(); |
| 454 |
| 445 // A function to encapsulate all the exception handling capability in the | 455 // A function to encapsulate all the exception handling capability in the |
| 446 // stacks around the running of a main message loop. It will run the message | 456 // stacks around the running of a main message loop. It will run the message |
| 447 // loop in a SEH try block or not depending on the set_SEH_restoration() | 457 // loop in a SEH try block or not depending on the set_SEH_restoration() |
| 448 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). | 458 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). |
| 449 void RunHandler(); | 459 void RunHandler(); |
| 450 | 460 |
| 451 #if defined(OS_WIN) | 461 #if defined(OS_WIN) |
| 452 __declspec(noinline) void RunInternalInSEHFrame(); | 462 __declspec(noinline) void RunInternalInSEHFrame(); |
| 453 #endif | 463 #endif |
| 454 | 464 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 // If message_histogram_ is NULL, this is a no-op. | 507 // If message_histogram_ is NULL, this is a no-op. |
| 498 void HistogramEvent(int event); | 508 void HistogramEvent(int event); |
| 499 | 509 |
| 500 // MessagePump::Delegate methods: | 510 // MessagePump::Delegate methods: |
| 501 virtual bool DoWork() OVERRIDE; | 511 virtual bool DoWork() OVERRIDE; |
| 502 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; | 512 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; |
| 503 virtual bool DoIdleWork() OVERRIDE; | 513 virtual bool DoIdleWork() OVERRIDE; |
| 504 virtual void GetQueueingInformation(size_t* queue_size, | 514 virtual void GetQueueingInformation(size_t* queue_size, |
| 505 TimeDelta* queueing_delay) OVERRIDE; | 515 TimeDelta* queueing_delay) OVERRIDE; |
| 506 | 516 |
| 507 Type type_; | 517 const Type type_; |
| 508 | 518 |
| 509 // A list of tasks that need to be processed by this instance. Note that | 519 // A list of tasks that need to be processed by this instance. Note that |
| 510 // this queue is only accessed (push/pop) by our current thread. | 520 // this queue is only accessed (push/pop) by our current thread. |
| 511 TaskQueue work_queue_; | 521 TaskQueue work_queue_; |
| 512 | 522 |
| 513 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 523 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
| 514 DelayedTaskQueue delayed_work_queue_; | 524 DelayedTaskQueue delayed_work_queue_; |
| 515 | 525 |
| 516 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 526 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
| 517 TimeTicks recent_time_; | 527 TimeTicks recent_time_; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 | 741 |
| 732 // Do not add any member variables to MessageLoopForIO! This is important b/c | 742 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 733 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 743 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 734 // data that you need should be stored on the MessageLoop's pump_ instance. | 744 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 735 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 745 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 736 MessageLoopForIO_should_not_have_extra_member_variables); | 746 MessageLoopForIO_should_not_have_extra_member_variables); |
| 737 | 747 |
| 738 } // namespace base | 748 } // namespace base |
| 739 | 749 |
| 740 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 750 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |