OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> All right reserv ed. | 2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> All right reserv ed. |
3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "core/EventTypeNames.h" | 29 #include "core/EventTypeNames.h" |
30 #include "core/events/ProgressEvent.h" | 30 #include "core/events/ProgressEvent.h" |
31 #include "core/inspector/InspectorInstrumentation.h" | 31 #include "core/inspector/InspectorInstrumentation.h" |
32 #include "core/inspector/InspectorTraceEvents.h" | 32 #include "core/inspector/InspectorTraceEvents.h" |
33 #include "core/xmlhttprequest/XMLHttpRequest.h" | 33 #include "core/xmlhttprequest/XMLHttpRequest.h" |
34 #include "wtf/Assertions.h" | 34 #include "wtf/Assertions.h" |
35 #include "wtf/text/AtomicString.h" | 35 #include "wtf/text/AtomicString.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 static const double kMinimumProgressEventDispatchingIntervalInSeconds = .05; // 50 ms per specification. | |
yhirano
2016/03/01 17:43:54
I generally prefer an unnamed namespace to static.
| |
40 | |
39 XMLHttpRequestProgressEventThrottle::DeferredEvent::DeferredEvent() | 41 XMLHttpRequestProgressEventThrottle::DeferredEvent::DeferredEvent() |
40 { | 42 { |
41 clear(); | 43 clear(); |
42 } | 44 } |
43 | 45 |
44 void XMLHttpRequestProgressEventThrottle::DeferredEvent::set(bool lengthComputab le, unsigned long long loaded, unsigned long long total) | 46 void XMLHttpRequestProgressEventThrottle::DeferredEvent::set(bool lengthComputab le, unsigned long long loaded, unsigned long long total) |
45 { | 47 { |
46 m_isSet = true; | 48 m_isSet = true; |
47 | 49 |
48 m_lengthComputable = lengthComputable; | 50 m_lengthComputable = lengthComputable; |
(...skipping 12 matching lines...) Expand all Loading... | |
61 | 63 |
62 PassRefPtrWillBeRawPtr<Event> XMLHttpRequestProgressEventThrottle::DeferredEvent ::take() | 64 PassRefPtrWillBeRawPtr<Event> XMLHttpRequestProgressEventThrottle::DeferredEvent ::take() |
63 { | 65 { |
64 ASSERT(m_isSet); | 66 ASSERT(m_isSet); |
65 | 67 |
66 RefPtrWillBeRawPtr<Event> event = ProgressEvent::create(EventTypeNames::prog ress, m_lengthComputable, m_loaded, m_total); | 68 RefPtrWillBeRawPtr<Event> event = ProgressEvent::create(EventTypeNames::prog ress, m_lengthComputable, m_loaded, m_total); |
67 clear(); | 69 clear(); |
68 return event.release(); | 70 return event.release(); |
69 } | 71 } |
70 | 72 |
71 const double XMLHttpRequestProgressEventThrottle::minimumProgressEventDispatchin gIntervalInSeconds = .05; // 50 ms per specification. | |
72 | |
73 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(XMLHttp Request* target) | 73 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(XMLHttp Request* target) |
74 : m_target(target) | 74 : m_target(target) |
75 , m_hasDispatchedProgressProgressEvent(false) | 75 , m_hasDispatchedProgressProgressEvent(false) |
76 { | 76 { |
77 ASSERT(target); | 77 ASSERT(target); |
78 } | 78 } |
79 | 79 |
80 XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle() | 80 XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle() |
81 { | 81 { |
82 } | 82 } |
83 | 83 |
84 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicStri ng& type, bool lengthComputable, unsigned long long loaded, unsigned long long t otal) | 84 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicStri ng& type, bool lengthComputable, unsigned long long loaded, unsigned long long t otal) |
85 { | 85 { |
86 // Given that ResourceDispatcher doesn't deliver an event when suspended, | 86 // Given that ResourceDispatcher doesn't deliver an event when suspended, |
87 // we don't have to worry about event dispatching while suspended. | 87 // we don't have to worry about event dispatching while suspended. |
88 if (type != EventTypeNames::progress) { | 88 if (type != EventTypeNames::progress) { |
89 m_target->dispatchEvent(ProgressEvent::create(type, lengthComputable, lo aded, total)); | 89 m_target->dispatchEvent(ProgressEvent::create(type, lengthComputable, lo aded, total)); |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 if (isActive()) { | 93 if (isActive()) { |
94 m_deferred.set(lengthComputable, loaded, total); | 94 m_deferred.set(lengthComputable, loaded, total); |
95 } else { | 95 } else { |
96 dispatchProgressProgressEvent(ProgressEvent::create(EventTypeNames::prog ress, lengthComputable, loaded, total)); | 96 dispatchProgressProgressEvent(ProgressEvent::create(EventTypeNames::prog ress, lengthComputable, loaded, total)); |
97 startOneShot(minimumProgressEventDispatchingIntervalInSeconds, BLINK_FRO M_HERE); | 97 startOneShot(kMinimumProgressEventDispatchingIntervalInSeconds, BLINK_FR OM_HERE); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP trWillBeRawPtr<Event> event, DeferredEventAction action) | 101 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP trWillBeRawPtr<Event> event, DeferredEventAction action) |
102 { | 102 { |
103 XMLHttpRequest::State state = m_target->readyState(); | 103 XMLHttpRequest::State state = m_target->readyState(); |
104 // Given that ResourceDispatcher doesn't deliver an event when suspended, | 104 // Given that ResourceDispatcher doesn't deliver an event when suspended, |
105 // we don't have to worry about event dispatching while suspended. | 105 // we don't have to worry about event dispatching while suspended. |
106 if (action == Flush) { | 106 if (action == Flush) { |
107 if (m_deferred.isSet()) | 107 if (m_deferred.isSet()) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 { | 143 { |
144 if (!m_deferred.isSet()) { | 144 if (!m_deferred.isSet()) { |
145 // No "progress" event was queued since the previous dispatch, we can | 145 // No "progress" event was queued since the previous dispatch, we can |
146 // safely stop the timer. | 146 // safely stop the timer. |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 dispatchProgressProgressEvent(m_deferred.take()); | 150 dispatchProgressProgressEvent(m_deferred.take()); |
151 | 151 |
152 // Watch if another "progress" ProgressEvent arrives in the next 50ms. | 152 // Watch if another "progress" ProgressEvent arrives in the next 50ms. |
153 startOneShot(minimumProgressEventDispatchingIntervalInSeconds, BLINK_FROM_HE RE); | 153 startOneShot(kMinimumProgressEventDispatchingIntervalInSeconds, BLINK_FROM_H ERE); |
154 } | 154 } |
155 | 155 |
156 void XMLHttpRequestProgressEventThrottle::suspend() | 156 void XMLHttpRequestProgressEventThrottle::suspend() |
157 { | 157 { |
158 stop(); | 158 stop(); |
159 } | 159 } |
160 | 160 |
161 void XMLHttpRequestProgressEventThrottle::resume() | 161 void XMLHttpRequestProgressEventThrottle::resume() |
162 { | 162 { |
163 if (!m_deferred.isSet()) | 163 if (!m_deferred.isSet()) |
164 return; | 164 return; |
165 | 165 |
166 // Do not dispatch events inline here, since ExecutionContext is iterating | 166 // Do not dispatch events inline here, since ExecutionContext is iterating |
167 // over the list of active DOM objects to resume them, and any activated JS | 167 // over the list of active DOM objects to resume them, and any activated JS |
168 // event-handler could insert new active DOM objects to the list. | 168 // event-handler could insert new active DOM objects to the list. |
169 startOneShot(0, BLINK_FROM_HERE); | 169 startOneShot(0, BLINK_FROM_HERE); |
170 } | 170 } |
171 | 171 |
172 DEFINE_TRACE(XMLHttpRequestProgressEventThrottle) | 172 DEFINE_TRACE(XMLHttpRequestProgressEventThrottle) |
173 { | 173 { |
174 visitor->trace(m_target); | 174 visitor->trace(m_target); |
175 } | 175 } |
176 | 176 |
177 } // namespace blink | 177 } // namespace blink |
OLD | NEW |