OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
14 #include "content/browser/download/download_buffer.h" | 14 #include "content/browser/download/download_buffer.h" |
15 #include "content/browser/download/download_create_info.h" | 15 #include "content/browser/download/download_create_info.h" |
16 #include "content/browser/download/download_file_manager.h" | 16 #include "content/browser/download/download_file_manager.h" |
17 #include "content/browser/download/download_item.h" | 17 #include "content/browser/download/download_item.h" |
18 #include "content/browser/download/download_request_handle.h" | 18 #include "content/browser/download/download_request_handle.h" |
19 #include "content/browser/download/download_stats.h" | 19 #include "content/browser/download/download_stats.h" |
| 20 #include "content/browser/download/interrupt_reasons.h" |
20 #include "content/browser/renderer_host/global_request_id.h" | 21 #include "content/browser/renderer_host/global_request_id.h" |
21 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 22 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
22 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 23 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
23 #include "content/common/resource_response.h" | 24 #include "content/common/resource_response.h" |
24 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
26 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
27 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
28 | 29 |
29 DownloadResourceHandler::DownloadResourceHandler( | 30 DownloadResourceHandler::DownloadResourceHandler( |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 189 } |
189 | 190 |
190 bool DownloadResourceHandler::OnResponseCompleted( | 191 bool DownloadResourceHandler::OnResponseCompleted( |
191 int request_id, | 192 int request_id, |
192 const net::URLRequestStatus& status, | 193 const net::URLRequestStatus& status, |
193 const std::string& security_info) { | 194 const std::string& security_info) { |
194 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 195 VLOG(20) << __FUNCTION__ << "()" << DebugString() |
195 << " request_id = " << request_id | 196 << " request_id = " << request_id |
196 << " status.status() = " << status.status() | 197 << " status.status() = " << status.status() |
197 << " status.error() = " << status.error(); | 198 << " status.error() = " << status.error(); |
198 net::Error error_code = (status.status() == net::URLRequestStatus::FAILED) ? | 199 net::Error error_code = net::OK; |
199 static_cast<net::Error>(status.error()) : net::OK; | 200 if (status.status() == net::URLRequestStatus::FAILED) |
| 201 error_code = static_cast<net::Error>(status.error()); // Normal case. |
| 202 // ERR_CONNECTION_CLOSED is allowed since a number of servers in the wild |
| 203 // advertise a larger Content-Length than the amount of bytes in the message |
| 204 // body, and then close the connection. Other browsers - IE8, Firefox 4.0.1, |
| 205 // and Safari 5.0.4 - treat the download as complete in this case, so we |
| 206 // follow their lead. |
| 207 if (error_code == net::ERR_CONNECTION_CLOSED) |
| 208 error_code = net::OK; |
| 209 InterruptReason reason = |
| 210 ConvertNetErrorToInterruptReason(error_code, |
| 211 DOWNLOAD_INTERRUPT_FROM_NETWORK); |
| 212 if ((status.status() == net::URLRequestStatus::CANCELED) && |
| 213 (status.error() == net::ERR_ABORTED)) { |
| 214 // TODO(ahendrickson) -- Find a better set of codes to use here, as |
| 215 // CANCELED/ERR_ABORTED can occur for reasons other than user cancel. |
| 216 reason = DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; // User canceled. |
| 217 } |
200 if (!download_id_.IsValid()) | 218 if (!download_id_.IsValid()) |
201 CallStartedCB(error_code); | 219 CallStartedCB(error_code); |
202 // We transfer ownership to |DownloadFileManager| to delete |buffer_|, | 220 // We transfer ownership to |DownloadFileManager| to delete |buffer_|, |
203 // so that any functions queued up on the FILE thread are executed | 221 // so that any functions queued up on the FILE thread are executed |
204 // before deletion. | 222 // before deletion. |
205 BrowserThread::PostTask( | 223 BrowserThread::PostTask( |
206 BrowserThread::FILE, FROM_HERE, | 224 BrowserThread::FILE, FROM_HERE, |
207 NewRunnableMethod(download_file_manager_, | 225 NewRunnableMethod(download_file_manager_, |
208 &DownloadFileManager::OnResponseCompleted, | 226 &DownloadFileManager::OnResponseCompleted, |
209 download_id_, | 227 download_id_, |
210 error_code, | 228 reason, |
211 security_info)); | 229 security_info)); |
212 buffer_ = NULL; // The buffer is longer needed by |DownloadResourceHandler|. | 230 buffer_ = NULL; // The buffer is longer needed by |DownloadResourceHandler|. |
213 read_buffer_ = NULL; | 231 read_buffer_ = NULL; |
214 return true; | 232 return true; |
215 } | 233 } |
216 | 234 |
217 void DownloadResourceHandler::OnRequestClosed() { | 235 void DownloadResourceHandler::OnRequestClosed() { |
218 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 236 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
219 base::TimeTicks::Now() - download_start_time_); | 237 base::TimeTicks::Now() - download_start_time_); |
220 } | 238 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 " render_view_id_ = " "%d" | 291 " render_view_id_ = " "%d" |
274 " save_info_.file_path = \"%" PRFilePath "\"" | 292 " save_info_.file_path = \"%" PRFilePath "\"" |
275 " }", | 293 " }", |
276 request_->url().spec().c_str(), | 294 request_->url().spec().c_str(), |
277 download_id_.local(), | 295 download_id_.local(), |
278 global_id_.child_id, | 296 global_id_.child_id, |
279 global_id_.request_id, | 297 global_id_.request_id, |
280 render_view_id_, | 298 render_view_id_, |
281 save_info_.file_path.value().c_str()); | 299 save_info_.file_path.value().c_str()); |
282 } | 300 } |
OLD | NEW |