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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 301 } |
302 | 302 |
303 // Sets a new TaskRunner for this message loop. The message loop must already | 303 // Sets a new TaskRunner for this message loop. The message loop must already |
304 // have been bound to a thread prior to this call, and the task runner must | 304 // have been bound to a thread prior to this call, and the task runner must |
305 // belong to that thread. Note that changing the task runner will also affect | 305 // belong to that thread. Note that changing the task runner will also affect |
306 // the ThreadTaskRunnerHandle for the target thread. Must be called on the | 306 // the ThreadTaskRunnerHandle for the target thread. Must be called on the |
307 // thread to which the message loop is bound. | 307 // thread to which the message loop is bound. |
308 void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner); | 308 void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner); |
309 | 309 |
310 // Enables or disables the recursive task processing. This happens in the case | 310 // Enables or disables the recursive task processing. This happens in the case |
311 // of recursive message loops. Some unwanted message loop may occurs when | 311 // of recursive message loops. Some unwanted message loops may occur when |
312 // using common controls or printer functions. By default, recursive task | 312 // using common controls or printer functions. By default, recursive task |
313 // processing is disabled. | 313 // processing is disabled. |
314 // | 314 // |
315 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods | 315 // Please use |ScopedNestableTaskAllower| instead of calling these methods |
316 // directly. In general nestable message loops are to be avoided. They are | 316 // directly. In general, nestable message loops are to be avoided. They are |
317 // dangerous and difficult to get right, so please use with extreme caution. | 317 // dangerous and difficult to get right, so please use with extreme caution. |
318 // | 318 // |
319 // The specific case where tasks get queued is: | 319 // The specific case where tasks get queued is: |
320 // - The thread is running a message loop. | 320 // - The thread is running a message loop. |
321 // - It receives a task #1 and execute it. | 321 // - It receives a task #1 and executes it. |
322 // - The task #1 implicitly start a message loop, like a MessageBox in the | 322 // - The task #1 implicitly starts a message loop, like a MessageBox in the |
323 // unit test. This can also be StartDoc or GetSaveFileName. | 323 // unit test. This can also be StartDoc or GetSaveFileName. |
324 // - The thread receives a task #2 before or while in this second message | 324 // - The thread receives a task #2 before or while in this second message |
325 // loop. | 325 // loop. |
326 // - With NestableTasksAllowed set to true, the task #2 will run right away. | 326 // - With NestableTasksAllowed set to true, the task #2 will run right away. |
327 // Otherwise, it will get executed right after task #1 completes at "thread | 327 // Otherwise, it will get executed right after task #1 completes at "thread |
328 // message loop level". | 328 // message loop level". |
329 void SetNestableTasksAllowed(bool allowed); | 329 void SetNestableTasksAllowed(bool allowed); |
330 bool NestableTasksAllowed() const; | 330 bool NestableTasksAllowed() const; |
331 | 331 |
332 // Enables nestable tasks on |loop| while in scope. | 332 // Enables nestable tasks on |loop| while in scope. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 413 |
414 // Creates a MessageLoop without binding to a thread. | 414 // Creates a MessageLoop without binding to a thread. |
415 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given | 415 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given |
416 // to create a message pump for this message loop. Otherwise a default | 416 // to create a message pump for this message loop. Otherwise a default |
417 // message pump for the |type| is created. | 417 // message pump for the |type| is created. |
418 // | 418 // |
419 // It is valid to call this to create a new message loop on one thread, | 419 // It is valid to call this to create a new message loop on one thread, |
420 // and then pass it to the thread where the message loop actually runs. | 420 // and then pass it to the thread where the message loop actually runs. |
421 // The message loop's BindToCurrentThread() method must be called on the | 421 // The message loop's BindToCurrentThread() method must be called on the |
422 // thread the message loop runs on, before calling Run(). | 422 // thread the message loop runs on, before calling Run(). |
423 // Before BindToCurrentThread() is called only Post*Task() functions can | 423 // Before BindToCurrentThread() is called, only Post*Task() functions can |
424 // be called on the message loop. | 424 // be called on the message loop. |
425 static scoped_ptr<MessageLoop> CreateUnbound( | 425 static scoped_ptr<MessageLoop> CreateUnbound( |
426 Type type, | 426 Type type, |
427 MessagePumpFactoryCallback pump_factory); | 427 MessagePumpFactoryCallback pump_factory); |
428 | 428 |
429 // Common private constructor. Other constructors delegate the initialization | 429 // Common private constructor. Other constructors delegate the initialization |
430 // to this constructor. | 430 // to this constructor. |
431 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); | 431 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); |
432 | 432 |
433 // Configure various members and bind this message loop to the current thread. | 433 // Configure various members and bind this message loop to the current thread. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // once we're out of nested message loops. | 504 // once we're out of nested message loops. |
505 TaskQueue deferred_non_nestable_work_queue_; | 505 TaskQueue deferred_non_nestable_work_queue_; |
506 | 506 |
507 ObserverList<DestructionObserver> destruction_observers_; | 507 ObserverList<DestructionObserver> destruction_observers_; |
508 | 508 |
509 // A recursion block that prevents accidentally running additional tasks when | 509 // A recursion block that prevents accidentally running additional tasks when |
510 // insider a (accidentally induced?) nested message pump. | 510 // insider a (accidentally induced?) nested message pump. |
511 bool nestable_tasks_allowed_; | 511 bool nestable_tasks_allowed_; |
512 | 512 |
513 #if defined(OS_WIN) | 513 #if defined(OS_WIN) |
514 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc | 514 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc. |
515 // which enter a modal message loop. | 515 // which enter a modal message loop. |
516 bool os_modal_loop_; | 516 bool os_modal_loop_; |
517 #endif | 517 #endif |
518 | 518 |
519 // pump_factory_.Run() is called to create a message pump for this loop | 519 // pump_factory_.Run() is called to create a message pump for this loop |
520 // if type_ is TYPE_CUSTOM and pump_ is null. | 520 // if type_ is TYPE_CUSTOM and pump_ is null. |
521 MessagePumpFactoryCallback pump_factory_; | 521 MessagePumpFactoryCallback pump_factory_; |
522 | 522 |
523 std::string thread_name_; | 523 std::string thread_name_; |
524 // A profiling histogram showing the counts of various messages and events. | 524 // A profiling histogram showing the counts of various messages and events. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 | 687 |
688 // Do not add any member variables to MessageLoopForIO! This is important b/c | 688 // Do not add any member variables to MessageLoopForIO! This is important b/c |
689 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 689 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
690 // data that you need should be stored on the MessageLoop's pump_ instance. | 690 // data that you need should be stored on the MessageLoop's pump_ instance. |
691 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 691 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
692 MessageLoopForIO_should_not_have_extra_member_variables); | 692 MessageLoopForIO_should_not_have_extra_member_variables); |
693 | 693 |
694 } // namespace base | 694 } // namespace base |
695 | 695 |
696 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 696 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |