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

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

Issue 2550373005: Make WebTaskRunner ThreadSafeRefCounted (Closed)
Patch Set: mac fix Created 4 years 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 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
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) {
(...skipping 13 matching lines...) Expand all
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 struct PLATFORM_EXPORT Comparator { 78 struct PLATFORM_EXPORT Comparator {
79 bool operator()(const TimerBase* a, const TimerBase* b) const; 79 bool operator()(const TimerBase* a, const TimerBase* b) const;
80 }; 80 };
81 81
82 protected: 82 protected:
83 static WebTaskRunner* getTimerTaskRunner(); 83 static RefPtr<WebTaskRunner> getTimerTaskRunner();
84 static WebTaskRunner* getUnthrottledTaskRunner(); 84 static RefPtr<WebTaskRunner> getUnthrottledTaskRunner();
85 85
86 private: 86 private:
87 virtual void fired() = 0; 87 virtual void fired() = 0;
88 88
89 virtual WebTaskRunner* timerTaskRunner() const; 89 virtual RefPtr<WebTaskRunner> timerTaskRunner() const;
90 90
91 NO_SANITIZE_ADDRESS 91 NO_SANITIZE_ADDRESS
92 virtual bool canFire() const { return true; } 92 virtual bool canFire() const { return true; }
93 93
94 double timerMonotonicallyIncreasingTime() const; 94 double timerMonotonicallyIncreasingTime() const;
95 95
96 void setNextFireTime(double now, double delay); 96 void setNextFireTime(double now, double delay);
97 97
98 void runInternal(); 98 void runInternal();
99 99
100 double m_nextFireTime; // 0 if inactive 100 double m_nextFireTime; // 0 if inactive
101 double m_repeatInterval; // 0 if not repeating 101 double m_repeatInterval; // 0 if not repeating
102 WebTraceLocation m_location; 102 WebTraceLocation m_location;
103 std::unique_ptr<WebTaskRunner> m_webTaskRunner; 103 RefPtr<WebTaskRunner> m_webTaskRunner;
104 104
105 #if DCHECK_IS_ON() 105 #if DCHECK_IS_ON()
106 ThreadIdentifier m_thread; 106 ThreadIdentifier m_thread;
107 #endif 107 #endif
108 WTF::WeakPtrFactory<TimerBase> m_weakPtrFactory; 108 WTF::WeakPtrFactory<TimerBase> m_weakPtrFactory;
109 109
110 friend class ThreadTimers; 110 friend class ThreadTimers;
111 friend class TimerHeapLessThanFunction; 111 friend class TimerHeapLessThanFunction;
112 friend class TimerHeapReference; 112 friend class TimerHeapReference;
113 }; 113 };
(...skipping 10 matching lines...) Expand all
124 static bool isHeapObjectAlive(T* objectPointer) { 124 static bool isHeapObjectAlive(T* objectPointer) {
125 return !ThreadHeap::willObjectBeLazilySwept(objectPointer); 125 return !ThreadHeap::willObjectBeLazilySwept(objectPointer);
126 } 126 }
127 }; 127 };
128 128
129 template <typename TimerFiredClass> 129 template <typename TimerFiredClass>
130 class TaskRunnerTimer : public TimerBase { 130 class TaskRunnerTimer : public TimerBase {
131 public: 131 public:
132 using TimerFiredFunction = void (TimerFiredClass::*)(TimerBase*); 132 using TimerFiredFunction = void (TimerFiredClass::*)(TimerBase*);
133 133
134 TaskRunnerTimer(WebTaskRunner* webTaskRunner, 134 TaskRunnerTimer(RefPtr<WebTaskRunner> webTaskRunner,
135 TimerFiredClass* o, 135 TimerFiredClass* o,
136 TimerFiredFunction f) 136 TimerFiredFunction f)
137 : TimerBase(webTaskRunner), m_object(o), m_function(f) {} 137 : TimerBase(std::move(webTaskRunner)), m_object(o), m_function(f) {}
138 138
139 ~TaskRunnerTimer() override {} 139 ~TaskRunnerTimer() override {}
140 140
141 protected: 141 protected:
142 void fired() override { (m_object->*m_function)(this); } 142 void fired() override { (m_object->*m_function)(this); }
143 143
144 NO_SANITIZE_ADDRESS 144 NO_SANITIZE_ADDRESS
145 bool canFire() const override { 145 bool canFire() const override {
146 // Oilpan: if a timer fires while Oilpan heaps are being lazily 146 // Oilpan: if a timer fires while Oilpan heaps are being lazily
147 // swept, it is not safe to proceed if the object is about to 147 // swept, it is not safe to proceed if the object is about to
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 inline bool TimerBase::isActive() const { 198 inline bool TimerBase::isActive() const {
199 #if DCHECK_IS_ON() 199 #if DCHECK_IS_ON()
200 DCHECK_EQ(m_thread, currentThread()); 200 DCHECK_EQ(m_thread, currentThread());
201 #endif 201 #endif
202 return m_weakPtrFactory.hasWeakPtrs(); 202 return m_weakPtrFactory.hasWeakPtrs();
203 } 203 }
204 204
205 } // namespace blink 205 } // namespace blink
206 206
207 #endif // Timer_h 207 #endif // Timer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698