| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Disallow nesting. After this is called, running a nested RunLoop or calling | 319 // Disallow nesting. After this is called, running a nested RunLoop or calling |
| 320 // Add/RemoveNestingObserver() on this MessageLoop will crash. | 320 // Add/RemoveNestingObserver() on this MessageLoop will crash. |
| 321 void DisallowNesting() { allow_nesting_ = false; } | 321 void DisallowNesting() { allow_nesting_ = false; } |
| 322 | 322 |
| 323 // Disallow task observers. After this is called, calling |
| 324 // Add/RemoveTaskObserver() on this MessageLoop will crash. |
| 325 void DisallowTaskObservers() { allow_task_observers_ = false; } |
| 326 |
| 323 //---------------------------------------------------------------------------- | 327 //---------------------------------------------------------------------------- |
| 324 protected: | 328 protected: |
| 325 std::unique_ptr<MessagePump> pump_; | 329 std::unique_ptr<MessagePump> pump_; |
| 326 | 330 |
| 327 using MessagePumpFactoryCallback = Callback<std::unique_ptr<MessagePump>()>; | 331 using MessagePumpFactoryCallback = Callback<std::unique_ptr<MessagePump>()>; |
| 328 | 332 |
| 329 // Common protected constructor. Other constructors delegate the | 333 // Common protected constructor. Other constructors delegate the |
| 330 // initialization to this constructor. | 334 // initialization to this constructor. |
| 331 // A subclass can invoke this constructor to create a message_loop of a | 335 // A subclass can invoke this constructor to create a message_loop of a |
| 332 // specific type with a custom loop. The implementation does not call | 336 // specific type with a custom loop. The implementation does not call |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 455 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| 452 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 456 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
| 453 | 457 |
| 454 // Id of the thread this message loop is bound to. Initialized once when the | 458 // Id of the thread this message loop is bound to. Initialized once when the |
| 455 // MessageLoop is bound to its thread and constant forever after. | 459 // MessageLoop is bound to its thread and constant forever after. |
| 456 PlatformThreadId thread_id_; | 460 PlatformThreadId thread_id_; |
| 457 | 461 |
| 458 // Whether nesting is allowed. | 462 // Whether nesting is allowed. |
| 459 bool allow_nesting_ = true; | 463 bool allow_nesting_ = true; |
| 460 | 464 |
| 465 // Whether task observers are allowed. |
| 466 bool allow_task_observers_ = true; |
| 467 |
| 461 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 468 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
| 462 }; | 469 }; |
| 463 | 470 |
| 464 #if !defined(OS_NACL) | 471 #if !defined(OS_NACL) |
| 465 | 472 |
| 466 //----------------------------------------------------------------------------- | 473 //----------------------------------------------------------------------------- |
| 467 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 474 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
| 468 // MessageLoop instantiated with TYPE_UI. | 475 // MessageLoop instantiated with TYPE_UI. |
| 469 // | 476 // |
| 470 // This class is typically used like so: | 477 // This class is typically used like so: |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 605 |
| 599 // Do not add any member variables to MessageLoopForIO! This is important b/c | 606 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 600 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 607 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 601 // data that you need should be stored on the MessageLoop's pump_ instance. | 608 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 602 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 609 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 603 "MessageLoopForIO should not have extra member variables"); | 610 "MessageLoopForIO should not have extra member variables"); |
| 604 | 611 |
| 605 } // namespace base | 612 } // namespace base |
| 606 | 613 |
| 607 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 614 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |