Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: base/message_loop.h

Issue 7529003: Make base::MessageLoops have names at construction time (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add name argument to MessageLoop Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_H_ 5 #ifndef BASE_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // MessageLoopForIO. 100 // MessageLoopForIO.
101 // 101 //
102 enum Type { 102 enum Type {
103 TYPE_DEFAULT, 103 TYPE_DEFAULT,
104 TYPE_UI, 104 TYPE_UI,
105 TYPE_IO 105 TYPE_IO
106 }; 106 };
107 107
108 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it 108 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it
109 // is typical to make use of the current thread's MessageLoop instance. 109 // is typical to make use of the current thread's MessageLoop instance.
110 explicit MessageLoop(Type type = TYPE_DEFAULT); 110 explicit MessageLoop(const char* thread_name, Type type = TYPE_DEFAULT);
nduca 2011/08/02 01:26:39 I'm fine making the thread_name optional, if you t
111 virtual ~MessageLoop(); 111 virtual ~MessageLoop();
112 112
113 // Returns the MessageLoop object for the current thread, or null if none. 113 // Returns the MessageLoop object for the current thread, or null if none.
114 static MessageLoop* current(); 114 static MessageLoop* current();
115 115
116 static void EnableHistogrammer(bool enable_histogrammer); 116 static void EnableHistogrammer(bool enable_histogrammer);
117 117
118 // A DestructionObserver is notified when the current MessageLoop is being 118 // A DestructionObserver is notified when the current MessageLoop is being
119 // destroyed. These obsevers are notified prior to MessageLoop::current() 119 // destroyed. These obsevers are notified prior to MessageLoop::current()
120 // being changed to return NULL. This gives interested parties the chance to 120 // being changed to return NULL. This gives interested parties the chance to
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 class QuitTask : public Task { 248 class QuitTask : public Task {
249 public: 249 public:
250 virtual void Run() { 250 virtual void Run() {
251 MessageLoop::current()->Quit(); 251 MessageLoop::current()->Quit();
252 } 252 }
253 }; 253 };
254 254
255 // Returns the type passed to the constructor. 255 // Returns the type passed to the constructor.
256 Type type() const { return type_; } 256 Type type() const { return type_; }
257 257
258 // Optional call to connect the thread name with this loop. 258 // Returns the name associated with this message loop's thread.
259 void set_thread_name(const std::string& thread_name) {
260 DCHECK(thread_name_.empty()) << "Should not rename this thread!";
261 thread_name_ = thread_name;
262 }
263 const std::string& thread_name() const { return thread_name_; } 259 const std::string& thread_name() const { return thread_name_; }
264 260
265 // Enables or disables the recursive task processing. This happens in the case 261 // Enables or disables the recursive task processing. This happens in the case
266 // of recursive message loops. Some unwanted message loop may occurs when 262 // of recursive message loops. Some unwanted message loop may occurs when
267 // using common controls or printer functions. By default, recursive task 263 // using common controls or printer functions. By default, recursive task
268 // processing is disabled. 264 // processing is disabled.
269 // 265 //
270 // The specific case where tasks get queued is: 266 // The specific case where tasks get queued is:
271 // - The thread is running a message loop. 267 // - The thread is running a message loop.
272 // - It receives a task #1 and execute it. 268 // - It receives a task #1 and execute it.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 558
563 //----------------------------------------------------------------------------- 559 //-----------------------------------------------------------------------------
564 // MessageLoopForUI extends MessageLoop with methods that are particular to a 560 // MessageLoopForUI extends MessageLoop with methods that are particular to a
565 // MessageLoop instantiated with TYPE_UI. 561 // MessageLoop instantiated with TYPE_UI.
566 // 562 //
567 // This class is typically used like so: 563 // This class is typically used like so:
568 // MessageLoopForUI::current()->...call some method... 564 // MessageLoopForUI::current()->...call some method...
569 // 565 //
570 class BASE_API MessageLoopForUI : public MessageLoop { 566 class BASE_API MessageLoopForUI : public MessageLoop {
571 public: 567 public:
572 MessageLoopForUI() : MessageLoop(TYPE_UI) { 568 MessageLoopForUI(const char* thread_name)
569 : MessageLoop(thread_name, TYPE_UI) {
573 } 570 }
574 571
575 // Returns the MessageLoopForUI of the current thread. 572 // Returns the MessageLoopForUI of the current thread.
576 static MessageLoopForUI* current() { 573 static MessageLoopForUI* current() {
577 MessageLoop* loop = MessageLoop::current(); 574 MessageLoop* loop = MessageLoop::current();
578 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); 575 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
579 return static_cast<MessageLoopForUI*>(loop); 576 return static_cast<MessageLoopForUI*>(loop);
580 } 577 }
581 578
582 #if defined(OS_WIN) 579 #if defined(OS_WIN)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 typedef base::MessagePumpLibevent::IOObserver IOObserver; 621 typedef base::MessagePumpLibevent::IOObserver IOObserver;
625 622
626 enum Mode { 623 enum Mode {
627 WATCH_READ = base::MessagePumpLibevent::WATCH_READ, 624 WATCH_READ = base::MessagePumpLibevent::WATCH_READ,
628 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE, 625 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE,
629 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE 626 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE
630 }; 627 };
631 628
632 #endif 629 #endif
633 630
634 MessageLoopForIO() : MessageLoop(TYPE_IO) { 631 MessageLoopForIO(const char* thread_name)
632 : MessageLoop(thread_name, TYPE_IO) {
635 } 633 }
636 634
637 // Returns the MessageLoopForIO of the current thread. 635 // Returns the MessageLoopForIO of the current thread.
638 static MessageLoopForIO* current() { 636 static MessageLoopForIO* current() {
639 MessageLoop* loop = MessageLoop::current(); 637 MessageLoop* loop = MessageLoop::current();
640 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); 638 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type());
641 return static_cast<MessageLoopForIO*>(loop); 639 return static_cast<MessageLoopForIO*>(loop);
642 } 640 }
643 641
644 void AddIOObserver(IOObserver* io_observer) { 642 void AddIOObserver(IOObserver* io_observer) {
(...skipping 30 matching lines...) Expand all
675 #endif // defined(OS_POSIX) 673 #endif // defined(OS_POSIX)
676 }; 674 };
677 675
678 // Do not add any member variables to MessageLoopForIO! This is important b/c 676 // Do not add any member variables to MessageLoopForIO! This is important b/c
679 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 677 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
680 // data that you need should be stored on the MessageLoop's pump_ instance. 678 // data that you need should be stored on the MessageLoop's pump_ instance.
681 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 679 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
682 MessageLoopForIO_should_not_have_extra_member_variables); 680 MessageLoopForIO_should_not_have_extra_member_variables);
683 681
684 #endif // BASE_MESSAGE_LOOP_H_ 682 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698