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

Unified Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 428473005: [XHR] Reduce 'readystatechange' event firing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/xml/XMLHttpRequest.cpp
diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
index 3e6bf6c9ed6e875d727eb210fdd20f233c178433..ea943c9983d1c5f9a5ccaa9f48e417af22f8de06 100644
--- a/Source/core/xml/XMLHttpRequest.cpp
+++ b/Source/core/xml/XMLHttpRequest.cpp
@@ -58,12 +58,20 @@
#include "wtf/ArrayBuffer.h"
#include "wtf/ArrayBufferView.h"
#include "wtf/Assertions.h"
+#include "wtf/CurrentTime.h"
#include "wtf/RefCountedLeakCounter.h"
#include "wtf/StdLibExtras.h"
#include "wtf/text/CString.h"
namespace blink {
+namespace {
+
+const double progressFireInterval = 0.05; // 0.05s
+const int progressFireMinimumSize = 1024 * 1024; // 1MB
+
+} // namespace
+
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XMLHttpRequest"));
struct XMLHttpRequestStaticData {
@@ -169,6 +177,8 @@ XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri
, m_progressEventThrottle(this)
, m_responseTypeCode(ResponseTypeDefault)
, m_securityOrigin(securityOrigin)
+ , m_previousProgressFireTime(0)
+ , m_previousProgressRemainLength(0)
, m_async(true)
, m_includeCredentials(false)
, m_createdDocument(false)
@@ -413,19 +423,26 @@ XMLHttpRequestUpload* XMLHttpRequest::upload()
void XMLHttpRequest::trackProgress(int length)
{
m_receivedLength += length;
+ double now = monotonicallyIncreasingTime();
+ bool shouldFire =
+ now - m_previousProgressFireTime >= progressFireInterval || m_previousProgressRemainLength + length >= progressFireMinimumSize;
tyoshino (SeeGerritForStatus) 2014/07/29 11:39:37 one line?
yhirano 2014/07/29 12:33:48 Done.
+ if (shouldFire) {
+ m_previousProgressFireTime = now;
+ m_previousProgressRemainLength = 0;
+ } else {
+ m_previousProgressRemainLength += length;
+ }
- if (m_async)
+ if (m_async && shouldFire)
dispatchProgressEventFromSnapshot(EventTypeNames::progress);
tyoshino (SeeGerritForStatus) 2014/07/29 11:39:37 progress events are already throttled. the algorit
yhirano 2014/07/29 12:33:48 Done. As discussed, we don't have to care about th
if (m_state != LOADING) {
changeState(LOADING);
} else {
- // Firefox calls readyStateChanged every time it receives data. Do
- // the same to align with Firefox.
- //
// FIXME: Make our implementation and the spec consistent. This
// behavior was needed when the progress event was not available.
- dispatchReadyStateChangeEvent();
+ if (shouldFire)
+ dispatchReadyStateChangeEvent();
}
}
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698