diff options
-rw-r--r-- | mojo/services/network/public/interfaces/url_loader.mojom | 5 | ||||
-rw-r--r-- | mojo/services/network/url_loader_impl.cc | 7 | ||||
-rw-r--r-- | mojo/services/network/url_loader_impl.h | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/mojo/services/network/public/interfaces/url_loader.mojom b/mojo/services/network/public/interfaces/url_loader.mojom index 8a18c26..f7e12c8 100644 --- a/mojo/services/network/public/interfaces/url_loader.mojom +++ b/mojo/services/network/public/interfaces/url_loader.mojom @@ -87,6 +87,11 @@ struct URLLoaderStatus { // body stream. bool is_loading; + // The length in bytes of the content as reported by the HTTP response header, + // and the number of bytes read by the URLLoader thus far. + int64 content_length; + int64 bytes_read; + // TODO(darin): Add further details about the stages of loading (e.g., // "resolving host") that happen prior to receiving bytes. }; diff --git a/mojo/services/network/url_loader_impl.cc b/mojo/services/network/url_loader_impl.cc index dfb1566..ab264cb 100644 --- a/mojo/services/network/url_loader_impl.cc +++ b/mojo/services/network/url_loader_impl.cc @@ -139,6 +139,7 @@ URLLoaderImpl::URLLoaderImpl(NetworkContext* context, scoped_ptr<mojo::AppRefCount> app_refcount) : context_(context), response_body_buffer_size_(0), + response_body_bytes_read_(0), auto_follow_redirects_(true), connected_(true), binding_(this, request.Pass()), @@ -231,10 +232,15 @@ void URLLoaderImpl::FollowRedirect( void URLLoaderImpl::QueryStatus( const Callback<void(URLLoaderStatusPtr)>& callback) { URLLoaderStatusPtr status(URLLoaderStatus::New()); + status->bytes_read = response_body_bytes_read_; if (url_request_) { status->is_loading = url_request_->is_pending(); if (!url_request_->status().is_success()) status->error = MakeNetworkError(url_request_->status().error()); + if (url_request_->response_info().headers) { + status->content_length = + url_request_->response_info().headers->GetContentLength(); + } } else { status->is_loading = false; } @@ -385,6 +391,7 @@ void URLLoaderImpl::ReadMore() { void URLLoaderImpl::DidRead(uint32_t num_bytes, bool completed_synchronously) { DCHECK(url_request_->status().is_success()); + response_body_bytes_read_ += num_bytes; response_body_stream_ = pending_write_->Complete(num_bytes); pending_write_ = nullptr; diff --git a/mojo/services/network/url_loader_impl.h b/mojo/services/network/url_loader_impl.h index 0b7b44d..c1931e3 100644 --- a/mojo/services/network/url_loader_impl.h +++ b/mojo/services/network/url_loader_impl.h @@ -63,7 +63,8 @@ class URLLoaderImpl : public URLLoader, ScopedDataPipeProducerHandle response_body_stream_; scoped_refptr<NetToMojoPendingBuffer> pending_write_; common::HandleWatcher handle_watcher_; - uint32 response_body_buffer_size_; + uint32_t response_body_buffer_size_; + uint32_t response_body_bytes_read_; bool auto_follow_redirects_; bool connected_; Binding<URLLoader> binding_; |