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

Side by Side Diff: base/message_loop/message_loop.cc

Issue 61643006: Adds the ability for MessageLoop to take a MessagePump (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TYPE_CUSTOM and some scoped_ptr Created 7 years, 1 month 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
OLDNEW
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 #include "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 MessageLoop::MessageLoop(Type type) 138 MessageLoop::MessageLoop(Type type)
139 : type_(type), 139 : type_(type),
140 exception_restoration_(false), 140 exception_restoration_(false),
141 nestable_tasks_allowed_(true), 141 nestable_tasks_allowed_(true),
142 #if defined(OS_WIN) 142 #if defined(OS_WIN)
143 os_modal_loop_(false), 143 os_modal_loop_(false),
144 #endif // OS_WIN 144 #endif // OS_WIN
145 message_histogram_(NULL), 145 message_histogram_(NULL),
146 run_loop_(NULL) { 146 run_loop_(NULL) {
147 DCHECK(!current()) << "should only have one message loop per thread"; 147 Init();
148 lazy_tls_ptr.Pointer()->Set(this);
149
150 incoming_task_queue_ = new internal::IncomingTaskQueue(this);
151 message_loop_proxy_ =
152 new internal::MessageLoopProxyImpl(incoming_task_queue_);
153 thread_task_runner_handle_.reset(
154 new ThreadTaskRunnerHandle(message_loop_proxy_));
155 148
156 // TODO(rvargas): Get rid of the OS guards. 149 // TODO(rvargas): Get rid of the OS guards.
157 #if defined(OS_WIN) 150 #if defined(OS_WIN)
158 #define MESSAGE_PUMP_UI new MessagePumpForUI() 151 #define MESSAGE_PUMP_UI new MessagePumpForUI()
159 #define MESSAGE_PUMP_IO new MessagePumpForIO() 152 #define MESSAGE_PUMP_IO new MessagePumpForIO()
160 #elif defined(OS_IOS) 153 #elif defined(OS_IOS)
161 #define MESSAGE_PUMP_UI MessagePumpMac::Create() 154 #define MESSAGE_PUMP_UI MessagePumpMac::Create()
162 #define MESSAGE_PUMP_IO new MessagePumpIOSForIO() 155 #define MESSAGE_PUMP_IO new MessagePumpIOSForIO()
163 #elif defined(OS_MACOSX) 156 #elif defined(OS_MACOSX)
164 #define MESSAGE_PUMP_UI MessagePumpMac::Create() 157 #define MESSAGE_PUMP_UI MessagePumpMac::Create()
(...skipping 26 matching lines...) Expand all
191 #if defined(OS_ANDROID) 184 #if defined(OS_ANDROID)
192 } else if (type_ == TYPE_JAVA) { 185 } else if (type_ == TYPE_JAVA) {
193 pump_.reset(MESSAGE_PUMP_UI); 186 pump_.reset(MESSAGE_PUMP_UI);
194 #endif 187 #endif
195 } else { 188 } else {
196 DCHECK_EQ(TYPE_DEFAULT, type_); 189 DCHECK_EQ(TYPE_DEFAULT, type_);
197 pump_.reset(new MessagePumpDefault()); 190 pump_.reset(new MessagePumpDefault());
198 } 191 }
199 } 192 }
200 193
194 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
195 : pump_(pump.Pass()),
196 type_(TYPE_CUSTOM),
197 exception_restoration_(false),
198 nestable_tasks_allowed_(true),
199 #if defined(OS_WIN)
200 os_modal_loop_(false),
201 #endif // OS_WIN
202 message_histogram_(NULL),
203 run_loop_(NULL) {
204 Init();
205 }
206
201 MessageLoop::~MessageLoop() { 207 MessageLoop::~MessageLoop() {
202 DCHECK_EQ(this, current()); 208 DCHECK_EQ(this, current());
203 209
204 DCHECK(!run_loop_); 210 DCHECK(!run_loop_);
205 211
206 // Clean up any unprocessed tasks, but take care: deleting a task could 212 // Clean up any unprocessed tasks, but take care: deleting a task could
207 // result in the addition of more tasks (e.g., via DeleteSoon). We set a 213 // result in the addition of more tasks (e.g., via DeleteSoon). We set a
208 // limit on the number of times we will allow a deleted task to generate more 214 // limit on the number of times we will allow a deleted task to generate more
209 // tasks. Normally, we should only pass through this loop once or twice. If 215 // tasks. Normally, we should only pass through this loop once or twice. If
210 // we end up hitting the loop limit, then it is probably due to one task that 216 // we end up hitting the loop limit, then it is probably due to one task that
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return incoming_task_queue_->IsIdleForTesting(); 396 return incoming_task_queue_->IsIdleForTesting();
391 } 397 }
392 398
393 void MessageLoop::LockWaitUnLockForTesting(WaitableEvent* caller_wait, 399 void MessageLoop::LockWaitUnLockForTesting(WaitableEvent* caller_wait,
394 WaitableEvent* caller_signal) { 400 WaitableEvent* caller_signal) {
395 incoming_task_queue_->LockWaitUnLockForTesting(caller_wait, caller_signal); 401 incoming_task_queue_->LockWaitUnLockForTesting(caller_wait, caller_signal);
396 } 402 }
397 403
398 //------------------------------------------------------------------------------ 404 //------------------------------------------------------------------------------
399 405
406 void MessageLoop::Init() {
407 DCHECK(!current()) << "should only have one message loop per thread";
408 lazy_tls_ptr.Pointer()->Set(this);
409
410 incoming_task_queue_ = new internal::IncomingTaskQueue(this);
411 message_loop_proxy_ =
412 new internal::MessageLoopProxyImpl(incoming_task_queue_);
413 thread_task_runner_handle_.reset(
414 new ThreadTaskRunnerHandle(message_loop_proxy_));
415 }
416
400 // Runs the loop in two different SEH modes: 417 // Runs the loop in two different SEH modes:
401 // enable_SEH_restoration_ = false : any unhandled exception goes to the last 418 // enable_SEH_restoration_ = false : any unhandled exception goes to the last
402 // one that calls SetUnhandledExceptionFilter(). 419 // one that calls SetUnhandledExceptionFilter().
403 // enable_SEH_restoration_ = true : any unhandled exception goes to the filter 420 // enable_SEH_restoration_ = true : any unhandled exception goes to the filter
404 // that was existed before the loop was run. 421 // that was existed before the loop was run.
405 void MessageLoop::RunHandler() { 422 void MessageLoop::RunHandler() {
406 #if defined(OS_WIN) 423 #if defined(OS_WIN)
407 if (exception_restoration_) { 424 if (exception_restoration_) {
408 RunInternalInSEHFrame(); 425 RunInternalInSEHFrame();
409 return; 426 return;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 fd, 779 fd,
763 persistent, 780 persistent,
764 mode, 781 mode,
765 controller, 782 controller,
766 delegate); 783 delegate);
767 } 784 }
768 785
769 #endif 786 #endif
770 787
771 } // namespace base 788 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698