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

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: Make message loop name optional. 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(Type type = TYPE_DEFAULT,
111 const char* thread_name = NULL);
111 virtual ~MessageLoop(); 112 virtual ~MessageLoop();
112 113
113 // Returns the MessageLoop object for the current thread, or null if none. 114 // Returns the MessageLoop object for the current thread, or null if none.
114 static MessageLoop* current(); 115 static MessageLoop* current();
115 116
116 static void EnableHistogrammer(bool enable_histogrammer); 117 static void EnableHistogrammer(bool enable_histogrammer);
117 118
118 // A DestructionObserver is notified when the current MessageLoop is being 119 // A DestructionObserver is notified when the current MessageLoop is being
119 // destroyed. These obsevers are notified prior to MessageLoop::current() 120 // destroyed. These obsevers are notified prior to MessageLoop::current()
120 // being changed to return NULL. This gives interested parties the chance to 121 // 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 { 249 class QuitTask : public Task {
249 public: 250 public:
250 virtual void Run() { 251 virtual void Run() {
251 MessageLoop::current()->Quit(); 252 MessageLoop::current()->Quit();
252 } 253 }
253 }; 254 };
254 255
255 // Returns the type passed to the constructor. 256 // Returns the type passed to the constructor.
256 Type type() const { return type_; } 257 Type type() const { return type_; }
257 258
258 // Optional call to connect the thread name with this loop. 259 // 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_; } 260 const std::string& thread_name() const { return thread_name_; }
264 261
265 // Enables or disables the recursive task processing. This happens in the case 262 // Enables or disables the recursive task processing. This happens in the case
266 // of recursive message loops. Some unwanted message loop may occurs when 263 // of recursive message loops. Some unwanted message loop may occurs when
267 // using common controls or printer functions. By default, recursive task 264 // using common controls or printer functions. By default, recursive task
268 // processing is disabled. 265 // processing is disabled.
269 // 266 //
270 // The specific case where tasks get queued is: 267 // The specific case where tasks get queued is:
271 // - The thread is running a message loop. 268 // - The thread is running a message loop.
272 // - It receives a task #1 and execute it. 269 // - It receives a task #1 and execute it.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 559
563 //----------------------------------------------------------------------------- 560 //-----------------------------------------------------------------------------
564 // MessageLoopForUI extends MessageLoop with methods that are particular to a 561 // MessageLoopForUI extends MessageLoop with methods that are particular to a
565 // MessageLoop instantiated with TYPE_UI. 562 // MessageLoop instantiated with TYPE_UI.
566 // 563 //
567 // This class is typically used like so: 564 // This class is typically used like so:
568 // MessageLoopForUI::current()->...call some method... 565 // MessageLoopForUI::current()->...call some method...
569 // 566 //
570 class BASE_API MessageLoopForUI : public MessageLoop { 567 class BASE_API MessageLoopForUI : public MessageLoop {
571 public: 568 public:
572 MessageLoopForUI() : MessageLoop(TYPE_UI) { 569 MessageLoopForUI(const char* thread_name)
570 : MessageLoop(thread_name, TYPE_UI) {
573 } 571 }
574 572
575 // Returns the MessageLoopForUI of the current thread. 573 // Returns the MessageLoopForUI of the current thread.
576 static MessageLoopForUI* current() { 574 static MessageLoopForUI* current() {
577 MessageLoop* loop = MessageLoop::current(); 575 MessageLoop* loop = MessageLoop::current();
578 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); 576 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
579 return static_cast<MessageLoopForUI*>(loop); 577 return static_cast<MessageLoopForUI*>(loop);
580 } 578 }
581 579
582 #if defined(OS_WIN) 580 #if defined(OS_WIN)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 typedef base::MessagePumpLibevent::IOObserver IOObserver; 622 typedef base::MessagePumpLibevent::IOObserver IOObserver;
625 623
626 enum Mode { 624 enum Mode {
627 WATCH_READ = base::MessagePumpLibevent::WATCH_READ, 625 WATCH_READ = base::MessagePumpLibevent::WATCH_READ,
628 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE, 626 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE,
629 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE 627 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE
630 }; 628 };
631 629
632 #endif 630 #endif
633 631
634 MessageLoopForIO() : MessageLoop(TYPE_IO) { 632 MessageLoopForIO(const char* thread_name)
633 : MessageLoop(thread_name, TYPE_IO) {
635 } 634 }
636 635
637 // Returns the MessageLoopForIO of the current thread. 636 // Returns the MessageLoopForIO of the current thread.
638 static MessageLoopForIO* current() { 637 static MessageLoopForIO* current() {
639 MessageLoop* loop = MessageLoop::current(); 638 MessageLoop* loop = MessageLoop::current();
640 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); 639 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type());
641 return static_cast<MessageLoopForIO*>(loop); 640 return static_cast<MessageLoopForIO*>(loop);
642 } 641 }
643 642
644 void AddIOObserver(IOObserver* io_observer) { 643 void AddIOObserver(IOObserver* io_observer) {
(...skipping 30 matching lines...) Expand all
675 #endif // defined(OS_POSIX) 674 #endif // defined(OS_POSIX)
676 }; 675 };
677 676
678 // Do not add any member variables to MessageLoopForIO! This is important b/c 677 // Do not add any member variables to MessageLoopForIO! This is important b/c
679 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 678 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
680 // data that you need should be stored on the MessageLoop's pump_ instance. 679 // data that you need should be stored on the MessageLoop's pump_ instance.
681 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 680 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
682 MessageLoopForIO_should_not_have_extra_member_variables); 681 MessageLoopForIO_should_not_have_extra_member_variables);
683 682
684 #endif // BASE_MESSAGE_LOOP_H_ 683 #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