| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 global_id_(render_process_host_id, request_id), | 46 global_id_(render_process_host_id, request_id), |
| 47 render_view_id_(render_view_id), | 47 render_view_id_(render_view_id), |
| 48 content_length_(0), | 48 content_length_(0), |
| 49 download_file_manager_(download_file_manager), | 49 download_file_manager_(download_file_manager), |
| 50 request_(request), | 50 request_(request), |
| 51 save_as_(save_as), | 51 save_as_(save_as), |
| 52 started_cb_(started_cb), | 52 started_cb_(started_cb), |
| 53 save_info_(save_info), | 53 save_info_(save_info), |
| 54 buffer_(new content::DownloadBuffer), | 54 buffer_(new content::DownloadBuffer), |
| 55 rdh_(rdh), | 55 rdh_(rdh), |
| 56 is_paused_(false) { | 56 is_paused_(false), |
| 57 start_offset_(0) { |
| 57 DCHECK(dl_id.IsValid()); | 58 DCHECK(dl_id.IsValid()); |
| 58 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); | 59 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool DownloadResourceHandler::OnUploadProgress(int request_id, | 62 bool DownloadResourceHandler::OnUploadProgress(int request_id, |
| 62 uint64 position, | 63 uint64 position, |
| 63 uint64 size) { | 64 uint64 size) { |
| 64 return true; | 65 return true; |
| 65 } | 66 } |
| 66 | 67 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 ResourceDispatcherHost::InfoForRequest(request_); | 94 ResourceDispatcherHost::InfoForRequest(request_); |
| 94 | 95 |
| 95 // Deleted in DownloadManager. | 96 // Deleted in DownloadManager. |
| 96 DownloadCreateInfo* info = new DownloadCreateInfo(FilePath(), GURL(), | 97 DownloadCreateInfo* info = new DownloadCreateInfo(FilePath(), GURL(), |
| 97 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, | 98 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, |
| 98 download_id_, request_info->has_user_gesture(), | 99 download_id_, request_info->has_user_gesture(), |
| 99 request_info->transition_type()); | 100 request_info->transition_type()); |
| 100 info->url_chain = request_->url_chain(); | 101 info->url_chain = request_->url_chain(); |
| 101 info->referrer_url = GURL(request_->referrer()); | 102 info->referrer_url = GURL(request_->referrer()); |
| 102 info->start_time = base::Time::Now(); | 103 info->start_time = base::Time::Now(); |
| 103 info->received_bytes = 0; | 104 info->received_bytes = start_offset_; |
| 104 info->total_bytes = content_length_; | 105 info->total_bytes = content_length_; |
| 105 info->state = DownloadItem::IN_PROGRESS; | 106 info->state = DownloadItem::IN_PROGRESS; |
| 106 info->download_id = download_id_; | 107 info->download_id = download_id_; |
| 107 info->has_user_gesture = request_info->has_user_gesture(); | 108 info->has_user_gesture = request_info->has_user_gesture(); |
| 108 info->content_disposition = content_disposition_; | 109 info->content_disposition = content_disposition_; |
| 109 info->mime_type = response->response_head.mime_type; | 110 info->mime_type = response->response_head.mime_type; |
| 110 download_stats::RecordDownloadMimeType(info->mime_type); | 111 download_stats::RecordDownloadMimeType(info->mime_type); |
| 111 | 112 |
| 112 DownloadRequestHandle request_handle(rdh_, global_id_.child_id, | 113 DownloadRequestHandle request_handle(rdh_, global_id_.child_id, |
| 113 render_view_id_, global_id_.request_id); | 114 render_view_id_, global_id_.request_id); |
| 114 | 115 |
| 115 // TODO(ahendrickson) -- Get the last modified time and etag, so we can | 116 // Get the last modified time and etag. |
| 116 // resume downloading. | 117 const net::HttpResponseHeaders* headers = request_->response_headers(); |
| 118 if (headers) { |
| 119 std::string last_modified_hdr; |
| 120 std::string etag; |
| 121 if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr)) |
| 122 info->last_modified = last_modified_hdr; |
| 123 if (headers->EnumerateHeader(NULL, "ETag", &etag)) |
| 124 info->etag = etag; |
| 125 } |
| 117 | 126 |
| 118 CallStartedCB(net::OK); | 127 CallStartedCB(net::OK); |
| 119 | 128 |
| 120 std::string content_type_header; | 129 std::string content_type_header; |
| 121 if (!response->response_head.headers || | 130 if (!response->response_head.headers || |
| 122 !response->response_head.headers->GetMimeType(&content_type_header)) | 131 !response->response_head.headers->GetMimeType(&content_type_header)) |
| 123 content_type_header = ""; | 132 content_type_header = ""; |
| 124 info->original_mime_type = content_type_header; | 133 info->original_mime_type = content_type_header; |
| 125 | 134 |
| 126 info->prompt_user_for_save_location = | 135 info->prompt_user_for_save_location = |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 " render_view_id_ = " "%d" | 317 " render_view_id_ = " "%d" |
| 309 " save_info_.file_path = \"%" PRFilePath "\"" | 318 " save_info_.file_path = \"%" PRFilePath "\"" |
| 310 " }", | 319 " }", |
| 311 request_->url().spec().c_str(), | 320 request_->url().spec().c_str(), |
| 312 download_id_.local(), | 321 download_id_.local(), |
| 313 global_id_.child_id, | 322 global_id_.child_id, |
| 314 global_id_.request_id, | 323 global_id_.request_id, |
| 315 render_view_id_, | 324 render_view_id_, |
| 316 save_info_.file_path.value().c_str()); | 325 save_info_.file_path.value().c_str()); |
| 317 } | 326 } |
| OLD | NEW |