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

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

Issue 1455513002: [XHR] Decrease readyStateChange event dispatching during loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h ('k') | no next file » | 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) 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 10 matching lines...) Expand all
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 "config.h" 27 #include "config.h"
28 #include "core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h" 28 #include "core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h"
29 29
30 #include "core/EventTypeNames.h" 30 #include "core/EventTypeNames.h"
31 #include "core/inspector/InspectorInstrumentation.h"
32 #include "core/inspector/InspectorTraceEvents.h"
31 #include "core/xmlhttprequest/XMLHttpRequest.h" 33 #include "core/xmlhttprequest/XMLHttpRequest.h"
32 #include "core/xmlhttprequest/XMLHttpRequestProgressEvent.h" 34 #include "core/xmlhttprequest/XMLHttpRequestProgressEvent.h"
33 #include "wtf/Assertions.h" 35 #include "wtf/Assertions.h"
34 #include "wtf/text/AtomicString.h" 36 #include "wtf/text/AtomicString.h"
35 37
36 namespace blink { 38 namespace blink {
37 39
38 class XMLHttpRequestProgressEventThrottle::DeferredEvent { 40 class XMLHttpRequestProgressEventThrottle::DeferredEvent {
39 public: 41 public:
40 DeferredEvent() { clear(); } 42 DeferredEvent() { clear(); }
(...skipping 21 matching lines...) Expand all
62 unsigned long long m_total; 64 unsigned long long m_total;
63 bool m_isDeferred; 65 bool m_isDeferred;
64 bool m_lengthComputable; 66 bool m_lengthComputable;
65 }; 67 };
66 68
67 const double XMLHttpRequestProgressEventThrottle::minimumProgressEventDispatchin gIntervalInSeconds = .05; // 50 ms per specification. 69 const double XMLHttpRequestProgressEventThrottle::minimumProgressEventDispatchin gIntervalInSeconds = .05; // 50 ms per specification.
68 70
69 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(XMLHttp Request* target) 71 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(XMLHttp Request* target)
70 : m_target(target) 72 : m_target(target)
71 , m_deferred(adoptPtr(new DeferredEvent)) 73 , m_deferred(adoptPtr(new DeferredEvent))
74 , m_hasDispatchedProgressProgressEvent(false)
72 { 75 {
73 ASSERT(target); 76 ASSERT(target);
74 } 77 }
75 78
76 XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle() 79 XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle()
77 { 80 {
78 } 81 }
79 82
80 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicStri ng& type, bool lengthComputable, unsigned long long loaded, unsigned long long t otal) 83 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicStri ng& type, bool lengthComputable, unsigned long long loaded, unsigned long long t otal)
81 { 84 {
82 // Given that ResourceDispatcher doesn't deliver an event when suspended, 85 // Given that ResourceDispatcher doesn't deliver an event when suspended,
83 // we don't have to worry about event dispatching while suspended. 86 // we don't have to worry about event dispatching while suspended.
84 if (type != EventTypeNames::progress) { 87 if (type != EventTypeNames::progress) {
85 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length Computable, loaded, total)); 88 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length Computable, loaded, total));
86 return; 89 return;
87 } 90 }
88 91
89 if (isActive()) { 92 if (isActive()) {
90 m_deferred->set(lengthComputable, loaded, total); 93 m_deferred->set(lengthComputable, loaded, total);
91 } else { 94 } else {
92 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length Computable, loaded, total)); 95 dispatchProgressProgressEvent(lengthComputable, loaded, total);
93 startOneShot(minimumProgressEventDispatchingIntervalInSeconds, BLINK_FRO M_HERE); 96 startOneShot(minimumProgressEventDispatchingIntervalInSeconds, BLINK_FRO M_HERE);
94 } 97 }
95 } 98 }
96 99
97 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP trWillBeRawPtr<Event> event, DeferredEventAction action) 100 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP trWillBeRawPtr<Event> event, DeferredEventAction action)
98 { 101 {
99 XMLHttpRequest::State state = m_target->readyState(); 102 XMLHttpRequest::State state = m_target->readyState();
100 // Given that ResourceDispatcher doesn't deliver an event when suspended, 103 // Given that ResourceDispatcher doesn't deliver an event when suspended,
101 // we don't have to worry about event dispatching while suspended. 104 // we don't have to worry about event dispatching while suspended.
102 if (action == Flush) { 105 if (action == Flush) {
103 dispatchDeferredEvent(); 106 dispatchDeferredEvent();
104 // |m_target| is protected by the caller.
105 stop(); 107 stop();
106 } else if (action == Clear) { 108 } else if (action == Clear) {
107 m_deferred->clear(); 109 m_deferred->clear();
108 stop(); 110 stop();
109 } 111 }
110 112
113 m_hasDispatchedProgressProgressEvent = false;
111 if (state == m_target->readyState()) { 114 if (state == m_target->readyState()) {
112 // We don't dispatch the event when an event handler associated with 115 // We don't dispatch the event when an event handler associated with
113 // the previously dispatched event changes the readyState (e.g. when 116 // the previously dispatched event changes the readyState (e.g. when
114 // the event handler calls xhr.abort()). In such cases a 117 // the event handler calls xhr.abort()). In such cases a
115 // readystatechange should have been already dispatched if necessary. 118 // readystatechange should have been already dispatched if necessary.
116 m_target->dispatchEvent(event); 119 m_target->dispatchEvent(event);
117 } 120 }
118 } 121 }
119 122
123 void XMLHttpRequestProgressEventThrottle::dispatchProgressProgressEvent(bool len gthComputable, unsigned long long loaded, unsigned long long total)
124 {
tyoshino (SeeGerritForStatus) 2015/11/26 07:04:13 are we sure that we can omit "if (!executionContex
yhirano 2015/11/26 11:36:32 I'm not sure what the block is for. I added a |sto
125 XMLHttpRequest::State state = m_target->readyState();
126 if (m_target->readyState() == XMLHttpRequest::LOADING && m_hasDispatchedProg ressProgressEvent) {
127 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(m_target->executionContext(), m_target));
128 m_target->dispatchEvent(Event::create(EventTypeNames::readystatechange)) ;
129 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata());
130 }
131
132 if (m_target->readyState() != state)
133 return;
134
135 m_hasDispatchedProgressProgressEvent = true;
136 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames:: progress, lengthComputable, loaded, total));
137 }
138
120 void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvent() 139 void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvent()
121 { 140 {
122 if (m_deferred->isDeferred()) { 141 if (m_deferred->isDeferred()) {
123 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNam es::progress, m_deferred->lengthComputable(), m_deferred->loaded(), m_deferred-> total())); 142 dispatchProgressProgressEvent(m_deferred->lengthComputable(), m_deferred ->loaded(), m_deferred->total());
124 m_deferred->clear(); 143 m_deferred->clear();
125 } 144 }
126 } 145 }
127 146
128 void XMLHttpRequestProgressEventThrottle::fired() 147 void XMLHttpRequestProgressEventThrottle::fired()
129 { 148 {
130 if (!m_deferred->isDeferred()) { 149 if (!m_deferred->isDeferred()) {
131 // No "progress" event was queued since the previous dispatch, we can 150 // No "progress" event was queued since the previous dispatch, we can
132 // safely stop the timer. 151 // safely stop the timer.
133 return; 152 return;
(...skipping 20 matching lines...) Expand all
154 // event-handler could insert new active DOM objects to the list. 173 // event-handler could insert new active DOM objects to the list.
155 startOneShot(0, BLINK_FROM_HERE); 174 startOneShot(0, BLINK_FROM_HERE);
156 } 175 }
157 176
158 DEFINE_TRACE(XMLHttpRequestProgressEventThrottle) 177 DEFINE_TRACE(XMLHttpRequestProgressEventThrottle)
159 { 178 {
160 visitor->trace(m_target); 179 visitor->trace(m_target);
161 } 180 }
162 181
163 } // namespace blink 182 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698