Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "wtf/Threading.h" | 37 #include "wtf/Threading.h" |
| 38 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 // Time intervals are all in seconds. | 42 // Time intervals are all in seconds. |
| 43 | 43 |
| 44 class PLATFORM_EXPORT TimerBase { | 44 class PLATFORM_EXPORT TimerBase { |
| 45 WTF_MAKE_NONCOPYABLE(TimerBase); | 45 WTF_MAKE_NONCOPYABLE(TimerBase); |
| 46 public: | 46 public: |
| 47 TimerBase(); | |
| 48 explicit TimerBase(WebTaskRunner*); | 47 explicit TimerBase(WebTaskRunner*); |
| 49 virtual ~TimerBase(); | 48 virtual ~TimerBase(); |
| 50 | 49 |
| 51 void start(double nextFireInterval, double repeatInterval, const WebTraceLoc ation&); | 50 void start(double nextFireInterval, double repeatInterval, const WebTraceLoc ation&); |
| 52 | 51 |
| 53 void startRepeating(double repeatInterval, const WebTraceLocation& caller) | 52 void startRepeating(double repeatInterval, const WebTraceLocation& caller) |
| 54 { | 53 { |
| 55 start(repeatInterval, repeatInterval, caller); | 54 start(repeatInterval, repeatInterval, caller); |
| 56 } | 55 } |
| 57 void startOneShot(double interval, const WebTraceLocation& caller) | 56 void startOneShot(double interval, const WebTraceLocation& caller) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 70 double now = timerMonotonicallyIncreasingTime(); | 69 double now = timerMonotonicallyIncreasingTime(); |
| 71 setNextFireTime(now, std::max(m_nextFireTime - now + delta, 0.0)); | 70 setNextFireTime(now, std::max(m_nextFireTime - now + delta, 0.0)); |
| 72 m_repeatInterval += delta; | 71 m_repeatInterval += delta; |
| 73 } | 72 } |
| 74 | 73 |
| 75 struct PLATFORM_EXPORT Comparator { | 74 struct PLATFORM_EXPORT Comparator { |
| 76 bool operator()(const TimerBase* a, const TimerBase* b) const; | 75 bool operator()(const TimerBase* a, const TimerBase* b) const; |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 protected: | 78 protected: |
| 80 static WebTaskRunner* UnthrottledWebTaskRunner(); | 79 static WebTaskRunner* getTimerTaskRunner(); |
| 80 static WebTaskRunner* getDefaultTaskRunner(); | |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 virtual void fired() = 0; | 83 virtual void fired() = 0; |
| 84 | 84 |
| 85 virtual WebTaskRunner* timerTaskRunner() const; | 85 virtual WebTaskRunner* timerTaskRunner() const; |
| 86 | 86 |
| 87 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 87 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 88 virtual bool canFire() const { return true; } | 88 virtual bool canFire() const { return true; } |
| 89 | 89 |
| 90 double timerMonotonicallyIncreasingTime() const; | 90 double timerMonotonicallyIncreasingTime() const; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 template<typename T> | 148 template<typename T> |
| 149 class TimerIsObjectAliveTrait<T, true> { | 149 class TimerIsObjectAliveTrait<T, true> { |
| 150 public: | 150 public: |
| 151 static bool isHeapObjectAlive(T* objectPointer) | 151 static bool isHeapObjectAlive(T* objectPointer) |
| 152 { | 152 { |
| 153 return !ThreadHeap::willObjectBeLazilySwept(objectPointer); | 153 return !ThreadHeap::willObjectBeLazilySwept(objectPointer); |
| 154 } | 154 } |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 template <typename TimerFiredClass> | 157 template <typename TimerFiredClass> |
| 158 class Timer : public TimerBase { | 158 class TaskRunnerTimer : public TimerBase { |
| 159 public: | 159 public: |
| 160 using TimerFiredFunction = void (TimerFiredClass::*)(Timer<TimerFiredClass>* ); | 160 using TimerFiredFunction = void (TimerFiredClass::*)(TimerBase*); |
| 161 | 161 |
| 162 // TODO(dcheng): Consider removing this overload once all timers are using t he | 162 TaskRunnerTimer(WebTaskRunner* webTaskRunner, TimerFiredClass* o, TimerFired Function f) |
| 163 // appropriate task runner. https://crbug.com/624694 | |
| 164 Timer(TimerFiredClass* o, TimerFiredFunction f) | |
| 165 : m_object(o), m_function(f) | |
| 166 { | |
| 167 } | |
| 168 | |
| 169 Timer(TimerFiredClass* o, TimerFiredFunction f, WebTaskRunner* webTaskRunner ) | |
| 170 : TimerBase(webTaskRunner), m_object(o), m_function(f) | 163 : TimerBase(webTaskRunner), m_object(o), m_function(f) |
| 171 { | 164 { |
| 172 } | 165 } |
| 173 | 166 |
| 174 ~Timer() override { } | 167 ~TaskRunnerTimer() override { } |
| 175 | 168 |
| 176 protected: | 169 protected: |
| 177 void fired() override | 170 void fired() override |
| 178 { | 171 { |
| 179 (m_object->*m_function)(this); | 172 (m_object->*m_function)(this); |
| 180 } | 173 } |
| 181 | 174 |
| 182 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 175 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 183 bool canFire() const override | 176 bool canFire() const override |
| 184 { | 177 { |
| 185 // Oilpan: if a timer fires while Oilpan heaps are being lazily | 178 // Oilpan: if a timer fires while Oilpan heaps are being lazily |
| 186 // swept, it is not safe to proceed if the object is about to | 179 // swept, it is not safe to proceed if the object is about to |
| 187 // be swept (and this timer will be stopped while doing so.) | 180 // be swept (and this timer will be stopped while doing so.) |
| 188 return TimerIsObjectAliveTrait<TimerFiredClass>::isHeapObjectAlive(m_obj ect); | 181 return TimerIsObjectAliveTrait<TimerFiredClass>::isHeapObjectAlive(m_obj ect); |
| 189 } | 182 } |
| 190 | 183 |
| 191 private: | 184 private: |
| 192 // FIXME: Oilpan: TimerBase should be moved to the heap and m_object should be traced. | 185 // FIXME: Oilpan: TimerBase should be moved to the heap and m_object should be traced. |
| 193 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha t's the case | 186 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha t's the case |
| 194 // in the current code base). | 187 // in the current code base). |
| 195 GC_PLUGIN_IGNORE("363031") | 188 GC_PLUGIN_IGNORE("363031") |
| 196 TimerFiredClass* m_object; | 189 TimerFiredClass* m_object; |
| 197 TimerFiredFunction m_function; | 190 TimerFiredFunction m_function; |
| 198 }; | 191 }; |
| 199 | 192 |
| 193 // TODO(dcheng): Consider removing this overload once all timers are using the | |
| 194 // appropriate task runner. https://crbug.com/624694 | |
| 195 template <typename TimerFiredClass> | |
| 196 class Timer : public TaskRunnerTimer<TimerFiredClass> { | |
| 197 public: | |
| 198 using TimerFiredFunction = typename TaskRunnerTimer<TimerFiredClass>::TimerF iredFunction; | |
| 199 | |
| 200 ~Timer() override { } | |
| 201 | |
| 202 Timer(TimerFiredClass* timerFiredClass, TimerFiredFunction timerFiredFunctio n) | |
| 203 : TaskRunnerTimer<TimerFiredClass>(TimerBase::getTimerTaskRunner(), time rFiredClass, timerFiredFunction) | |
|
haraken
2016/07/28 14:44:46
Doesn't this mean that all Timers start using the
Sami
2016/07/28 16:38:55
All timers already use the timer task runner, unle
haraken
2016/07/28 17:38:15
Oh, I was misunderstanding. You're right.
- Only
dcheng
2016/07/29 02:23:18
Right, per Sami, the default for Timer right now i
| |
| 204 { | |
| 205 } | |
| 206 }; | |
| 207 | |
| 208 | |
| 200 // This subclass of Timer posts its tasks on the current thread's default task r unner. | 209 // This subclass of Timer posts its tasks on the current thread's default task r unner. |
| 201 // Tasks posted on there are not throttled when the tab is in the background. | 210 // Tasks posted on there are not throttled when the tab is in the background. |
| 202 template <typename TimerFiredClass> | 211 template <typename TimerFiredClass> |
| 203 class UnthrottledTimer : public Timer<TimerFiredClass> { | 212 class UnthrottledThreadTimer : public TaskRunnerTimer<TimerFiredClass> { |
|
haraken
2016/07/28 14:44:46
Maybe can we keep the current name as is? Unthrott
dcheng
2016/07/29 02:23:18
I think this might be confusing in combination wit
haraken
2016/07/29 08:35:27
Is your plan to replace UnthrottledThreadTimer wit
dcheng
2016/07/29 08:44:40
Yes, though I would probably just use a subclass o
| |
| 204 public: | 213 public: |
| 205 using TimerFiredFunction = void (TimerFiredClass::*)(Timer<TimerFiredClass>* ); | 214 using TimerFiredFunction = typename TaskRunnerTimer<TimerFiredClass>::TimerF iredFunction; |
| 206 | 215 |
| 207 ~UnthrottledTimer() override { } | 216 ~UnthrottledThreadTimer() override { } |
| 208 | 217 |
| 209 UnthrottledTimer(TimerFiredClass* timerFiredClass, TimerFiredFunction timerF iredFunction) | 218 UnthrottledThreadTimer(TimerFiredClass* timerFiredClass, TimerFiredFunction timerFiredFunction) |
| 210 : Timer<TimerFiredClass>(timerFiredClass, timerFiredFunction, TimerBase: :UnthrottledWebTaskRunner()) | 219 : TaskRunnerTimer<TimerFiredClass>(TimerBase::getDefaultTaskRunner(), ti merFiredClass, timerFiredFunction) |
| 211 { | 220 { |
| 212 } | 221 } |
| 213 }; | 222 }; |
| 214 | 223 |
| 215 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 224 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 216 inline bool TimerBase::isActive() const | 225 inline bool TimerBase::isActive() const |
| 217 { | 226 { |
| 218 ASSERT(m_thread == currentThread()); | 227 ASSERT(m_thread == currentThread()); |
| 219 return m_cancellableTimerTask; | 228 return m_cancellableTimerTask; |
| 220 } | 229 } |
| 221 | 230 |
| 222 } // namespace blink | 231 } // namespace blink |
| 223 | 232 |
| 224 #endif // Timer_h | 233 #endif // Timer_h |
| OLD | NEW |