Chromium Code Reviews

Side by Side 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, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « Source/core/xml/XMLHttpRequest.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) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 40 matching lines...)
51 #include "platform/SharedBuffer.h" 51 #include "platform/SharedBuffer.h"
52 #include "platform/blob/BlobData.h" 52 #include "platform/blob/BlobData.h"
53 #include "platform/network/HTTPParsers.h" 53 #include "platform/network/HTTPParsers.h"
54 #include "platform/network/ParsedContentType.h" 54 #include "platform/network/ParsedContentType.h"
55 #include "platform/network/ResourceError.h" 55 #include "platform/network/ResourceError.h"
56 #include "platform/network/ResourceRequest.h" 56 #include "platform/network/ResourceRequest.h"
57 #include "public/platform/WebURLRequest.h" 57 #include "public/platform/WebURLRequest.h"
58 #include "wtf/ArrayBuffer.h" 58 #include "wtf/ArrayBuffer.h"
59 #include "wtf/ArrayBufferView.h" 59 #include "wtf/ArrayBufferView.h"
60 #include "wtf/Assertions.h" 60 #include "wtf/Assertions.h"
61 #include "wtf/CurrentTime.h"
61 #include "wtf/RefCountedLeakCounter.h" 62 #include "wtf/RefCountedLeakCounter.h"
62 #include "wtf/StdLibExtras.h" 63 #include "wtf/StdLibExtras.h"
63 #include "wtf/text/CString.h" 64 #include "wtf/text/CString.h"
64 65
65 namespace blink { 66 namespace blink {
66 67
68 namespace {
69
70 const double readyStateChangeFireInterval = 0.05; // 0.05s
71
72 } // namespace
73
67 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XM LHttpRequest")); 74 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XM LHttpRequest"));
68 75
69 struct XMLHttpRequestStaticData { 76 struct XMLHttpRequestStaticData {
70 WTF_MAKE_NONCOPYABLE(XMLHttpRequestStaticData); WTF_MAKE_FAST_ALLOCATED; 77 WTF_MAKE_NONCOPYABLE(XMLHttpRequestStaticData); WTF_MAKE_FAST_ALLOCATED;
71 public: 78 public:
72 XMLHttpRequestStaticData(); 79 XMLHttpRequestStaticData();
73 String m_proxyHeaderPrefix; 80 String m_proxyHeaderPrefix;
74 String m_secHeaderPrefix; 81 String m_secHeaderPrefix;
75 HashSet<String, CaseFoldingHash> m_forbiddenRequestHeaders; 82 HashSet<String, CaseFoldingHash> m_forbiddenRequestHeaders;
76 }; 83 };
(...skipping 85 matching lines...)
162 : ActiveDOMObject(context) 169 : ActiveDOMObject(context)
163 , m_timeoutMilliseconds(0) 170 , m_timeoutMilliseconds(0)
164 , m_state(UNSENT) 171 , m_state(UNSENT)
165 , m_downloadedBlobLength(0) 172 , m_downloadedBlobLength(0)
166 , m_receivedLength(0) 173 , m_receivedLength(0)
167 , m_lastSendLineNumber(0) 174 , m_lastSendLineNumber(0)
168 , m_exceptionCode(0) 175 , m_exceptionCode(0)
169 , m_progressEventThrottle(this) 176 , m_progressEventThrottle(this)
170 , m_responseTypeCode(ResponseTypeDefault) 177 , m_responseTypeCode(ResponseTypeDefault)
171 , m_securityOrigin(securityOrigin) 178 , m_securityOrigin(securityOrigin)
179 , m_previousReadyStateChangeFireTime(0)
172 , m_async(true) 180 , m_async(true)
173 , m_includeCredentials(false) 181 , m_includeCredentials(false)
174 , m_createdDocument(false) 182 , m_createdDocument(false)
175 , m_error(false) 183 , m_error(false)
176 , m_uploadEventsAllowed(true) 184 , m_uploadEventsAllowed(true)
177 , m_uploadComplete(false) 185 , m_uploadComplete(false)
178 , m_sameOriginRequest(true) 186 , m_sameOriginRequest(true)
179 { 187 {
180 initializeXMLHttpRequestStaticData(); 188 initializeXMLHttpRequestStaticData();
181 #ifndef NDEBUG 189 #ifndef NDEBUG
(...skipping 231 matching lines...)
413 void XMLHttpRequest::trackProgress(int length) 421 void XMLHttpRequest::trackProgress(int length)
414 { 422 {
415 m_receivedLength += length; 423 m_receivedLength += length;
416 424
417 if (m_async) 425 if (m_async)
418 dispatchProgressEventFromSnapshot(EventTypeNames::progress); 426 dispatchProgressEventFromSnapshot(EventTypeNames::progress);
419 427
420 if (m_state != LOADING) { 428 if (m_state != LOADING) {
421 changeState(LOADING); 429 changeState(LOADING);
422 } else { 430 } else {
423 // Firefox calls readyStateChanged every time it receives data. Do
424 // the same to align with Firefox.
425 //
426 // FIXME: Make our implementation and the spec consistent. This 431 // FIXME: Make our implementation and the spec consistent. This
427 // behavior was needed when the progress event was not available. 432 // behavior was needed when the progress event was not available.
tyoshino (SeeGerritForStatus) 2014/07/30 08:44:07 Please replace "This behavior" with "This extra in
yhirano 2014/07/30 10:22:09 Done.
428 dispatchReadyStateChangeEvent(); 433 double now = monotonicallyIncreasingTime();
434 bool shouldFire = now - m_previousReadyStateChangeFireTime >= readyState ChangeFireInterval;
435 if (shouldFire) {
436 m_previousReadyStateChangeFireTime = now;
437 dispatchReadyStateChangeEvent();
438 }
429 } 439 }
430 } 440 }
431 441
432 void XMLHttpRequest::changeState(State newState) 442 void XMLHttpRequest::changeState(State newState)
433 { 443 {
434 if (m_state != newState) { 444 if (m_state != newState) {
435 m_state = newState; 445 m_state = newState;
436 dispatchReadyStateChangeEvent(); 446 dispatchReadyStateChangeEvent();
437 } 447 }
438 } 448 }
(...skipping 985 matching lines...)
1424 { 1434 {
1425 visitor->trace(m_responseBlob); 1435 visitor->trace(m_responseBlob);
1426 visitor->trace(m_responseStream); 1436 visitor->trace(m_responseStream);
1427 visitor->trace(m_responseDocument); 1437 visitor->trace(m_responseDocument);
1428 visitor->trace(m_progressEventThrottle); 1438 visitor->trace(m_progressEventThrottle);
1429 visitor->trace(m_upload); 1439 visitor->trace(m_upload);
1430 XMLHttpRequestEventTarget::trace(visitor); 1440 XMLHttpRequestEventTarget::trace(visitor);
1431 } 1441 }
1432 1442
1433 } // namespace blink 1443 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine