diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-09 20:03:42 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-09 20:03:42 +0000 |
commit | 7794bb39fd44344e1b2d91aea29d119500e9a9ae (patch) | |
tree | 589ed4aa612b7f8b6fae1c94fc91534dbe687fd8 /webkit | |
parent | a98e945abdfd58229e90f2cbfb8b2ec4173f4b0d (diff) | |
download | chromium_src-7794bb39fd44344e1b2d91aea29d119500e9a9ae.zip chromium_src-7794bb39fd44344e1b2d91aea29d119500e9a9ae.tar.gz chromium_src-7794bb39fd44344e1b2d91aea29d119500e9a9ae.tar.bz2 |
Fix BufferedResourceLoader to immediately return a read error if the underlying connection failed.
Previously we would either return a cache miss or a read failure based on whether a read was pending.
BUG=127248
TEST=play a video over the network, disconnect ethernet/wifi and notice that we error immediately
Review URL: https://chromiumcodereview.appspot.com/10375061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/media/buffered_resource_loader.cc | 10 | ||||
-rw-r--r-- | webkit/media/buffered_resource_loader.h | 4 | ||||
-rw-r--r-- | webkit/media/buffered_resource_loader_unittest.cc | 24 |
3 files changed, 37 insertions, 1 deletions
diff --git a/webkit/media/buffered_resource_loader.cc b/webkit/media/buffered_resource_loader.cc index ec3347f..1a78aac 100644 --- a/webkit/media/buffered_resource_loader.cc +++ b/webkit/media/buffered_resource_loader.cc @@ -109,7 +109,8 @@ BufferedResourceLoader::BufferedResourceLoader( int bitrate, float playback_rate, media::MediaLog* media_log) - : defer_strategy_(strategy), + : loader_failed_(false), + defer_strategy_(strategy), range_supported_(false), saved_forward_capacity_(0), url_(url), @@ -228,6 +229,12 @@ void BufferedResourceLoader::Read( read_size_ = read_size; read_buffer_ = buffer; + // Reads should immediately fail if the loader also failed. + if (loader_failed_) { + DoneRead(kFailed, 0); + return; + } + // If we're attempting to read past the end of the file, return a zero // indicating EOF. // @@ -526,6 +533,7 @@ void BufferedResourceLoader::didFail( // // Keep it alive until we exit this method so that |error| remains valid. scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); + loader_failed_ = true; NotifyNetworkEvent(); // Don't leave start callbacks hanging around. diff --git a/webkit/media/buffered_resource_loader.h b/webkit/media/buffered_resource_loader.h index a0417e5..9186514 100644 --- a/webkit/media/buffered_resource_loader.h +++ b/webkit/media/buffered_resource_loader.h @@ -259,6 +259,10 @@ class BufferedResourceLoader : public WebKit::WebURLLoaderClient { // Keeps track of an active WebURLLoader and associated state. scoped_ptr<ActiveLoader> active_loader_; + // Tracks if |active_loader_| failed. If so, then all calls to Read() will + // fail. + bool loader_failed_; + // Current buffering algorithm in place for resource loading. DeferStrategy defer_strategy_; diff --git a/webkit/media/buffered_resource_loader_unittest.cc b/webkit/media/buffered_resource_loader_unittest.cc index ab82be4..7769ca5 100644 --- a/webkit/media/buffered_resource_loader_unittest.cc +++ b/webkit/media/buffered_resource_loader_unittest.cc @@ -542,6 +542,30 @@ TEST_F(BufferedResourceLoaderTest, RequestFailedWhenRead) { loader_->didFail(url_loader_, error); } +TEST_F(BufferedResourceLoaderTest, RequestFailedWithNoPendingReads) { + Initialize(kHttpUrl, 10, 29); + Start(); + PartialResponse(10, 29, 30); + + uint8 buffer[10]; + InSequence s; + + // Write enough data so that a read would technically complete had the request + // not failed. + WriteLoader(10, 20); + + // Fail without a pending read. + WebURLError error; + error.reason = net::ERR_TIMED_OUT; + error.isCancellation = false; + EXPECT_CALL(*this, NetworkCallback()); + loader_->didFail(url_loader_, error); + + // Now we should immediately fail any read even if we have data buffered. + EXPECT_CALL(*this, ReadCallback(BufferedResourceLoader::kFailed, 0)); + ReadLoader(10, 10, buffer); +} + TEST_F(BufferedResourceLoaderTest, RequestCancelledWhenRead) { Initialize(kHttpUrl, 10, 29); Start(); |