From f2477e01787aa58f445919b809d89e252beef54f Mon Sep 17 00:00:00 2001 From: "Torne (Richard Coles)" Date: Thu, 28 Nov 2013 11:55:43 +0000 Subject: Merge from Chromium at DEPS revision 237746 This commit was generated by merge_to_master.py. Change-Id: I8997af4cddfeb09a7c26f7e8e672c712cab461ea --- .../browser/download/download_resource_handler.cc | 98 +++++++++------------- 1 file changed, 41 insertions(+), 57 deletions(-) (limited to 'content/browser/download/download_resource_handler.cc') diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc index fded1ebce9..9f00ef660b 100644 --- a/content/browser/download/download_resource_handler.cc +++ b/content/browser/download/download_resource_handler.cc @@ -76,7 +76,6 @@ DownloadResourceHandler::DownloadResourceHandler( scoped_ptr save_info) : ResourceHandler(request), download_id_(id), - content_length_(0), started_cb_(started_cb), save_info_(save_info.Pass()), last_buffer_size_(0), @@ -125,19 +124,22 @@ bool DownloadResourceHandler::OnResponseStarted( // with main frames. request()->SetPriority(net::IDLE); - std::string content_disposition; - request()->GetResponseHeaderByName("content-disposition", - &content_disposition); - SetContentDisposition(content_disposition); - SetContentLength(response->head.content_length); + // If the content-length header is not present (or contains something other + // than numbers), the incoming content_length is -1 (unknown size). + // Set the content length to 0 to indicate unknown size to DownloadManager. + int64 content_length = + response->head.content_length > 0 ? response->head.content_length : 0; const ResourceRequestInfoImpl* request_info = GetRequestInfo(); // Deleted in DownloadManager. - scoped_ptr info(new DownloadCreateInfo( - base::Time::Now(), content_length_, - request()->net_log(), request_info->HasUserGesture(), - request_info->GetPageTransition())); + scoped_ptr info( + new DownloadCreateInfo(base::Time::Now(), + content_length, + request()->net_log(), + request_info->HasUserGesture(), + request_info->GetPageTransition(), + save_info_.Pass())); // Create the ByteStream for sending data to the download sink. scoped_ptr stream_reader; @@ -151,12 +153,10 @@ bool DownloadResourceHandler::OnResponseStarted( info->download_id = download_id_; info->url_chain = request()->url_chain(); info->referrer_url = GURL(request()->referrer()); - info->start_time = base::Time::Now(); - info->total_bytes = content_length_; - info->has_user_gesture = request_info->HasUserGesture(); - info->content_disposition = content_disposition_; info->mime_type = response->head.mime_type; info->remote_address = request()->GetSocketAddress().host(); + request()->GetResponseHeaderByName("content-disposition", + &info->content_disposition); RecordDownloadMimeType(info->mime_type); RecordDownloadContentDisposition(info->content_disposition); @@ -168,35 +168,28 @@ bool DownloadResourceHandler::OnResponseStarted( // Get the last modified time and etag. const net::HttpResponseHeaders* headers = request()->response_headers(); if (headers) { - std::string last_modified_hdr; - if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr)) - info->last_modified = last_modified_hdr; - if (headers->EnumerateHeader(NULL, "ETag", &etag_)) - info->etag = etag_; + if (headers->HasStrongValidators()) { + // If we don't have strong validators as per RFC 2616 section 13.3.3, then + // we neither store nor use them for range requests. + if (!headers->EnumerateHeader(NULL, "Last-Modified", + &info->last_modified)) + info->last_modified.clear(); + if (!headers->EnumerateHeader(NULL, "ETag", &info->etag)) + info->etag.clear(); + } int status = headers->response_code(); if (2 == status / 100 && status != net::HTTP_PARTIAL_CONTENT) { // Success & not range response; if we asked for a range, we didn't // get it--reset the file pointers to reflect that. - save_info_->offset = 0; - save_info_->hash_state = ""; + info->save_info->offset = 0; + info->save_info->hash_state = ""; } - } - std::string content_type_header; - if (!response->head.headers.get() || - !response->head.headers->GetMimeType(&content_type_header)) - content_type_header = ""; - info->original_mime_type = content_type_header; - - if (!response->head.headers.get() || - !response->head.headers->EnumerateHeader( - NULL, "Accept-Ranges", &accept_ranges_)) { - accept_ranges_ = ""; + if (!headers->GetMimeType(&info->original_mime_type)) + info->original_mime_type.clear(); } - info->save_info = save_info_.Pass(); - BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&StartOnUIThread, @@ -287,10 +280,11 @@ bool DownloadResourceHandler::OnReadCompleted(int request_id, int bytes_read, return true; } -bool DownloadResourceHandler::OnResponseCompleted( +void DownloadResourceHandler::OnResponseCompleted( int request_id, const net::URLRequestStatus& status, - const std::string& security_info) { + const std::string& security_info, + bool* defer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); int response_code = status.is_success() ? request()->GetResponseCode() : 0; VLOG(20) << __FUNCTION__ << "()" << DebugString() @@ -372,9 +366,17 @@ bool DownloadResourceHandler::OnResponseCompleted( } } - RecordAcceptsRanges(accept_ranges_, bytes_read_, etag_); - RecordNetworkBlockage( - base::TimeTicks::Now() - download_start_time_, total_pause_time_); + std::string accept_ranges; + bool has_strong_validators = false; + if (request()->response_headers()) { + request()->response_headers()->EnumerateHeader( + NULL, "Accept-Ranges", &accept_ranges); + has_strong_validators = + request()->response_headers()->HasStrongValidators(); + } + RecordAcceptsRanges(accept_ranges, bytes_read_, has_strong_validators); + RecordNetworkBlockage(base::TimeTicks::Now() - download_start_time_, + total_pause_time_); CallStartedCB(NULL, error_code); @@ -393,8 +395,6 @@ bool DownloadResourceHandler::OnResponseCompleted( stream_writer_.reset(); // We no longer need the stream. read_buffer_ = NULL; - - return true; } void DownloadResourceHandler::OnDataDownloaded( @@ -403,22 +403,6 @@ void DownloadResourceHandler::OnDataDownloaded( NOTREACHED(); } -// If the content-length header is not present (or contains something other -// than numbers), the incoming content_length is -1 (unknown size). -// Set the content length to 0 to indicate unknown size to DownloadManager. -void DownloadResourceHandler::SetContentLength(const int64& content_length) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - content_length_ = 0; - if (content_length > 0) - content_length_ = content_length; -} - -void DownloadResourceHandler::SetContentDisposition( - const std::string& content_disposition) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - content_disposition_ = content_disposition; -} - void DownloadResourceHandler::PauseRequest() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -- cgit v1.2.3