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

Side by Side Diff: base/message_loop.cc

Issue 6904117: Reland old fix that was reverted without my knowledge. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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
« no previous file with comments | « no previous file | base/time.h » ('j') | base/time_win.cc » ('J')
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/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_pump_default.h" 13 #include "base/message_pump_default.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
16 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 16 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
17 #include "base/threading/thread_local.h" 17 #include "base/threading/thread_local.h"
18 #include "base/time.h"
18 #include "base/tracked_objects.h" 19 #include "base/tracked_objects.h"
19 20
20 #if defined(OS_MACOSX) 21 #if defined(OS_MACOSX)
21 #include "base/message_pump_mac.h" 22 #include "base/message_pump_mac.h"
22 #endif 23 #endif
23 #if defined(OS_POSIX) 24 #if defined(OS_POSIX)
24 #include "base/message_pump_libevent.h" 25 #include "base/message_pump_libevent.h"
25 #endif 26 #endif
26 #if defined(OS_POSIX) && !defined(OS_MACOSX) 27 #if defined(OS_POSIX) && !defined(OS_MACOSX)
27 #include <gdk/gdk.h> 28 #include <gdk/gdk.h>
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 break; 220 break;
220 } 221 }
221 DCHECK(!did_work); 222 DCHECK(!did_work);
222 223
223 // Let interested parties have one last shot at accessing this. 224 // Let interested parties have one last shot at accessing this.
224 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, 225 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_,
225 WillDestroyCurrentMessageLoop()); 226 WillDestroyCurrentMessageLoop());
226 227
227 // OK, now make it so that no one can find us. 228 // OK, now make it so that no one can find us.
228 lazy_tls_ptr.Pointer()->Set(NULL); 229 lazy_tls_ptr.Pointer()->Set(NULL);
230
231 #if defined(OS_WIN)
232 // If we left the high-resolution timer activated, deactivate it now.
233 // Doing this is not-critical, it is mainly to make sure we track
234 // the high resolution timer activations properly in our unit tests.
235 if (!high_resolution_timer_expiration_.is_null()) {
236 base::Time::ActivateHighResolutionTimer(false);
237 high_resolution_timer_expiration_ = base::TimeTicks();
238 }
239 #endif
229 } 240 }
230 241
231 // static 242 // static
232 MessageLoop* MessageLoop::current() { 243 MessageLoop* MessageLoop::current() {
233 // TODO(darin): sadly, we cannot enable this yet since people call us even 244 // TODO(darin): sadly, we cannot enable this yet since people call us even
234 // when they have no intention of using us. 245 // when they have no intention of using us.
235 // DCHECK(loop) << "Ouch, did you forget to initialize me?"; 246 // DCHECK(loop) << "Ouch, did you forget to initialize me?";
236 return lazy_tls_ptr.Pointer()->Get(); 247 return lazy_tls_ptr.Pointer()->Get();
237 } 248 }
238 249
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 #if defined(OS_WIN) 576 #if defined(OS_WIN)
566 if (high_resolution_timer_expiration_.is_null()) { 577 if (high_resolution_timer_expiration_.is_null()) {
567 // Windows timers are granular to 15.6ms. If we only set high-res 578 // Windows timers are granular to 15.6ms. If we only set high-res
568 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, 579 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms,
569 // which as a percentage is pretty inaccurate. So enable high 580 // which as a percentage is pretty inaccurate. So enable high
570 // res timers for any timer which is within 2x of the granularity. 581 // res timers for any timer which is within 2x of the granularity.
571 // This is a tradeoff between accuracy and power management. 582 // This is a tradeoff between accuracy and power management.
572 bool needs_high_res_timers = 583 bool needs_high_res_timers =
573 delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs); 584 delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs);
574 if (needs_high_res_timers) { 585 if (needs_high_res_timers) {
575 base::Time::ActivateHighResolutionTimer(true); 586 if (base::Time::ActivateHighResolutionTimer(true)) {
576 high_resolution_timer_expiration_ = TimeTicks::Now() + 587 high_resolution_timer_expiration_ = TimeTicks::Now() +
577 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); 588 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs);
589 }
578 } 590 }
579 } 591 }
580 #endif 592 #endif
581 } else { 593 } else {
582 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; 594 DCHECK_EQ(delay_ms, 0) << "delay should not be negative";
583 } 595 }
584 596
585 #if defined(OS_WIN) 597 #if defined(OS_WIN)
586 if (!high_resolution_timer_expiration_.is_null()) { 598 if (!high_resolution_timer_expiration_.is_null()) {
587 if (TimeTicks::Now() > high_resolution_timer_expiration_) { 599 if (TimeTicks::Now() > high_resolution_timer_expiration_) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 Watcher *delegate) { 849 Watcher *delegate) {
838 return pump_libevent()->WatchFileDescriptor( 850 return pump_libevent()->WatchFileDescriptor(
839 fd, 851 fd,
840 persistent, 852 persistent,
841 static_cast<base::MessagePumpLibevent::Mode>(mode), 853 static_cast<base::MessagePumpLibevent::Mode>(mode),
842 controller, 854 controller,
843 delegate); 855 delegate);
844 } 856 }
845 857
846 #endif 858 #endif
OLDNEW
« no previous file with comments | « no previous file | base/time.h » ('j') | base/time_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698