| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 28 #include "sky/engine/core/frame/DOMTimer.h" | 28 #include "sky/engine/core/frame/DOMTimer.h" |
| 29 | 29 |
| 30 #include "sky/engine/core/dom/ExecutionContext.h" | 30 #include "sky/engine/core/dom/ExecutionContext.h" |
| 31 #include "sky/engine/core/inspector/InspectorTraceEvents.h" | 31 #include "sky/engine/core/inspector/InspectorTraceEvents.h" |
| 32 #include "sky/engine/platform/Logging.h" | 32 #include "sky/engine/platform/Logging.h" |
| 33 #include "sky/engine/platform/TraceEvent.h" | 33 #include "sky/engine/platform/TraceEvent.h" |
| 34 #include "sky/engine/wtf/CurrentTime.h" | 34 #include "sky/engine/wtf/CurrentTime.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 static const int maxIntervalForUserGestureForwarding = 1000; // One second match
es Gecko. | |
| 39 static const int maxTimerNestingLevel = 5; | 38 static const int maxTimerNestingLevel = 5; |
| 40 static const double oneMillisecond = 0.001; | 39 static const double oneMillisecond = 0.001; |
| 41 // Chromium uses a minimum timer interval of 4ms. We'd like to go | 40 // Chromium uses a minimum timer interval of 4ms. We'd like to go |
| 42 // lower; however, there are poorly coded websites out there which do | 41 // lower; however, there are poorly coded websites out there which do |
| 43 // create CPU-spinning loops. Using 4ms prevents the CPU from | 42 // create CPU-spinning loops. Using 4ms prevents the CPU from |
| 44 // spinning too busily and provides a balance between CPU spinning and | 43 // spinning too busily and provides a balance between CPU spinning and |
| 45 // the smallest possible interval timer. | 44 // the smallest possible interval timer. |
| 46 static const double minimumInterval = 0.004; | 45 static const double minimumInterval = 0.004; |
| 47 | 46 |
| 48 static int timerNestingLevel = 0; | 47 static int timerNestingLevel = 0; |
| 49 | 48 |
| 50 static inline bool shouldForwardUserGesture(int interval, int nestingLevel) | |
| 51 { | |
| 52 return UserGestureIndicator::processingUserGesture() | |
| 53 && interval <= maxIntervalForUserGestureForwarding | |
| 54 && nestingLevel == 1; // Gestures should not be forwarded to nested time
rs. | |
| 55 } | |
| 56 | |
| 57 double DOMTimer::hiddenPageAlignmentInterval() | 49 double DOMTimer::hiddenPageAlignmentInterval() |
| 58 { | 50 { |
| 59 // Timers on hidden pages are aligned so that they fire once per | 51 // Timers on hidden pages are aligned so that they fire once per |
| 60 // second at most. | 52 // second at most. |
| 61 return 1.0; | 53 return 1.0; |
| 62 } | 54 } |
| 63 | 55 |
| 64 double DOMTimer::visiblePageAlignmentInterval() | 56 double DOMTimer::visiblePageAlignmentInterval() |
| 65 { | 57 { |
| 66 // Alignment does not apply to timers on visible pages. | 58 // Alignment does not apply to timers on visible pages. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", TRACE_EVENT_SCOPE_PROCESS, "stack", InspectorCallStackEvent::current
CallStack()); | 76 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", TRACE_EVENT_SCOPE_PROCESS, "stack", InspectorCallStackEvent::current
CallStack()); |
| 85 } | 77 } |
| 86 | 78 |
| 87 DOMTimer::DOMTimer(ExecutionContext* context, PassOwnPtr<ScheduledAction> action
, int interval, bool singleShot, int timeoutID) | 79 DOMTimer::DOMTimer(ExecutionContext* context, PassOwnPtr<ScheduledAction> action
, int interval, bool singleShot, int timeoutID) |
| 88 : SuspendableTimer(context) | 80 : SuspendableTimer(context) |
| 89 , m_timeoutID(timeoutID) | 81 , m_timeoutID(timeoutID) |
| 90 , m_nestingLevel(timerNestingLevel + 1) | 82 , m_nestingLevel(timerNestingLevel + 1) |
| 91 , m_action(action) | 83 , m_action(action) |
| 92 { | 84 { |
| 93 ASSERT(timeoutID > 0); | 85 ASSERT(timeoutID > 0); |
| 94 if (shouldForwardUserGesture(interval, m_nestingLevel)) | |
| 95 m_userGestureToken = UserGestureIndicator::currentToken(); | |
| 96 | 86 |
| 97 double intervalMilliseconds = std::max(oneMillisecond, interval * oneMillise
cond); | 87 double intervalMilliseconds = std::max(oneMillisecond, interval * oneMillise
cond); |
| 98 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest
ingLevel) | 88 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest
ingLevel) |
| 99 intervalMilliseconds = minimumInterval; | 89 intervalMilliseconds = minimumInterval; |
| 100 if (singleShot) | 90 if (singleShot) |
| 101 startOneShot(intervalMilliseconds, FROM_HERE); | 91 startOneShot(intervalMilliseconds, FROM_HERE); |
| 102 else | 92 else |
| 103 startRepeating(intervalMilliseconds, FROM_HERE); | 93 startRepeating(intervalMilliseconds, FROM_HERE); |
| 104 } | 94 } |
| 105 | 95 |
| 106 DOMTimer::~DOMTimer() | 96 DOMTimer::~DOMTimer() |
| 107 { | 97 { |
| 108 } | 98 } |
| 109 | 99 |
| 110 int DOMTimer::timeoutID() const | 100 int DOMTimer::timeoutID() const |
| 111 { | 101 { |
| 112 return m_timeoutID; | 102 return m_timeoutID; |
| 113 } | 103 } |
| 114 | 104 |
| 115 void DOMTimer::fired() | 105 void DOMTimer::fired() |
| 116 { | 106 { |
| 117 ExecutionContext* context = executionContext(); | 107 ExecutionContext* context = executionContext(); |
| 118 timerNestingLevel = m_nestingLevel; | 108 timerNestingLevel = m_nestingLevel; |
| 119 ASSERT(!context->activeDOMObjectsAreSuspended()); | 109 ASSERT(!context->activeDOMObjectsAreSuspended()); |
| 120 // Only the first execution of a multi-shot timer should get an affirmative
user gesture indicator. | |
| 121 UserGestureIndicator gestureIndicator(m_userGestureToken.release()); | |
| 122 | 110 |
| 123 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "TimerFire", "d
ata", InspectorTimerFireEvent::data(context, m_timeoutID)); | 111 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "TimerFire", "d
ata", InspectorTimerFireEvent::data(context, m_timeoutID)); |
| 124 | 112 |
| 125 // Simple case for non-one-shot timers. | 113 // Simple case for non-one-shot timers. |
| 126 if (isActive()) { | 114 if (isActive()) { |
| 127 if (repeatInterval() && repeatInterval() < minimumInterval) { | 115 if (repeatInterval() && repeatInterval() < minimumInterval) { |
| 128 m_nestingLevel++; | 116 m_nestingLevel++; |
| 129 if (m_nestingLevel >= maxTimerNestingLevel) | 117 if (m_nestingLevel >= maxTimerNestingLevel) |
| 130 augmentRepeatInterval(minimumInterval - repeatInterval()); | 118 augmentRepeatInterval(minimumInterval - repeatInterval()); |
| 131 } | 119 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (fireTime - alignedTimeRoundedDown < minimumInterval) | 184 if (fireTime - alignedTimeRoundedDown < minimumInterval) |
| 197 return alignedTimeRoundedDown; | 185 return alignedTimeRoundedDown; |
| 198 | 186 |
| 199 return alignedTimeRoundedUp; | 187 return alignedTimeRoundedUp; |
| 200 } | 188 } |
| 201 | 189 |
| 202 return fireTime; | 190 return fireTime; |
| 203 } | 191 } |
| 204 | 192 |
| 205 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |