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

Side by Side Diff: base/message_loop.cc

Issue 10380016: Add base::ThreadTaskRunner class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop_proxy_impl.h" 16 #include "base/message_loop_proxy_impl.h"
17 #include "base/message_pump_default.h" 17 #include "base/message_pump_default.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
20 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/thread_local.h" 21 #include "base/threading/thread_local.h"
21 #include "base/time.h" 22 #include "base/time.h"
22 #include "base/tracked_objects.h" 23 #include "base/tracked_objects.h"
23 24
24 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
25 #include "base/message_pump_mac.h" 26 #include "base/message_pump_mac.h"
26 #endif 27 #endif
27 #if defined(OS_POSIX) 28 #if defined(OS_POSIX)
28 #include "base/message_pump_libevent.h" 29 #include "base/message_pump_libevent.h"
29 #endif 30 #endif
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 message_histogram_(NULL), 133 message_histogram_(NULL),
133 state_(NULL), 134 state_(NULL),
134 #ifdef OS_WIN 135 #ifdef OS_WIN
135 os_modal_loop_(false), 136 os_modal_loop_(false),
136 #endif // OS_WIN 137 #endif // OS_WIN
137 next_sequence_num_(0) { 138 next_sequence_num_(0) {
138 DCHECK(!current()) << "should only have one message loop per thread"; 139 DCHECK(!current()) << "should only have one message loop per thread";
139 lazy_tls_ptr.Pointer()->Set(this); 140 lazy_tls_ptr.Pointer()->Set(this);
140 141
141 message_loop_proxy_ = new base::MessageLoopProxyImpl(); 142 message_loop_proxy_ = new base::MessageLoopProxyImpl();
143 thread_task_runner_handle_.reset(
144 new base::ThreadTaskRunnerHandle(message_loop_proxy_));
142 145
143 // TODO(rvargas): Get rid of the OS guards. 146 // TODO(rvargas): Get rid of the OS guards.
144 #if defined(OS_WIN) 147 #if defined(OS_WIN)
145 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() 148 #define MESSAGE_PUMP_UI new base::MessagePumpForUI()
146 #define MESSAGE_PUMP_IO new base::MessagePumpForIO() 149 #define MESSAGE_PUMP_IO new base::MessagePumpForIO()
147 #elif defined(OS_MACOSX) 150 #elif defined(OS_MACOSX)
148 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() 151 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create()
149 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() 152 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
150 #elif defined(OS_NACL) 153 #elif defined(OS_NACL)
151 // Currently NaCl doesn't have a UI or an IO MessageLoop. 154 // Currently NaCl doesn't have a UI or an IO MessageLoop.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 did_work = DeletePendingTasks(); 194 did_work = DeletePendingTasks();
192 if (!did_work) 195 if (!did_work)
193 break; 196 break;
194 } 197 }
195 DCHECK(!did_work); 198 DCHECK(!did_work);
196 199
197 // Let interested parties have one last shot at accessing this. 200 // Let interested parties have one last shot at accessing this.
198 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, 201 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_,
199 WillDestroyCurrentMessageLoop()); 202 WillDestroyCurrentMessageLoop());
200 203
204 thread_task_runner_handle_.reset();
205
201 // Tell the message_loop_proxy that we are dying. 206 // Tell the message_loop_proxy that we are dying.
202 static_cast<base::MessageLoopProxyImpl*>(message_loop_proxy_.get())-> 207 static_cast<base::MessageLoopProxyImpl*>(message_loop_proxy_.get())->
203 WillDestroyCurrentMessageLoop(); 208 WillDestroyCurrentMessageLoop();
204 message_loop_proxy_ = NULL; 209 message_loop_proxy_ = NULL;
205 210
206 // OK, now make it so that no one can find us. 211 // OK, now make it so that no one can find us.
207 lazy_tls_ptr.Pointer()->Set(NULL); 212 lazy_tls_ptr.Pointer()->Set(NULL);
208 213
209 #if defined(OS_WIN) 214 #if defined(OS_WIN)
210 // If we left the high-resolution timer activated, deactivate it now. 215 // If we left the high-resolution timer activated, deactivate it now.
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 Watcher *delegate) { 799 Watcher *delegate) {
795 return pump_libevent()->WatchFileDescriptor( 800 return pump_libevent()->WatchFileDescriptor(
796 fd, 801 fd,
797 persistent, 802 persistent,
798 static_cast<base::MessagePumpLibevent::Mode>(mode), 803 static_cast<base::MessagePumpLibevent::Mode>(mode),
799 controller, 804 controller,
800 delegate); 805 delegate);
801 } 806 }
802 807
803 #endif 808 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698