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

Side by Side Diff: base/message_loop.cc

Issue 7583053: Add MessageLoopProxy::current (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No need for MessageLoopProxy destruction observer. 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 | « base/message_loop.h ('k') | base/message_loop_proxy.h » ('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 #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/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop_proxy_impl.h"
15 #include "base/message_pump_default.h" 16 #include "base/message_pump_default.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
18 #include "base/threading/thread_local.h" 19 #include "base/threading/thread_local.h"
19 #include "base/time.h" 20 #include "base/time.h"
20 #include "base/tracked_objects.h" 21 #include "base/tracked_objects.h"
21 22
22 #if defined(OS_MACOSX) 23 #if defined(OS_MACOSX)
23 #include "base/message_pump_mac.h" 24 #include "base/message_pump_mac.h"
24 #endif 25 #endif
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 message_histogram_(NULL), 129 message_histogram_(NULL),
129 state_(NULL), 130 state_(NULL),
130 should_leak_tasks_(true), 131 should_leak_tasks_(true),
131 #ifdef OS_WIN 132 #ifdef OS_WIN
132 os_modal_loop_(false), 133 os_modal_loop_(false),
133 #endif // OS_WIN 134 #endif // OS_WIN
134 next_sequence_num_(0) { 135 next_sequence_num_(0) {
135 DCHECK(!current()) << "should only have one message loop per thread"; 136 DCHECK(!current()) << "should only have one message loop per thread";
136 lazy_tls_ptr.Pointer()->Set(this); 137 lazy_tls_ptr.Pointer()->Set(this);
137 138
139 message_loop_proxy_ = new base::MessageLoopProxyImpl();
140
138 // TODO(rvargas): Get rid of the OS guards. 141 // TODO(rvargas): Get rid of the OS guards.
139 #if defined(OS_WIN) 142 #if defined(OS_WIN)
140 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() 143 #define MESSAGE_PUMP_UI new base::MessagePumpForUI()
141 #define MESSAGE_PUMP_IO new base::MessagePumpForIO() 144 #define MESSAGE_PUMP_IO new base::MessagePumpForIO()
142 #elif defined(OS_MACOSX) 145 #elif defined(OS_MACOSX)
143 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() 146 #define MESSAGE_PUMP_UI base::MessagePumpMac::Create()
144 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() 147 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
145 #elif defined(OS_ANDROID) 148 #elif defined(OS_ANDROID)
146 #define MESSAGE_PUMP_UI new base::MessagePumpForUI() 149 #define MESSAGE_PUMP_UI new base::MessagePumpForUI()
147 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() 150 #define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 did_work = DeletePendingTasks(); 198 did_work = DeletePendingTasks();
196 if (!did_work) 199 if (!did_work)
197 break; 200 break;
198 } 201 }
199 DCHECK(!did_work); 202 DCHECK(!did_work);
200 203
201 // Let interested parties have one last shot at accessing this. 204 // Let interested parties have one last shot at accessing this.
202 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, 205 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_,
203 WillDestroyCurrentMessageLoop()); 206 WillDestroyCurrentMessageLoop());
204 207
208 // Tell the message_loop_proxy that we are dying.
209 static_cast<base::MessageLoopProxyImpl*>(message_loop_proxy_.get())->
210 WillDestroyCurrentMessageLoop();
211 message_loop_proxy_ = NULL;
212
205 // OK, now make it so that no one can find us. 213 // OK, now make it so that no one can find us.
206 lazy_tls_ptr.Pointer()->Set(NULL); 214 lazy_tls_ptr.Pointer()->Set(NULL);
207 215
208 #if defined(OS_WIN) 216 #if defined(OS_WIN)
209 // If we left the high-resolution timer activated, deactivate it now. 217 // If we left the high-resolution timer activated, deactivate it now.
210 // Doing this is not-critical, it is mainly to make sure we track 218 // Doing this is not-critical, it is mainly to make sure we track
211 // the high resolution timer activations properly in our unit tests. 219 // the high resolution timer activations properly in our unit tests.
212 if (!high_resolution_timer_expiration_.is_null()) { 220 if (!high_resolution_timer_expiration_.is_null()) {
213 base::Time::ActivateHighResolutionTimer(false); 221 base::Time::ActivateHighResolutionTimer(false);
214 high_resolution_timer_expiration_ = base::TimeTicks(); 222 high_resolution_timer_expiration_ = base::TimeTicks();
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 Watcher *delegate) { 847 Watcher *delegate) {
840 return pump_libevent()->WatchFileDescriptor( 848 return pump_libevent()->WatchFileDescriptor(
841 fd, 849 fd,
842 persistent, 850 persistent,
843 static_cast<base::MessagePumpLibevent::Mode>(mode), 851 static_cast<base::MessagePumpLibevent::Mode>(mode),
844 controller, 852 controller,
845 delegate); 853 delegate);
846 } 854 }
847 855
848 #endif 856 #endif
OLDNEW
« no previous file with comments | « base/message_loop.h ('k') | base/message_loop_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698