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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 << " request_id = " << request_id; | 129 << " request_id = " << request_id; |
130 download_start_time_ = base::TimeTicks::Now(); | 130 download_start_time_ = base::TimeTicks::Now(); |
131 | 131 |
132 // If it's a download, we don't want to poison the cache with it. | 132 // If it's a download, we don't want to poison the cache with it. |
133 request_->StopCaching(); | 133 request_->StopCaching(); |
134 | 134 |
135 std::string content_disposition; | 135 std::string content_disposition; |
136 request_->GetResponseHeaderByName("content-disposition", | 136 request_->GetResponseHeaderByName("content-disposition", |
137 &content_disposition); | 137 &content_disposition); |
138 SetContentDisposition(content_disposition); | 138 SetContentDisposition(content_disposition); |
139 SetContentLength(response->content_length); | 139 SetContentLength(response->head.content_length); |
140 | 140 |
141 const ResourceRequestInfoImpl* request_info = | 141 const ResourceRequestInfoImpl* request_info = |
142 ResourceRequestInfoImpl::ForRequest(request_); | 142 ResourceRequestInfoImpl::ForRequest(request_); |
143 | 143 |
144 // Deleted in DownloadManager. | 144 // Deleted in DownloadManager. |
145 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( | 145 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( |
146 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, | 146 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, |
147 request_->net_log(), request_info->HasUserGesture(), | 147 request_->net_log(), request_info->HasUserGesture(), |
148 request_info->transition_type())); | 148 request_info->transition_type())); |
149 | 149 |
150 // Create the ByteStream for sending data to the download sink. | 150 // Create the ByteStream for sending data to the download sink. |
151 scoped_ptr<content::ByteStreamReader> stream_reader; | 151 scoped_ptr<content::ByteStreamReader> stream_reader; |
152 CreateByteStream( | 152 CreateByteStream( |
153 base::MessageLoopProxy::current(), | 153 base::MessageLoopProxy::current(), |
154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
155 kDownloadByteStreamSize, &stream_writer_, &stream_reader); | 155 kDownloadByteStreamSize, &stream_writer_, &stream_reader); |
156 stream_writer_->RegisterCallback( | 156 stream_writer_->RegisterCallback( |
157 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); | 157 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); |
158 | 158 |
159 info->url_chain = request_->url_chain(); | 159 info->url_chain = request_->url_chain(); |
160 info->referrer_url = GURL(request_->referrer()); | 160 info->referrer_url = GURL(request_->referrer()); |
161 info->start_time = base::Time::Now(); | 161 info->start_time = base::Time::Now(); |
162 info->received_bytes = save_info_.offset; | 162 info->received_bytes = save_info_.offset; |
163 info->total_bytes = content_length_; | 163 info->total_bytes = content_length_; |
164 info->state = DownloadItem::IN_PROGRESS; | 164 info->state = DownloadItem::IN_PROGRESS; |
165 info->has_user_gesture = request_info->HasUserGesture(); | 165 info->has_user_gesture = request_info->HasUserGesture(); |
166 info->content_disposition = content_disposition_; | 166 info->content_disposition = content_disposition_; |
167 info->mime_type = response->mime_type; | 167 info->mime_type = response->head.mime_type; |
168 info->remote_address = request_->GetSocketAddress().host(); | 168 info->remote_address = request_->GetSocketAddress().host(); |
169 download_stats::RecordDownloadMimeType(info->mime_type); | 169 download_stats::RecordDownloadMimeType(info->mime_type); |
170 | 170 |
171 info->request_handle = | 171 info->request_handle = |
172 DownloadRequestHandle(AsWeakPtr(), global_id_.child_id, | 172 DownloadRequestHandle(AsWeakPtr(), global_id_.child_id, |
173 render_view_id_, global_id_.request_id); | 173 render_view_id_, global_id_.request_id); |
174 | 174 |
175 // Get the last modified time and etag. | 175 // Get the last modified time and etag. |
176 const net::HttpResponseHeaders* headers = request_->response_headers(); | 176 const net::HttpResponseHeaders* headers = request_->response_headers(); |
177 if (headers) { | 177 if (headers) { |
178 std::string last_modified_hdr; | 178 std::string last_modified_hdr; |
179 std::string etag; | 179 std::string etag; |
180 if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr)) | 180 if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr)) |
181 info->last_modified = last_modified_hdr; | 181 info->last_modified = last_modified_hdr; |
182 if (headers->EnumerateHeader(NULL, "ETag", &etag)) | 182 if (headers->EnumerateHeader(NULL, "ETag", &etag)) |
183 info->etag = etag; | 183 info->etag = etag; |
184 } | 184 } |
185 | 185 |
186 std::string content_type_header; | 186 std::string content_type_header; |
187 if (!response->headers || | 187 if (!response->head.headers || |
188 !response->headers->GetMimeType(&content_type_header)) | 188 !response->head.headers->GetMimeType(&content_type_header)) |
189 content_type_header = ""; | 189 content_type_header = ""; |
190 info->original_mime_type = content_type_header; | 190 info->original_mime_type = content_type_header; |
191 | 191 |
192 if (!response->headers || | 192 if (!response->head.headers || |
193 !response->headers->EnumerateHeader(NULL, | 193 !response->head.headers->EnumerateHeader( |
194 "Accept-Ranges", | 194 NULL, "Accept-Ranges", &accept_ranges_)) { |
195 &accept_ranges_)) { | |
196 accept_ranges_ = ""; | 195 accept_ranges_ = ""; |
197 } | 196 } |
198 | 197 |
199 info->prompt_user_for_save_location = | 198 info->prompt_user_for_save_location = |
200 save_info_.prompt_for_save_location && save_info_.file_path.empty(); | 199 save_info_.prompt_for_save_location && save_info_.file_path.empty(); |
201 info->referrer_charset = request_->context()->referrer_charset(); | 200 info->referrer_charset = request_->context()->referrer_charset(); |
202 info->save_info = save_info_; | 201 info->save_info = save_info_; |
203 | 202 |
204 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
205 BrowserThread::UI, FROM_HERE, | 204 BrowserThread::UI, FROM_HERE, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 // false somewhere in the chain of resource handlers. | 445 // false somewhere in the chain of resource handlers. |
447 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); | 446 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); |
448 | 447 |
449 // Remove output stream callback if a stream exists. | 448 // Remove output stream callback if a stream exists. |
450 if (stream_writer_.get()) | 449 if (stream_writer_.get()) |
451 stream_writer_->RegisterCallback(base::Closure()); | 450 stream_writer_->RegisterCallback(base::Closure()); |
452 | 451 |
453 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 452 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
454 base::TimeTicks::Now() - download_start_time_); | 453 base::TimeTicks::Now() - download_start_time_); |
455 } | 454 } |
OLD | NEW |