| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // Returns true if the message loop is "idle". Provided for testing. | 309 // Returns true if the message loop is "idle". Provided for testing. |
| 310 bool IsIdleForTesting(); | 310 bool IsIdleForTesting(); |
| 311 | 311 |
| 312 // Returns the TaskAnnotator which is used to add debug information to posted | 312 // Returns the TaskAnnotator which is used to add debug information to posted |
| 313 // tasks. | 313 // tasks. |
| 314 debug::TaskAnnotator* task_annotator() { return &task_annotator_; } | 314 debug::TaskAnnotator* task_annotator() { return &task_annotator_; } |
| 315 | 315 |
| 316 // Runs the specified PendingTask. | 316 // Runs the specified PendingTask. |
| 317 void RunTask(const PendingTask& pending_task); | 317 void RunTask(const PendingTask& pending_task); |
| 318 | 318 |
| 319 // Disables running nested loops and Add/RemoveNestingObserver(). |
| 320 void DisableNesting() { enable_nesting_ = false; } |
| 321 |
| 322 // Disables Add/RemoveDestructionObserver(). |
| 323 void DisableDestructionObservers() { enable_destruction_observers_ = false; } |
| 324 |
| 325 // Disables Add/RemoveTaskObserver(). |
| 326 void DisableTaskObservers() { enable_task_observers_ = false; } |
| 327 |
| 319 //---------------------------------------------------------------------------- | 328 //---------------------------------------------------------------------------- |
| 320 protected: | 329 protected: |
| 321 std::unique_ptr<MessagePump> pump_; | 330 std::unique_ptr<MessagePump> pump_; |
| 322 | 331 |
| 323 using MessagePumpFactoryCallback = Callback<std::unique_ptr<MessagePump>()>; | 332 using MessagePumpFactoryCallback = Callback<std::unique_ptr<MessagePump>()>; |
| 324 | 333 |
| 325 // Common protected constructor. Other constructors delegate the | 334 // Common protected constructor. Other constructors delegate the |
| 326 // initialization to this constructor. | 335 // initialization to this constructor. |
| 327 // A subclass can invoke this constructor to create a message_loop of a | 336 // A subclass can invoke this constructor to create a message_loop of a |
| 328 // specific type with a custom loop. The implementation does not call | 337 // specific type with a custom loop. The implementation does not call |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 453 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
| 445 | 454 |
| 446 // The task runner associated with this message loop. | 455 // The task runner associated with this message loop. |
| 447 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 456 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| 448 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 457 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
| 449 | 458 |
| 450 // Id of the thread this message loop is bound to. Initialized once when the | 459 // Id of the thread this message loop is bound to. Initialized once when the |
| 451 // MessageLoop is bound to its thread and constant forever after. | 460 // MessageLoop is bound to its thread and constant forever after. |
| 452 PlatformThreadId thread_id_; | 461 PlatformThreadId thread_id_; |
| 453 | 462 |
| 463 // Enable running nested loops and Add/RemoveNestingObserver(). |
| 464 bool enable_nesting_ = true; |
| 465 |
| 466 // Enable Add/RemoveDestructionObserver(). |
| 467 bool enable_destruction_observers_ = true; |
| 468 |
| 469 // Enable Add/RemoveTaskObserver(). |
| 470 bool enable_task_observers_ = true; |
| 471 |
| 454 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 472 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
| 455 }; | 473 }; |
| 456 | 474 |
| 457 #if !defined(OS_NACL) | 475 #if !defined(OS_NACL) |
| 458 | 476 |
| 459 //----------------------------------------------------------------------------- | 477 //----------------------------------------------------------------------------- |
| 460 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 478 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
| 461 // MessageLoop instantiated with TYPE_UI. | 479 // MessageLoop instantiated with TYPE_UI. |
| 462 // | 480 // |
| 463 // This class is typically used like so: | 481 // This class is typically used like so: |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 609 |
| 592 // Do not add any member variables to MessageLoopForIO! This is important b/c | 610 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 593 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 611 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 594 // data that you need should be stored on the MessageLoop's pump_ instance. | 612 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 595 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 613 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 596 "MessageLoopForIO should not have extra member variables"); | 614 "MessageLoopForIO should not have extra member variables"); |
| 597 | 615 |
| 598 } // namespace base | 616 } // namespace base |
| 599 | 617 |
| 600 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 618 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |