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

Side by Side Diff: third_party/WebKit/Source/core/xmlhttprequest/ProgressEventThrottle.cpp

Issue 1690503002: Rename XMLHttpRequestProgressEventThrottle to ProgressEventThrottle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
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
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h" 27 #include "core/xmlhttprequest/ProgressEventThrottle.h"
28 28
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 XMLHttpRequestProgressEventThrottle::DeferredEvent::DeferredEvent() 39 ProgressEventThrottle::DeferredEvent::DeferredEvent()
40 { 40 {
41 clear(); 41 clear();
42 } 42 }
43 43
44 void XMLHttpRequestProgressEventThrottle::DeferredEvent::set(bool lengthComputab le, unsigned long long loaded, unsigned long long total) 44 void ProgressEventThrottle::DeferredEvent::set(bool lengthComputable, unsigned l ong long loaded, unsigned long long total)
45 { 45 {
46 m_isSet = true; 46 m_isSet = true;
47 47
48 m_lengthComputable = lengthComputable; 48 m_lengthComputable = lengthComputable;
49 m_loaded = loaded; 49 m_loaded = loaded;
50 m_total = total; 50 m_total = total;
51 } 51 }
52 52
53 void XMLHttpRequestProgressEventThrottle::DeferredEvent::clear() 53 void ProgressEventThrottle::DeferredEvent::clear()
54 { 54 {
55 m_isSet = false; 55 m_isSet = false;
56 56
57 m_lengthComputable = false; 57 m_lengthComputable = false;
58 m_loaded = 0; 58 m_loaded = 0;
59 m_total = 0; 59 m_total = 0;
60 } 60 }
61 61
62 PassRefPtrWillBeRawPtr<Event> XMLHttpRequestProgressEventThrottle::DeferredEvent ::take() 62 PassRefPtrWillBeRawPtr<Event> ProgressEventThrottle::DeferredEvent::take()
63 { 63 {
64 ASSERT(m_isSet); 64 ASSERT(m_isSet);
65 65
66 RefPtrWillBeRawPtr<Event> event = ProgressEvent::create(EventTypeNames::prog ress, m_lengthComputable, m_loaded, m_total); 66 RefPtrWillBeRawPtr<Event> event = ProgressEvent::create(EventTypeNames::prog ress, m_lengthComputable, m_loaded, m_total);
67 clear(); 67 clear();
68 return event.release(); 68 return event.release();
69 } 69 }
70 70
71 const double XMLHttpRequestProgressEventThrottle::minimumProgressEventDispatchin gIntervalInSeconds = .05; // 50 ms per specification. 71 const double ProgressEventThrottle::minimumProgressEventDispatchingIntervalInSec onds = .05; // 50 ms per specification.
72 72
73 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(XMLHttp Request* target) 73 ProgressEventThrottle::ProgressEventThrottle(XMLHttpRequest* 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 ProgressEventThrottle::~ProgressEventThrottle()
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 ProgressEventThrottle::dispatchProgressEvent(const AtomicString& type, bool lengthComputable, unsigned long long loaded, unsigned long long total)
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(minimumProgressEventDispatchingIntervalInSeconds, BLINK_FRO M_HERE);
98 } 98 }
99 } 99 }
100 100
101 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP trWillBeRawPtr<Event> event, DeferredEventAction action) 101 void ProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefPtrWillBeRawPtr <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())
108 dispatchProgressProgressEvent(m_deferred.take()); 108 dispatchProgressProgressEvent(m_deferred.take());
109 109
110 stop(); 110 stop();
111 } else if (action == Clear) { 111 } else if (action == Clear) {
112 m_deferred.clear(); 112 m_deferred.clear();
113 stop(); 113 stop();
114 } 114 }
115 115
116 m_hasDispatchedProgressProgressEvent = false; 116 m_hasDispatchedProgressProgressEvent = false;
117 if (state == m_target->readyState()) { 117 if (state == m_target->readyState()) {
118 // We don't dispatch the event when an event handler associated with 118 // We don't dispatch the event when an event handler associated with
119 // the previously dispatched event changes the readyState (e.g. when 119 // the previously dispatched event changes the readyState (e.g. when
120 // the event handler calls xhr.abort()). In such cases a 120 // the event handler calls xhr.abort()). In such cases a
121 // readystatechange should have been already dispatched if necessary. 121 // readystatechange should have been already dispatched if necessary.
122 m_target->dispatchEvent(event); 122 m_target->dispatchEvent(event);
123 } 123 }
124 } 124 }
125 125
126 void XMLHttpRequestProgressEventThrottle::dispatchProgressProgressEvent(PassRefP trWillBeRawPtr<Event> progressEvent) 126 void ProgressEventThrottle::dispatchProgressProgressEvent(PassRefPtrWillBeRawPtr <Event> progressEvent)
127 { 127 {
128 XMLHttpRequest::State state = m_target->readyState(); 128 XMLHttpRequest::State state = m_target->readyState();
129 if (m_target->readyState() == XMLHttpRequest::LOADING && m_hasDispatchedProg ressProgressEvent) { 129 if (m_target->readyState() == XMLHttpRequest::LOADING && m_hasDispatchedProg ressProgressEvent) {
130 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(m_target->executionContext(), m_target)); 130 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(m_target->executionContext(), m_target));
131 m_target->dispatchEvent(Event::create(EventTypeNames::readystatechange)) ; 131 m_target->dispatchEvent(Event::create(EventTypeNames::readystatechange)) ;
132 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata()); 132 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata());
133 } 133 }
134 134
135 if (m_target->readyState() != state) 135 if (m_target->readyState() != state)
136 return; 136 return;
137 137
138 m_hasDispatchedProgressProgressEvent = true; 138 m_hasDispatchedProgressProgressEvent = true;
139 m_target->dispatchEvent(progressEvent); 139 m_target->dispatchEvent(progressEvent);
140 } 140 }
141 141
142 void XMLHttpRequestProgressEventThrottle::fired() 142 void ProgressEventThrottle::fired()
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(minimumProgressEventDispatchingIntervalInSeconds, BLINK_FROM_HE RE);
154 } 154 }
155 155
156 void XMLHttpRequestProgressEventThrottle::suspend() 156 void ProgressEventThrottle::suspend()
157 { 157 {
158 stop(); 158 stop();
159 } 159 }
160 160
161 void XMLHttpRequestProgressEventThrottle::resume() 161 void ProgressEventThrottle::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(ProgressEventThrottle)
173 { 173 {
174 visitor->trace(m_target); 174 visitor->trace(m_target);
175 } 175 }
176 176
177 } // namespace blink 177 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698