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> | |
11 | 10 |
12 #include "base/base_export.h" | 11 #include "base/base_export.h" |
13 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
14 #include "base/debug/task_annotator.h" | 13 #include "base/debug/task_annotator.h" |
15 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
16 #include "base/location.h" | 15 #include "base/location.h" |
17 #include "base/macros.h" | 16 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
19 #include "base/message_loop/incoming_task_queue.h" | 18 #include "base/message_loop/incoming_task_queue.h" |
20 #include "base/message_loop/message_loop_task_runner.h" | 19 #include "base/message_loop/message_loop_task_runner.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 pump_->SetTimerSlack(timer_slack); | 286 pump_->SetTimerSlack(timer_slack); |
288 } | 287 } |
289 | 288 |
290 // Returns true if this loop is |type|. This allows subclasses (especially | 289 // Returns true if this loop is |type|. This allows subclasses (especially |
291 // those in tests) to specialize how they are identified. | 290 // those in tests) to specialize how they are identified. |
292 virtual bool IsType(Type type) const; | 291 virtual bool IsType(Type type) const; |
293 | 292 |
294 // Returns the type passed to the constructor. | 293 // Returns the type passed to the constructor. |
295 Type type() const { return type_; } | 294 Type type() const { return type_; } |
296 | 295 |
297 // Optional call to connect the thread name with this loop. | |
298 void set_thread_name(const std::string& thread_name) { | |
299 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; | |
300 thread_name_ = thread_name; | |
301 } | |
302 const std::string& thread_name() const { return thread_name_; } | |
303 | |
304 // Gets the TaskRunner associated with this message loop. | 296 // Gets the TaskRunner associated with this message loop. |
305 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { | 297 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { |
306 return task_runner_; | 298 return task_runner_; |
307 } | 299 } |
308 | 300 |
309 // Sets a new TaskRunner for this message loop. The message loop must already | 301 // Sets a new TaskRunner for this message loop. The message loop must already |
310 // have been bound to a thread prior to this call, and the task runner must | 302 // have been bound to a thread prior to this call, and the task runner must |
311 // belong to that thread. Note that changing the task runner will also affect | 303 // belong to that thread. Note that changing the task runner will also affect |
312 // the ThreadTaskRunnerHandle for the target thread. Must be called on the | 304 // the ThreadTaskRunnerHandle for the target thread. Must be called on the |
313 // thread to which the message loop is bound. | 305 // thread to which the message loop is bound. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 #if defined(OS_WIN) | 521 #if defined(OS_WIN) |
530 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc. | 522 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc. |
531 // which enter a modal message loop. | 523 // which enter a modal message loop. |
532 bool os_modal_loop_; | 524 bool os_modal_loop_; |
533 #endif | 525 #endif |
534 | 526 |
535 // pump_factory_.Run() is called to create a message pump for this loop | 527 // pump_factory_.Run() is called to create a message pump for this loop |
536 // if type_ is TYPE_CUSTOM and pump_ is null. | 528 // if type_ is TYPE_CUSTOM and pump_ is null. |
537 MessagePumpFactoryCallback pump_factory_; | 529 MessagePumpFactoryCallback pump_factory_; |
538 | 530 |
539 std::string thread_name_; | |
540 // A profiling histogram showing the counts of various messages and events. | 531 // A profiling histogram showing the counts of various messages and events. |
541 HistogramBase* message_histogram_; | 532 HistogramBase* message_histogram_; |
542 | 533 |
543 RunLoop* run_loop_; | 534 RunLoop* run_loop_; |
544 | 535 |
545 ObserverList<TaskObserver> task_observers_; | 536 ObserverList<TaskObserver> task_observers_; |
546 | 537 |
547 debug::TaskAnnotator task_annotator_; | 538 debug::TaskAnnotator task_annotator_; |
548 | 539 |
549 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; | 540 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 697 |
707 // Do not add any member variables to MessageLoopForIO! This is important b/c | 698 // Do not add any member variables to MessageLoopForIO! This is important b/c |
708 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 699 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
709 // data that you need should be stored on the MessageLoop's pump_ instance. | 700 // data that you need should be stored on the MessageLoop's pump_ instance. |
710 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 701 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
711 "MessageLoopForIO should not have extra member variables"); | 702 "MessageLoopForIO should not have extra member variables"); |
712 | 703 |
713 } // namespace base | 704 } // namespace base |
714 | 705 |
715 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 706 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |