summaryrefslogtreecommitdiffstats
path: root/content/browser/download/download_resource_handler.cc
diff options
context:
space:
mode:
authorcreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-07 19:45:52 +0000
committercreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-07 19:45:52 +0000
commit66ab87e8ebc518ab54238f9899f813311844997b (patch)
treeb26bbd221e2668c33d84ab9ca92cc45a01828080 /content/browser/download/download_resource_handler.cc
parentc745d405c8ac5a39c4ede5ccafe3445878b3767b (diff)
downloadchromium_src-66ab87e8ebc518ab54238f9899f813311844997b.zip
chromium_src-66ab87e8ebc518ab54238f9899f813311844997b.tar.gz
chromium_src-66ab87e8ebc518ab54238f9899f813311844997b.tar.bz2
Clean up ResourceHandler API.
1. Move URLRequest member to ResourceHandler base class and add convenience functions for subclasses. 2. Make OnWillRead take a scoped_refptr to avoid leaking the buffer. BUG=295239 TEST=No behavior change. Review URL: https://codereview.chromium.org/25536005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download/download_resource_handler.cc')
-rw-r--r--content/browser/download/download_resource_handler.cc45
1 files changed, 23 insertions, 22 deletions
diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc
index 6fae0c7..fded1eb 100644
--- a/content/browser/download/download_resource_handler.cc
+++ b/content/browser/download/download_resource_handler.cc
@@ -74,9 +74,9 @@ DownloadResourceHandler::DownloadResourceHandler(
net::URLRequest* request,
const DownloadUrlParameters::OnStartedCallback& started_cb,
scoped_ptr<DownloadSaveInfo> save_info)
- : download_id_(id),
+ : ResourceHandler(request),
+ download_id_(id),
content_length_(0),
- request_(request),
started_cb_(started_cb),
save_info_(save_info.Pass()),
last_buffer_size_(0),
@@ -100,7 +100,7 @@ bool DownloadResourceHandler::OnRequestRedirected(
bool* defer) {
// We treat a download as a main frame load, and thus update the policy URL
// on redirects.
- request_->set_first_party_for_cookies(url);
+ request()->set_first_party_for_cookies(url);
return true;
}
@@ -119,25 +119,24 @@ bool DownloadResourceHandler::OnResponseStarted(
download_start_time_ = base::TimeTicks::Now();
// If it's a download, we don't want to poison the cache with it.
- request_->StopCaching();
+ request()->StopCaching();
// Lower priority as well, so downloads don't contend for resources
// with main frames.
- request_->SetPriority(net::IDLE);
+ request()->SetPriority(net::IDLE);
std::string content_disposition;
- request_->GetResponseHeaderByName("content-disposition",
- &content_disposition);
+ request()->GetResponseHeaderByName("content-disposition",
+ &content_disposition);
SetContentDisposition(content_disposition);
SetContentLength(response->head.content_length);
- const ResourceRequestInfoImpl* request_info =
- ResourceRequestInfoImpl::ForRequest(request_);
+ const ResourceRequestInfoImpl* request_info = GetRequestInfo();
// Deleted in DownloadManager.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo(
base::Time::Now(), content_length_,
- request_->net_log(), request_info->HasUserGesture(),
+ request()->net_log(), request_info->HasUserGesture(),
request_info->GetPageTransition()));
// Create the ByteStream for sending data to the download sink.
@@ -150,14 +149,14 @@ bool DownloadResourceHandler::OnResponseStarted(
base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr()));
info->download_id = download_id_;
- info->url_chain = request_->url_chain();
- info->referrer_url = GURL(request_->referrer());
+ 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();
+ info->remote_address = request()->GetSocketAddress().host();
RecordDownloadMimeType(info->mime_type);
RecordDownloadContentDisposition(info->content_disposition);
@@ -167,7 +166,7 @@ bool DownloadResourceHandler::OnResponseStarted(
request_info->GetRequestID());
// Get the last modified time and etag.
- const net::HttpResponseHeaders* headers = request_->response_headers();
+ const net::HttpResponseHeaders* headers = request()->response_headers();
if (headers) {
std::string last_modified_hdr;
if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr))
@@ -232,8 +231,10 @@ bool DownloadResourceHandler::OnWillStart(int request_id,
// Create a new buffer, which will be handed to the download thread for file
// writing and deletion.
-bool DownloadResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
- int* buf_size, int min_size) {
+bool DownloadResourceHandler::OnWillRead(int request_id,
+ scoped_refptr<net::IOBuffer>* buf,
+ int* buf_size,
+ int min_size) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(buf && buf_size);
DCHECK(!read_buffer_.get());
@@ -291,7 +292,7 @@ bool DownloadResourceHandler::OnResponseCompleted(
const net::URLRequestStatus& status,
const std::string& security_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- int response_code = status.is_success() ? request_->GetResponseCode() : 0;
+ int response_code = status.is_success() ? request()->GetResponseCode() : 0;
VLOG(20) << __FUNCTION__ << "()" << DebugString()
<< " request_id = " << request_id
<< " status.status() = " << status.status()
@@ -335,7 +336,7 @@ bool DownloadResourceHandler::OnResponseCompleted(
if (status.is_success() &&
reason == DOWNLOAD_INTERRUPT_REASON_NONE &&
- request_->response_headers()) {
+ request()->response_headers()) {
// Handle server's response codes.
switch(response_code) {
case -1: // Non-HTTP request.
@@ -447,7 +448,7 @@ void DownloadResourceHandler::ResumeRequest() {
void DownloadResourceHandler::CancelRequest() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
+ const ResourceRequestInfo* info = GetRequestInfo();
ResourceDispatcherHostImpl::Get()->CancelRequest(
info->GetChildID(),
info->GetRequestID(),
@@ -455,7 +456,7 @@ void DownloadResourceHandler::CancelRequest() {
}
std::string DownloadResourceHandler::DebugString() const {
- const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
+ const ResourceRequestInfo* info = GetRequestInfo();
return base::StringPrintf("{"
" url_ = " "\"%s\""
" info = {"
@@ -464,8 +465,8 @@ std::string DownloadResourceHandler::DebugString() const {
" route_id = " "%d"
" }"
" }",
- request_ ?
- request_->url().spec().c_str() :
+ request() ?
+ request()->url().spec().c_str() :
"<NULL request>",
info->GetChildID(),
info->GetRequestID(),