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

Side by Side Diff: base/message_loop.cc

Issue 495002: Changes to base/ from a combination of FreeBSD and OpenBSD patches. (Closed)
Patch Set: minor tweaks Created 11 years 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "base/message_loop.h" 5 #include "base/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_pump_default.h" 12 #include "base/message_pump_default.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/thread_local.h" 14 #include "base/thread_local.h"
15 15
16 #if defined(OS_MACOSX) 16 #if defined(OS_MACOSX)
17 #include "base/message_pump_mac.h" 17 #include "base/message_pump_mac.h"
18 #endif 18 #endif
19 #if defined(OS_POSIX) 19 #if defined(OS_POSIX)
20 #include "base/message_pump_libevent.h" 20 #include "base/message_pump_libevent.h"
21 #include "base/third_party/valgrind/valgrind.h" 21 #include "base/third_party/valgrind/valgrind.h"
22 #endif 22 #endif
23 #if defined(OS_LINUX) 23 #if defined(OS_POSIX) && !defined(OS_MACOSX)
24 #include "base/message_pump_glib.h" 24 #include "base/message_pump_glib.h"
25 #endif 25 #endif
26 26
27 using base::Time; 27 using base::Time;
28 using base::TimeDelta; 28 using base::TimeDelta;
29 29
30 // A lazily created thread local storage for quick access to a thread's message 30 // A lazily created thread local storage for quick access to a thread's message
31 // loop, if one exists. This should be safe and free of static constructors. 31 // loop, if one exists. This should be safe and free of static constructors.
32 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( 32 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr(
33 base::LINKER_INITIALIZED); 33 base::LINKER_INITIALIZED);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } else if (type_ == TYPE_IO) { 92 } else if (type_ == TYPE_IO) {
93 pump_ = new base::MessagePumpForIO(); 93 pump_ = new base::MessagePumpForIO();
94 } else { 94 } else {
95 DCHECK(type_ == TYPE_UI); 95 DCHECK(type_ == TYPE_UI);
96 pump_ = new base::MessagePumpForUI(); 96 pump_ = new base::MessagePumpForUI();
97 } 97 }
98 #elif defined(OS_POSIX) 98 #elif defined(OS_POSIX)
99 if (type_ == TYPE_UI) { 99 if (type_ == TYPE_UI) {
100 #if defined(OS_MACOSX) 100 #if defined(OS_MACOSX)
101 pump_ = base::MessagePumpMac::Create(); 101 pump_ = base::MessagePumpMac::Create();
102 #elif defined(OS_LINUX) 102 #else
103 pump_ = new base::MessagePumpForUI(); 103 pump_ = new base::MessagePumpForUI();
104 #endif // OS_LINUX 104 #endif
105 } else if (type_ == TYPE_IO) { 105 } else if (type_ == TYPE_IO) {
106 pump_ = new base::MessagePumpLibevent(); 106 pump_ = new base::MessagePumpLibevent();
107 } else { 107 } else {
108 pump_ = new base::MessagePumpDefault(); 108 pump_ = new base::MessagePumpDefault();
109 } 109 }
110 #endif // OS_POSIX 110 #endif // OS_POSIX
111 } 111 }
112 112
113 MessageLoop::~MessageLoop() { 113 MessageLoop::~MessageLoop() {
114 DCHECK(this == current()); 114 DCHECK(this == current());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return; 187 return;
188 } 188 }
189 #endif 189 #endif
190 //------------------------------------------------------------------------------ 190 //------------------------------------------------------------------------------
191 191
192 void MessageLoop::RunInternal() { 192 void MessageLoop::RunInternal() {
193 DCHECK(this == current()); 193 DCHECK(this == current());
194 194
195 StartHistogrammer(); 195 StartHistogrammer();
196 196
197 #if defined(OS_WIN) || defined(OS_LINUX) 197 #if !defined(OS_MACOSX)
198 if (state_->dispatcher && type() == TYPE_UI) { 198 if (state_->dispatcher && type() == TYPE_UI) {
199 static_cast<base::MessagePumpForUI*>(pump_.get())-> 199 static_cast<base::MessagePumpForUI*>(pump_.get())->
200 RunWithDispatcher(this, state_->dispatcher); 200 RunWithDispatcher(this, state_->dispatcher);
201 return; 201 return;
202 } 202 }
203 #endif 203 #endif
204 204
205 pump_->Run(this); 205 pump_->Run(this);
206 } 206 }
207 207
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 previous_state_ = loop_->state_; 480 previous_state_ = loop_->state_;
481 if (previous_state_) { 481 if (previous_state_) {
482 run_depth = previous_state_->run_depth + 1; 482 run_depth = previous_state_->run_depth + 1;
483 } else { 483 } else {
484 run_depth = 1; 484 run_depth = 1;
485 } 485 }
486 loop_->state_ = this; 486 loop_->state_ = this;
487 487
488 // Initialize the other fields: 488 // Initialize the other fields:
489 quit_received = false; 489 quit_received = false;
490 #if defined(OS_WIN) || defined(OS_LINUX) 490 #if !defined(OS_MACOSX)
491 dispatcher = NULL; 491 dispatcher = NULL;
492 #endif 492 #endif
493 } 493 }
494 494
495 MessageLoop::AutoRunState::~AutoRunState() { 495 MessageLoop::AutoRunState::~AutoRunState() {
496 loop_->state_ = previous_state_; 496 loop_->state_ = previous_state_;
497 } 497 }
498 498
499 //------------------------------------------------------------------------------ 499 //------------------------------------------------------------------------------
500 // MessageLoop::PendingTask 500 // MessageLoop::PendingTask
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 584 }
585 void MessageLoopForUI::DidProcessMessage(const MSG& message) { 585 void MessageLoopForUI::DidProcessMessage(const MSG& message) {
586 pump_win()->DidProcessMessage(message); 586 pump_win()->DidProcessMessage(message);
587 } 587 }
588 void MessageLoopForUI::PumpOutPendingPaintMessages() { 588 void MessageLoopForUI::PumpOutPendingPaintMessages() {
589 pump_ui()->PumpOutPendingPaintMessages(); 589 pump_ui()->PumpOutPendingPaintMessages();
590 } 590 }
591 591
592 #endif // defined(OS_WIN) 592 #endif // defined(OS_WIN)
593 593
594 #if defined(OS_LINUX) || defined(OS_WIN) 594 #if !defined(OS_MACOSX)
595 void MessageLoopForUI::AddObserver(Observer* observer) { 595 void MessageLoopForUI::AddObserver(Observer* observer) {
596 pump_ui()->AddObserver(observer); 596 pump_ui()->AddObserver(observer);
597 } 597 }
598 598
599 void MessageLoopForUI::RemoveObserver(Observer* observer) { 599 void MessageLoopForUI::RemoveObserver(Observer* observer) {
600 pump_ui()->RemoveObserver(observer); 600 pump_ui()->RemoveObserver(observer);
601 } 601 }
602 602
603 void MessageLoopForUI::Run(Dispatcher* dispatcher) { 603 void MessageLoopForUI::Run(Dispatcher* dispatcher) {
604 AutoRunState save_state(this); 604 AutoRunState save_state(this);
605 state_->dispatcher = dispatcher; 605 state_->dispatcher = dispatcher;
606 RunHandler(); 606 RunHandler();
607 } 607 }
608 #endif // defined(OS_LINUX) || defined(OS_WIN) 608 #endif // !defined(OS_MACOSX)
609 609
610 //------------------------------------------------------------------------------ 610 //------------------------------------------------------------------------------
611 // MessageLoopForIO 611 // MessageLoopForIO
612 612
613 #if defined(OS_WIN) 613 #if defined(OS_WIN)
614 614
615 void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) { 615 void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) {
616 pump_io()->RegisterIOHandler(file, handler); 616 pump_io()->RegisterIOHandler(file, handler);
617 } 617 }
618 618
(...skipping 10 matching lines...) Expand all
629 Watcher *delegate) { 629 Watcher *delegate) {
630 return pump_libevent()->WatchFileDescriptor( 630 return pump_libevent()->WatchFileDescriptor(
631 fd, 631 fd,
632 persistent, 632 persistent,
633 static_cast<base::MessagePumpLibevent::Mode>(mode), 633 static_cast<base::MessagePumpLibevent::Mode>(mode),
634 controller, 634 controller,
635 delegate); 635 delegate);
636 } 636 }
637 637
638 #endif 638 #endif
OLDNEW
« base/message_loop.h ('K') | « base/message_loop.h ('k') | base/message_loop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698