diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-16 00:39:41 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-16 00:39:41 +0000 |
commit | 5b26ed7cb7e9a31ba474f43058e460b8321159d3 (patch) | |
tree | 2229d830584598f64ad6a5113a4cbe7d131b6606 | |
parent | 28f39c67d6dc6ee3b28f1bf47f97ab7629d4faaf (diff) | |
download | chromium_src-5b26ed7cb7e9a31ba474f43058e460b8321159d3.zip chromium_src-5b26ed7cb7e9a31ba474f43058e460b8321159d3.tar.gz chromium_src-5b26ed7cb7e9a31ba474f43058e460b8321159d3.tar.bz2 |
Shouldn't assume response code of 200 in SimpleDataSource
SimpleDataSource assumes the scheme is file or http and the
response code is 200. We should just check if the response
is successful using response.is_success() and verify the
content_length, which will be -1 in case of unspecified length.
Review URL: http://codereview.chromium.org/113422
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16217 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/media/simple_data_source.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/chrome/renderer/media/simple_data_source.cc b/chrome/renderer/media/simple_data_source.cc index 87e79d3..d029382 100644 --- a/chrome/renderer/media/simple_data_source.cc +++ b/chrome/renderer/media/simple_data_source.cc @@ -15,7 +15,7 @@ SimpleDataSource::SimpleDataSource(int32 routing_id) : routing_id_(routing_id), render_loop_(RenderThread::current()->message_loop()), - size_(0), + size_(-1), position_(0) { } @@ -59,6 +59,7 @@ const media::MediaFormat& SimpleDataSource::media_format() { } size_t SimpleDataSource::Read(uint8* data, size_t size) { + DCHECK_GE(size_, 0); size_t copied = std::min(size, static_cast<size_t>(size_ - position_)); memcpy(data, data_.c_str() + position_, copied); position_ += copied; @@ -97,10 +98,6 @@ void SimpleDataSource::OnReceivedRedirect(const GURL& new_url) { void SimpleDataSource::OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered) { - // This is a simple data source, so we assume 200 responses with the content - // length provided. - DCHECK(url_.SchemeIsFile() || info.headers->response_code() == 200); - DCHECK(info.content_length != -1); size_ = info.content_length; } @@ -110,9 +107,17 @@ void SimpleDataSource::OnReceivedData(const char* data, int len) { void SimpleDataSource::OnCompletedRequest(const URLRequestStatus& status, const std::string& security_info) { - DCHECK(size_ == data_.length()); - position_ = 0; bridge_.reset(); + // If we don't get a content length or the request has failed, report it + // as a network error. + DCHECK(size_ == -1 || size_ == data_.length()); + if (size_ == -1) + size_ = data_.length(); + if (!status.is_success()) { + host_->Error(media::PIPELINE_ERROR_NETWORK); + } else { + host_->InitializationComplete(); + } host_->SetTotalBytes(size_); host_->SetBufferedBytes(size_); host_->InitializationComplete(); |