OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/download/download_resource_handler.h" | 5 #include "content/browser/download/download_resource_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 &content_disposition); | 142 &content_disposition); |
143 SetContentDisposition(content_disposition); | 143 SetContentDisposition(content_disposition); |
144 SetContentLength(response->content_length); | 144 SetContentLength(response->content_length); |
145 | 145 |
146 const ResourceRequestInfoImpl* request_info = | 146 const ResourceRequestInfoImpl* request_info = |
147 ResourceRequestInfoImpl::ForRequest(request_); | 147 ResourceRequestInfoImpl::ForRequest(request_); |
148 | 148 |
149 // Deleted in DownloadManager. | 149 // Deleted in DownloadManager. |
150 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( | 150 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( |
151 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, | 151 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, |
152 request_->net_log(), request_info->has_user_gesture(), | 152 request_->net_log(), request_info->HasUserGesture(), |
153 request_info->transition_type())); | 153 request_info->transition_type())); |
154 | 154 |
155 // Create the ByteStream for sending data to the download sink. | 155 // Create the ByteStream for sending data to the download sink. |
156 scoped_ptr<content::ByteStreamReader> stream_reader; | 156 scoped_ptr<content::ByteStreamReader> stream_reader; |
157 CreateByteStream( | 157 CreateByteStream( |
158 base::MessageLoopProxy::current(), | 158 base::MessageLoopProxy::current(), |
159 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 159 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
160 kDownloadByteStreamSize, &stream_writer_, &stream_reader); | 160 kDownloadByteStreamSize, &stream_writer_, &stream_reader); |
161 stream_writer_->RegisterCallback( | 161 stream_writer_->RegisterCallback( |
162 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); | 162 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); |
163 | 163 |
164 info->url_chain = request_->url_chain(); | 164 info->url_chain = request_->url_chain(); |
165 info->referrer_url = GURL(request_->referrer()); | 165 info->referrer_url = GURL(request_->referrer()); |
166 info->start_time = base::Time::Now(); | 166 info->start_time = base::Time::Now(); |
167 info->received_bytes = save_info_.offset; | 167 info->received_bytes = save_info_.offset; |
168 info->total_bytes = content_length_; | 168 info->total_bytes = content_length_; |
169 info->state = DownloadItem::IN_PROGRESS; | 169 info->state = DownloadItem::IN_PROGRESS; |
170 info->has_user_gesture = request_info->has_user_gesture(); | 170 info->has_user_gesture = request_info->HasUserGesture(); |
171 info->content_disposition = content_disposition_; | 171 info->content_disposition = content_disposition_; |
172 info->mime_type = response->mime_type; | 172 info->mime_type = response->mime_type; |
173 info->remote_address = request_->GetSocketAddress().host(); | 173 info->remote_address = request_->GetSocketAddress().host(); |
174 download_stats::RecordDownloadMimeType(info->mime_type); | 174 download_stats::RecordDownloadMimeType(info->mime_type); |
175 | 175 |
176 DownloadRequestHandle request_handle(AsWeakPtr(), global_id_.child_id, | 176 DownloadRequestHandle request_handle(AsWeakPtr(), global_id_.child_id, |
177 render_view_id_, global_id_.request_id); | 177 render_view_id_, global_id_.request_id); |
178 | 178 |
179 // Get the last modified time and etag. | 179 // Get the last modified time and etag. |
180 const net::HttpResponseHeaders* headers = request_->response_headers(); | 180 const net::HttpResponseHeaders* headers = request_->response_headers(); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // false somewhere in the chain of resource handlers. | 452 // false somewhere in the chain of resource handlers. |
453 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); | 453 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); |
454 | 454 |
455 // Remove output stream callback if a stream exists. | 455 // Remove output stream callback if a stream exists. |
456 if (stream_writer_.get()) | 456 if (stream_writer_.get()) |
457 stream_writer_->RegisterCallback(base::Closure()); | 457 stream_writer_->RegisterCallback(base::Closure()); |
458 | 458 |
459 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 459 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
460 base::TimeTicks::Now() - download_start_time_); | 460 base::TimeTicks::Now() - download_start_time_); |
461 } | 461 } |
OLD | NEW |