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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 // A subclass can invoke this constructor to create a message_loop of a | 339 // A subclass can invoke this constructor to create a message_loop of a |
340 // specific type with a custom loop. The implementation does not call | 340 // specific type with a custom loop. The implementation does not call |
341 // BindToCurrentThread. If this constructor is invoked directly by a subclass, | 341 // BindToCurrentThread. If this constructor is invoked directly by a subclass, |
342 // then the subclass must subsequently bind the message loop. | 342 // then the subclass must subsequently bind the message loop. |
343 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); | 343 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); |
344 | 344 |
345 // Configure various members and bind this message loop to the current thread. | 345 // Configure various members and bind this message loop to the current thread. |
346 void BindToCurrentThread(); | 346 void BindToCurrentThread(); |
347 | 347 |
348 private: | 348 private: |
349 friend class internal::IncomingTaskQueue; | |
349 friend class RunLoop; | 350 friend class RunLoop; |
350 friend class internal::IncomingTaskQueue; | |
351 friend class ScheduleWorkTest; | 351 friend class ScheduleWorkTest; |
352 friend class Thread; | 352 friend class Thread; |
353 friend struct PendingTask; | |
353 FRIEND_TEST_ALL_PREFIXES(MessageLoopTest, DeleteUnboundLoop); | 354 FRIEND_TEST_ALL_PREFIXES(MessageLoopTest, DeleteUnboundLoop); |
354 | 355 |
355 // Creates a MessageLoop without binding to a thread. | 356 // Creates a MessageLoop without binding to a thread. |
356 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given | 357 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given |
357 // to create a message pump for this message loop. Otherwise a default | 358 // to create a message pump for this message loop. Otherwise a default |
358 // message pump for the |type| is created. | 359 // message pump for the |type| is created. |
359 // | 360 // |
360 // It is valid to call this to create a new message loop on one thread, | 361 // It is valid to call this to create a new message loop on one thread, |
361 // and then pass it to the thread where the message loop actually runs. | 362 // and then pass it to the thread where the message loop actually runs. |
362 // The message loop's BindToCurrentThread() method must be called on the | 363 // The message loop's BindToCurrentThread() method must be called on the |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 // pump_factory_.Run() is called to create a message pump for this loop | 444 // pump_factory_.Run() is called to create a message pump for this loop |
444 // if type_ is TYPE_CUSTOM and pump_ is null. | 445 // if type_ is TYPE_CUSTOM and pump_ is null. |
445 MessagePumpFactoryCallback pump_factory_; | 446 MessagePumpFactoryCallback pump_factory_; |
446 | 447 |
447 RunLoop* run_loop_; | 448 RunLoop* run_loop_; |
448 | 449 |
449 ObserverList<TaskObserver> task_observers_; | 450 ObserverList<TaskObserver> task_observers_; |
450 | 451 |
451 debug::TaskAnnotator task_annotator_; | 452 debug::TaskAnnotator task_annotator_; |
452 | 453 |
454 // Used to allow creating a breadcrumb of program counters in PostTask. | |
455 // Be very careful when using this variable. | |
danakj
2017/02/07 23:16:46
careful in what way, what are the risks?
awong
2017/02/08 01:55:50
rewrote comment.
| |
456 const PendingTask* current_pending_task_; | |
457 | |
453 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; | 458 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
454 | 459 |
455 // A task runner which we haven't bound to a thread yet. | 460 // A task runner which we haven't bound to a thread yet. |
456 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 461 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
457 | 462 |
458 // The task runner associated with this message loop. | 463 // The task runner associated with this message loop. |
459 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 464 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
460 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 465 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
461 | 466 |
462 // Id of the thread this message loop is bound to. Initialized once when the | 467 // Id of the thread this message loop is bound to. Initialized once when the |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 | 614 |
610 // Do not add any member variables to MessageLoopForIO! This is important b/c | 615 // Do not add any member variables to MessageLoopForIO! This is important b/c |
611 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 616 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
612 // data that you need should be stored on the MessageLoop's pump_ instance. | 617 // data that you need should be stored on the MessageLoop's pump_ instance. |
613 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 618 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
614 "MessageLoopForIO should not have extra member variables"); | 619 "MessageLoopForIO should not have extra member variables"); |
615 | 620 |
616 } // namespace base | 621 } // namespace base |
617 | 622 |
618 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 623 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |