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

Unified Diff: Source/core/loader/DocumentThreadableLoader.cpp

Issue 273993002: Allow XHR timeout attribute to be overridden after send(), per spec (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Avoid potential race-condition between load and timeout Created 6 years, 7 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
Index: Source/core/loader/DocumentThreadableLoader.cpp
diff --git a/Source/core/loader/DocumentThreadableLoader.cpp b/Source/core/loader/DocumentThreadableLoader.cpp
index 2840dce77f4d9e26c4eae1e3c59f20864f715df6..2fc71d221bcf3bd031caa1e44570aab008536ffe 100644
--- a/Source/core/loader/DocumentThreadableLoader.cpp
+++ b/Source/core/loader/DocumentThreadableLoader.cpp
@@ -76,11 +76,14 @@ DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl
, m_simpleRequest(true)
, m_async(blockingBehavior == LoadAsynchronously)
, m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout)
+ , m_requestStarted(0.0)
{
ASSERT(client);
// Setting an outgoing referer is only supported in the async code path.
ASSERT(m_async || request.httpReferrer().isEmpty());
+ m_requestStarted = monotonicallyIncreasingTime();
+
// Save any CORS simple headers on the request here. If this request redirects cross-origin, we cancel the old request
// create a new one, and copy these headers.
const HTTPHeaderMap& headerMap = request.httpHeaderFields();
@@ -138,6 +141,26 @@ DocumentThreadableLoader::~DocumentThreadableLoader()
{
}
+void DocumentThreadableLoader::overrideTimeout(unsigned long timeoutMilliseconds)
+{
+ if (!m_async)
+ return;
+ m_timeoutTimer.stop();
+ // At the time of this method's implementation, it is only ever called by
+ // XMLHttpRequest, when the timeout attribute is set after sending the
+ // request.
+ //
+ // The XHR request says to resolve the time relative to when the request
+ // was initially sent, however other uses of this method may need to
+ // behave differently, in which case this should be re-arranged somehow.
+ if (timeoutMilliseconds && m_requestStarted > 0.0) {
+ double elapsedTime = monotonicallyIncreasingTime() - m_requestStarted;
+ double nextFire = timeoutMilliseconds / 1000.0;
+ double resolvedTime = nextFire > elapsedTime ? nextFire - elapsedTime : 0.0;
eseidel 2014/05/21 21:41:50 std:min(nextfire - elapsedTime, 0) may be simpler.
+ m_timeoutTimer.startOneShot(resolvedTime, FROM_HERE);
+ }
+}
+
void DocumentThreadableLoader::cancel()
{
cancelWithError(ResourceError());
@@ -159,6 +182,7 @@ void DocumentThreadableLoader::cancelWithError(const ResourceError& error)
}
clearResource();
m_client = 0;
+ m_requestStarted = 0.0;
}
void DocumentThreadableLoader::setDefersLoading(bool value)
@@ -337,6 +361,8 @@ void DocumentThreadableLoader::notifyFinished(Resource* resource)
m_client->didFail(resource->resourceError());
else
didFinishLoading(resource->identifier(), resource->loadFinishTime());
+
+ m_requestStarted = 0.0;
tyoshino (SeeGerritForStatus) 2014/05/28 02:21:26 not here. see below
}
void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double finishTime)

Powered by Google App Engine
This is Rietveld 408576698