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

Side by Side Diff: Source/core/page/DOMTimer.cpp

Issue 19494002: Distinguish actions registered with setTimeout() and setInterval(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase again. Created 7 years, 5 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
« no previous file with comments | « Source/core/page/DOMTimer.h ('k') | Source/core/page/DOMWindowTimers.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // second at most. 61 // second at most.
62 return 1.0; 62 return 1.0;
63 } 63 }
64 64
65 double DOMTimer::visiblePageAlignmentInterval() 65 double DOMTimer::visiblePageAlignmentInterval()
66 { 66 {
67 // Alignment does not apply to timers on visible pages. 67 // Alignment does not apply to timers on visible pages.
68 return 0; 68 return 0;
69 } 69 }
70 70
71 int DOMTimer::install(ScriptExecutionContext* context, PassOwnPtr<ScheduledActio n> action, int timeout, bool singleShot) 71 int DOMTimer::install(ScriptExecutionContext* context, Type type, PassOwnPtr<Sch eduledAction> action, int timeout)
72 { 72 {
73 int timeoutID = context->installNewTimeout(action, timeout, singleShot); 73 int timeoutID = context->installNewTimeout(type, action, timeout);
74 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singl eShot); 74 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, type == TimeoutType); // FIXME: Fix inspector so it can accept a DOMTimer::Type value .
75 return timeoutID; 75 return timeoutID;
76 } 76 }
77 77
78 void DOMTimer::removeByID(ScriptExecutionContext* context, int timeoutID) 78 void DOMTimer::removeByIDIfTypeMatches(ScriptExecutionContext* context, Type typ e, int timeoutID)
79 { 79 {
80 context->removeTimeoutByID(timeoutID); 80 // FIXME: Invoke didRemoveTimer() if a timer is actually removed.
81 context->removeTimeoutByIDIfTypeMatches(type, timeoutID);
81 InspectorInstrumentation::didRemoveTimer(context, timeoutID); 82 InspectorInstrumentation::didRemoveTimer(context, timeoutID);
82 } 83 }
83 84
84 DOMTimer::DOMTimer(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int interval, bool singleShot, int timeoutID) 85 DOMTimer::DOMTimer(ScriptExecutionContext* context, Type type, PassOwnPtr<Schedu ledAction> action, int interval, int timeoutID)
85 : SuspendableTimer(context) 86 : SuspendableTimer(context)
87 , m_type(type)
86 , m_timeoutID(timeoutID) 88 , m_timeoutID(timeoutID)
87 , m_nestingLevel(timerNestingLevel + 1) 89 , m_nestingLevel(timerNestingLevel + 1)
88 , m_action(action) 90 , m_action(action)
89 { 91 {
90 ASSERT(timeoutID > 0); 92 ASSERT(timeoutID > 0);
91 if (shouldForwardUserGesture(interval, m_nestingLevel)) 93 if (shouldForwardUserGesture(interval, m_nestingLevel))
92 m_userGestureToken = UserGestureIndicator::currentToken(); 94 m_userGestureToken = UserGestureIndicator::currentToken();
93 95
94 double intervalMilliseconds = max(oneMillisecond, interval * oneMillisecond) ; 96 double intervalMilliseconds = max(oneMillisecond, interval * oneMillisecond) ;
95 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest ingLevel) 97 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest ingLevel)
96 intervalMilliseconds = minimumInterval; 98 intervalMilliseconds = minimumInterval;
97 if (singleShot) 99 switch (type) {
100 case TimeoutType:
98 startOneShot(intervalMilliseconds); 101 startOneShot(intervalMilliseconds);
99 else 102 break;
103 case IntervalType:
100 startRepeating(intervalMilliseconds); 104 startRepeating(intervalMilliseconds);
105 break;
106 }
101 } 107 }
102 108
103 DOMTimer::~DOMTimer() 109 DOMTimer::~DOMTimer()
104 { 110 {
105 } 111 }
106 112
107 int DOMTimer::timeoutID() const 113 int DOMTimer::timeoutID() const
108 { 114 {
109 return m_timeoutID; 115 return m_timeoutID;
110 } 116 }
111 117
118 DOMTimer::Type DOMTimer::type() const
119 {
120 return m_type;
121 }
122
112 void DOMTimer::fired() 123 void DOMTimer::fired()
113 { 124 {
114 ScriptExecutionContext* context = scriptExecutionContext(); 125 ScriptExecutionContext* context = scriptExecutionContext();
115 timerNestingLevel = m_nestingLevel; 126 timerNestingLevel = m_nestingLevel;
116 ASSERT(!context->activeDOMObjectsAreSuspended()); 127 ASSERT(!context->activeDOMObjectsAreSuspended());
117 // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator. 128 // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator.
118 UserGestureIndicator gestureIndicator(m_userGestureToken.release()); 129 UserGestureIndicator gestureIndicator(m_userGestureToken.release());
119 130
120 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireTi mer(context, m_timeoutID); 131 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireTi mer(context, m_timeoutID);
121 132
(...skipping 10 matching lines...) Expand all
132 143
133 InspectorInstrumentation::didFireTimer(cookie); 144 InspectorInstrumentation::didFireTimer(cookie);
134 145
135 return; 146 return;
136 } 147 }
137 148
138 // Delete timer before executing the action for one-shot timers. 149 // Delete timer before executing the action for one-shot timers.
139 OwnPtr<ScheduledAction> action = m_action.release(); 150 OwnPtr<ScheduledAction> action = m_action.release();
140 151
141 // This timer is being deleted; no access to member variables allowed after this point. 152 // This timer is being deleted; no access to member variables allowed after this point.
142 context->removeTimeoutByID(m_timeoutID); 153 bool removed = context->removeTimeoutByIDIfTypeMatches(m_type, m_timeoutID);
154 ASSERT_UNUSED(removed, removed);
143 155
144 action->execute(context); 156 action->execute(context);
145 157
146 InspectorInstrumentation::didFireTimer(cookie); 158 InspectorInstrumentation::didFireTimer(cookie);
147 159
148 timerNestingLevel = 0; 160 timerNestingLevel = 0;
149 } 161 }
150 162
151 void DOMTimer::contextDestroyed() 163 void DOMTimer::contextDestroyed()
152 { 164 {
(...skipping 18 matching lines...) Expand all
171 return fireTime; 183 return fireTime;
172 184
173 double alignedTime = ceil(fireTime / alignmentInterval) * alignmentInter val; 185 double alignedTime = ceil(fireTime / alignmentInterval) * alignmentInter val;
174 return alignedTime; 186 return alignedTime;
175 } 187 }
176 188
177 return fireTime; 189 return fireTime;
178 } 190 }
179 191
180 } // namespace WebCore 192 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/DOMTimer.h ('k') | Source/core/page/DOMWindowTimers.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698