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

Side by Side Diff: third_party/WebKit/Source/platform/Timer.cpp

Issue 1340343003: scheduler: Implement WebFrameScheduler and WebPageScheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased + fixed gn build. Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 double TimerBase::nextFireInterval() const 81 double TimerBase::nextFireInterval() const
82 { 82 {
83 ASSERT(isActive()); 83 ASSERT(isActive());
84 double current = monotonicallyIncreasingTime(); 84 double current = monotonicallyIncreasingTime();
85 if (m_nextFireTime < current) 85 if (m_nextFireTime < current)
86 return 0; 86 return 0;
87 return m_nextFireTime - current; 87 return m_nextFireTime - current;
88 } 88 }
89 89
90 WebTaskRunner* TimerBase::timerTaskRunner()
91 {
92 return m_webScheduler->timerTaskRunner();
93 }
94
90 void TimerBase::setNextFireTime(double now, double delay) 95 void TimerBase::setNextFireTime(double now, double delay)
91 { 96 {
92 ASSERT(m_thread == currentThread()); 97 ASSERT(m_thread == currentThread());
93 98
94 m_unalignedNextFireTime = now + delay; 99 m_unalignedNextFireTime = now + delay;
95 100
96 double newTime = alignedFireTime(m_unalignedNextFireTime); 101 double newTime = alignedFireTime(m_unalignedNextFireTime);
97 if (m_nextFireTime != newTime) { 102 if (m_nextFireTime != newTime) {
98 m_nextFireTime = newTime; 103 m_nextFireTime = newTime;
99 if (m_cancellableTimerTask) 104 if (m_cancellableTimerTask)
100 m_cancellableTimerTask->cancel(); 105 m_cancellableTimerTask->cancel();
101 m_cancellableTimerTask = new CancellableTimerTask(this); 106 m_cancellableTimerTask = new CancellableTimerTask(this);
102 if (newTime != m_unalignedNextFireTime) { 107 if (newTime != m_unalignedNextFireTime) {
103 // If the timer is being aligned, use postTimerTaskAt() to schedule it 108 // If the timer is being aligned, use postTimerTaskAt() to schedule it
104 // so that the relative order of aligned timers is preserved. 109 // so that the relative order of aligned timers is preserved.
105 // TODO(skyostil): Move timer alignment into the scheduler. 110 // TODO(skyostil): Move timer alignment into the scheduler.
106 m_webScheduler->postTimerTaskAt(m_location, m_cancellableTimerTask, m_nextFireTime); 111 m_webScheduler->postTimerTaskAt(m_location, m_cancellableTimerTask, m_nextFireTime);
107 } else { 112 } else {
108 // Round the delay up to the nearest millisecond to be consistant wi th the 113 // Round the delay up to the nearest millisecond to be consistant wi th the
109 // previous behavior of BlinkPlatformImpl::setSharedTimerFireInterva l. 114 // previous behavior of BlinkPlatformImpl::setSharedTimerFireInterva l.
110 long long delayMs = static_cast<long long>(ceil((newTime - now) * 10 00.0)); 115 long long delayMs = static_cast<long long>(ceil((newTime - now) * 10 00.0));
111 if (delayMs < 0) 116 if (delayMs < 0)
112 delayMs = 0; 117 delayMs = 0;
113 m_webScheduler->timerTaskRunner()->postDelayedTask(m_location, m_can cellableTimerTask, delayMs); 118 timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTas k, delayMs);
114 } 119 }
115 } 120 }
116 } 121 }
117 122
118 NO_LAZY_SWEEP_SANITIZE_ADDRESS 123 NO_LAZY_SWEEP_SANITIZE_ADDRESS
119 void TimerBase::runInternal() 124 void TimerBase::runInternal()
120 { 125 {
121 if (!canFire()) 126 if (!canFire())
122 return; 127 return;
123 128
(...skipping 20 matching lines...) Expand all
144 ASSERT(isActive()); 149 ASSERT(isActive());
145 return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0 ); 150 return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0 );
146 } 151 }
147 152
148 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c onst 153 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c onst
149 { 154 {
150 return a->m_unalignedNextFireTime < b->m_unalignedNextFireTime; 155 return a->m_unalignedNextFireTime < b->m_unalignedNextFireTime;
151 } 156 }
152 157
153 } // namespace blink 158 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | third_party/WebKit/Source/platform/WebScheduler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698