| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef BASE_MESSAGE_LOOP_H_ |
| 6 #define BASE_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop_proxy.h" |
| 16 #include "base/message_pump.h" | 17 #include "base/message_pump.h" |
| 17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "base/task.h" | 20 #include "base/task.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 21 #include "base/tracked.h" | 22 #include "base/tracked.h" |
| 22 | 23 |
| 23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 24 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 25 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
| 25 // really just eliminate. | 26 // really just eliminate. |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // Returns the type passed to the constructor. | 265 // Returns the type passed to the constructor. |
| 265 Type type() const { return type_; } | 266 Type type() const { return type_; } |
| 266 | 267 |
| 267 // Optional call to connect the thread name with this loop. | 268 // Optional call to connect the thread name with this loop. |
| 268 void set_thread_name(const std::string& thread_name) { | 269 void set_thread_name(const std::string& thread_name) { |
| 269 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; | 270 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; |
| 270 thread_name_ = thread_name; | 271 thread_name_ = thread_name; |
| 271 } | 272 } |
| 272 const std::string& thread_name() const { return thread_name_; } | 273 const std::string& thread_name() const { return thread_name_; } |
| 273 | 274 |
| 275 // Gets the message loop proxy associated with this message loop proxy |
| 276 scoped_refptr<base::MessageLoopProxy> message_loop_proxy() { |
| 277 return message_loop_proxy_.get(); |
| 278 } |
| 279 |
| 274 // Enables or disables the recursive task processing. This happens in the case | 280 // Enables or disables the recursive task processing. This happens in the case |
| 275 // of recursive message loops. Some unwanted message loop may occurs when | 281 // of recursive message loops. Some unwanted message loop may occurs when |
| 276 // using common controls or printer functions. By default, recursive task | 282 // using common controls or printer functions. By default, recursive task |
| 277 // processing is disabled. | 283 // processing is disabled. |
| 278 // | 284 // |
| 279 // The specific case where tasks get queued is: | 285 // The specific case where tasks get queued is: |
| 280 // - The thread is running a message loop. | 286 // - The thread is running a message loop. |
| 281 // - It receives a task #1 and execute it. | 287 // - It receives a task #1 and execute it. |
| 282 // - The task #1 implicitly start a message loop, like a MessageBox in the | 288 // - The task #1 implicitly start a message loop, like a MessageBox in the |
| 283 // unit test. This can also be StartDoc or GetSaveFileName. | 289 // unit test. This can also be StartDoc or GetSaveFileName. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc | 572 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc |
| 567 // which enter a modal message loop. | 573 // which enter a modal message loop. |
| 568 bool os_modal_loop_; | 574 bool os_modal_loop_; |
| 569 #endif | 575 #endif |
| 570 | 576 |
| 571 // The next sequence number to use for delayed tasks. | 577 // The next sequence number to use for delayed tasks. |
| 572 int next_sequence_num_; | 578 int next_sequence_num_; |
| 573 | 579 |
| 574 ObserverList<TaskObserver> task_observers_; | 580 ObserverList<TaskObserver> task_observers_; |
| 575 | 581 |
| 582 // The message loop proxy associated with this message loop, if one exists. |
| 583 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 584 |
| 576 private: | 585 private: |
| 577 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 586 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
| 578 }; | 587 }; |
| 579 | 588 |
| 580 //----------------------------------------------------------------------------- | 589 //----------------------------------------------------------------------------- |
| 581 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 590 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
| 582 // MessageLoop instantiated with TYPE_UI. | 591 // MessageLoop instantiated with TYPE_UI. |
| 583 // | 592 // |
| 584 // This class is typically used like so: | 593 // This class is typically used like so: |
| 585 // MessageLoopForUI::current()->...call some method... | 594 // MessageLoopForUI::current()->...call some method... |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 #endif // defined(OS_POSIX) | 706 #endif // defined(OS_POSIX) |
| 698 }; | 707 }; |
| 699 | 708 |
| 700 // Do not add any member variables to MessageLoopForIO! This is important b/c | 709 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 701 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 710 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 702 // data that you need should be stored on the MessageLoop's pump_ instance. | 711 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 703 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 712 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 704 MessageLoopForIO_should_not_have_extra_member_variables); | 713 MessageLoopForIO_should_not_have_extra_member_variables); |
| 705 | 714 |
| 706 #endif // BASE_MESSAGE_LOOP_H_ | 715 #endif // BASE_MESSAGE_LOOP_H_ |
| OLD | NEW |