diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 22:56:33 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 22:56:33 +0000 |
commit | a187253e60e728614c730b7e568369d1bc1da07a (patch) | |
tree | 1619e254e0d30494147a633b43668234a90b60d4 /o3d | |
parent | cf8ebbba224c7d01170a46d81b3feda976298b67 (diff) | |
download | chromium_src-a187253e60e728614c730b7e568369d1bc1da07a.zip chromium_src-a187253e60e728614c730b7e568369d1bc1da07a.tar.gz chromium_src-a187253e60e728614c730b7e568369d1bc1da07a.tar.bz2 |
Fixed race condition in O3D/WebGL FileRequest implementation by only
initiating download upon send().
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2903002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51909 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/samples/o3d-webgl/file_request.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/o3d/samples/o3d-webgl/file_request.js b/o3d/samples/o3d-webgl/file_request.js index 164e184..d759613 100644 --- a/o3d/samples/o3d-webgl/file_request.js +++ b/o3d/samples/o3d-webgl/file_request.js @@ -58,6 +58,8 @@ * request.send(); */ o3d.FileRequest = function() { + this.method_ = ""; + this.async_ = true; this.request_ = new XMLHttpRequest(); var fileRequest = this; this.request_.onreadystatechange = function() { @@ -187,20 +189,8 @@ o3d.FileRequest.prototype.imageLoaded_ = function() { o3d.FileRequest.prototype.open = function(method, uri, async) { this.uri = uri; - // TODO(petersont): I think there is a race condition here -- calling - // code expects that it can still set up the onreadystatechange callback - // between open() and send(), but if open() actually initiates the XHR - // then the caller may miss the crucial completion callback! - if (this.isImageUrl_(uri)) { - this.image_ = new Image(); - var that = this; - this.image_.onload = function() { - that.imageLoaded_.call(that); - } - this.image_.src = uri; - } else { - this.request_.open(method, uri, async); - } + this.method_ = method; + this.async_ = async; }; @@ -210,7 +200,16 @@ o3d.FileRequest.prototype.open = * matter what, with success or failure. */ o3d.FileRequest.prototype.send = function() { - // This function left blank for compatability with o3djs.io. + if (this.isImageUrl_(this.uri)) { + this.image_ = new Image(); + var that = this; + this.image_.onload = function() { + that.imageLoaded_.call(that); + } + this.image_.src = this.uri; + } else { + this.request_.open(this.method_, this.uri, this.async_); + } }; |