| 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 28 matching lines...) Expand all Loading... |
| 39 #include "wtf/WeakPtr.h" | 39 #include "wtf/WeakPtr.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 // Time intervals are all in seconds. | 43 // Time intervals are all in seconds. |
| 44 | 44 |
| 45 class PLATFORM_EXPORT TimerBase { | 45 class PLATFORM_EXPORT TimerBase { |
| 46 WTF_MAKE_NONCOPYABLE(TimerBase); | 46 WTF_MAKE_NONCOPYABLE(TimerBase); |
| 47 | 47 |
| 48 public: | 48 public: |
| 49 explicit TimerBase(WebTaskRunner*); | 49 explicit TimerBase(RefPtr<WebTaskRunner>); |
| 50 virtual ~TimerBase(); | 50 virtual ~TimerBase(); |
| 51 | 51 |
| 52 void start(double nextFireInterval, | 52 void start(double nextFireInterval, |
| 53 double repeatInterval, | 53 double repeatInterval, |
| 54 const WebTraceLocation&); | 54 const WebTraceLocation&); |
| 55 | 55 |
| 56 void startRepeating(double repeatInterval, const WebTraceLocation& caller) { | 56 void startRepeating(double repeatInterval, const WebTraceLocation& caller) { |
| 57 start(repeatInterval, repeatInterval, caller); | 57 start(repeatInterval, repeatInterval, caller); |
| 58 } | 58 } |
| 59 void startOneShot(double interval, const WebTraceLocation& caller) { | 59 void startOneShot(double interval, const WebTraceLocation& caller) { |
| 60 start(interval, 0, caller); | 60 start(interval, 0, caller); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Timer cancellation is fast enough that you shouldn't have to worry | 63 // Timer cancellation is fast enough that you shouldn't have to worry |
| 64 // about it unless you're canceling tens of thousands of tasks. | 64 // about it unless you're canceling tens of thousands of tasks. |
| 65 virtual void stop(); | 65 virtual void stop(); |
| 66 bool isActive() const; | 66 bool isActive() const; |
| 67 const WebTraceLocation& location() const { return m_location; } | 67 const WebTraceLocation& location() const { return m_location; } |
| 68 | 68 |
| 69 double nextFireInterval() const; | 69 double nextFireInterval() const; |
| 70 double repeatInterval() const { return m_repeatInterval; } | 70 double repeatInterval() const { return m_repeatInterval; } |
| 71 | 71 |
| 72 void augmentRepeatInterval(double delta) { | 72 void augmentRepeatInterval(double delta) { |
| 73 double now = timerMonotonicallyIncreasingTime(); | 73 double now = timerMonotonicallyIncreasingTime(); |
| 74 setNextFireTime(now, std::max(m_nextFireTime - now + delta, 0.0)); | 74 setNextFireTime(now, std::max(m_nextFireTime - now + delta, 0.0)); |
| 75 m_repeatInterval += delta; | 75 m_repeatInterval += delta; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void moveToNewTaskRunner(WebTaskRunner*); | 78 void moveToNewTaskRunner(RefPtr<WebTaskRunner>); |
| 79 | 79 |
| 80 struct PLATFORM_EXPORT Comparator { | 80 struct PLATFORM_EXPORT Comparator { |
| 81 bool operator()(const TimerBase* a, const TimerBase* b) const; | 81 bool operator()(const TimerBase* a, const TimerBase* b) const; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 protected: | 84 protected: |
| 85 static WebTaskRunner* getTimerTaskRunner(); | 85 static RefPtr<WebTaskRunner> getTimerTaskRunner(); |
| 86 static WebTaskRunner* getUnthrottledTaskRunner(); | 86 static RefPtr<WebTaskRunner> getUnthrottledTaskRunner(); |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 virtual void fired() = 0; | 89 virtual void fired() = 0; |
| 90 | 90 |
| 91 virtual WebTaskRunner* timerTaskRunner() const; | 91 virtual RefPtr<WebTaskRunner> timerTaskRunner() const; |
| 92 | 92 |
| 93 NO_SANITIZE_ADDRESS | 93 NO_SANITIZE_ADDRESS |
| 94 virtual bool canFire() const { return true; } | 94 virtual bool canFire() const { return true; } |
| 95 | 95 |
| 96 double timerMonotonicallyIncreasingTime() const; | 96 double timerMonotonicallyIncreasingTime() const; |
| 97 | 97 |
| 98 void setNextFireTime(double now, double delay); | 98 void setNextFireTime(double now, double delay); |
| 99 | 99 |
| 100 void runInternal(); | 100 void runInternal(); |
| 101 | 101 |
| 102 double m_nextFireTime; // 0 if inactive | 102 double m_nextFireTime; // 0 if inactive |
| 103 double m_repeatInterval; // 0 if not repeating | 103 double m_repeatInterval; // 0 if not repeating |
| 104 WebTraceLocation m_location; | 104 WebTraceLocation m_location; |
| 105 std::unique_ptr<WebTaskRunner> m_webTaskRunner; | 105 RefPtr<WebTaskRunner> m_webTaskRunner; |
| 106 | 106 |
| 107 #if DCHECK_IS_ON() | 107 #if DCHECK_IS_ON() |
| 108 ThreadIdentifier m_thread; | 108 ThreadIdentifier m_thread; |
| 109 #endif | 109 #endif |
| 110 WTF::WeakPtrFactory<TimerBase> m_weakPtrFactory; | 110 WTF::WeakPtrFactory<TimerBase> m_weakPtrFactory; |
| 111 | 111 |
| 112 friend class ThreadTimers; | 112 friend class ThreadTimers; |
| 113 friend class TimerHeapLessThanFunction; | 113 friend class TimerHeapLessThanFunction; |
| 114 friend class TimerHeapReference; | 114 friend class TimerHeapReference; |
| 115 }; | 115 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 126 static bool isHeapObjectAlive(T* objectPointer) { | 126 static bool isHeapObjectAlive(T* objectPointer) { |
| 127 return !ThreadHeap::willObjectBeLazilySwept(objectPointer); | 127 return !ThreadHeap::willObjectBeLazilySwept(objectPointer); |
| 128 } | 128 } |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 template <typename TimerFiredClass> | 131 template <typename TimerFiredClass> |
| 132 class TaskRunnerTimer : public TimerBase { | 132 class TaskRunnerTimer : public TimerBase { |
| 133 public: | 133 public: |
| 134 using TimerFiredFunction = void (TimerFiredClass::*)(TimerBase*); | 134 using TimerFiredFunction = void (TimerFiredClass::*)(TimerBase*); |
| 135 | 135 |
| 136 TaskRunnerTimer(WebTaskRunner* webTaskRunner, | 136 TaskRunnerTimer(RefPtr<WebTaskRunner> webTaskRunner, |
| 137 TimerFiredClass* o, | 137 TimerFiredClass* o, |
| 138 TimerFiredFunction f) | 138 TimerFiredFunction f) |
| 139 : TimerBase(webTaskRunner), m_object(o), m_function(f) {} | 139 : TimerBase(std::move(webTaskRunner)), m_object(o), m_function(f) {} |
| 140 | 140 |
| 141 ~TaskRunnerTimer() override {} | 141 ~TaskRunnerTimer() override {} |
| 142 | 142 |
| 143 protected: | 143 protected: |
| 144 void fired() override { (m_object->*m_function)(this); } | 144 void fired() override { (m_object->*m_function)(this); } |
| 145 | 145 |
| 146 NO_SANITIZE_ADDRESS | 146 NO_SANITIZE_ADDRESS |
| 147 bool canFire() const override { | 147 bool canFire() const override { |
| 148 // Oilpan: if a timer fires while Oilpan heaps are being lazily | 148 // Oilpan: if a timer fires while Oilpan heaps are being lazily |
| 149 // swept, it is not safe to proceed if the object is about to | 149 // swept, it is not safe to proceed if the object is about to |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 inline bool TimerBase::isActive() const { | 202 inline bool TimerBase::isActive() const { |
| 203 #if DCHECK_IS_ON() | 203 #if DCHECK_IS_ON() |
| 204 DCHECK_EQ(m_thread, currentThread()); | 204 DCHECK_EQ(m_thread, currentThread()); |
| 205 #endif | 205 #endif |
| 206 return m_weakPtrFactory.hasWeakPtrs(); | 206 return m_weakPtrFactory.hasWeakPtrs(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // namespace blink | 209 } // namespace blink |
| 210 | 210 |
| 211 #endif // Timer_h | 211 #endif // Timer_h |
| OLD | NEW |