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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 << " request_id = " << request_id; | 98 << " request_id = " << request_id; |
99 download_start_time_ = base::TimeTicks::Now(); | 99 download_start_time_ = base::TimeTicks::Now(); |
100 | 100 |
101 // If it's a download, we don't want to poison the cache with it. | 101 // If it's a download, we don't want to poison the cache with it. |
102 request_->StopCaching(); | 102 request_->StopCaching(); |
103 | 103 |
104 std::string content_disposition; | 104 std::string content_disposition; |
105 request_->GetResponseHeaderByName("content-disposition", | 105 request_->GetResponseHeaderByName("content-disposition", |
106 &content_disposition); | 106 &content_disposition); |
107 set_content_disposition(content_disposition); | 107 set_content_disposition(content_disposition); |
108 set_content_length(response->content_length); | 108 set_content_length(response->data.content_length); |
darin (slow to review)
2012/05/22 18:01:31
yuck, the extra "data." is quite unfortunate.
| |
109 | 109 |
110 const ResourceRequestInfoImpl* request_info = | 110 const ResourceRequestInfoImpl* request_info = |
111 ResourceRequestInfoImpl::ForRequest(request_); | 111 ResourceRequestInfoImpl::ForRequest(request_); |
112 | 112 |
113 // Deleted in DownloadManager. | 113 // Deleted in DownloadManager. |
114 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( | 114 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( |
115 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, | 115 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, |
116 request_->net_log(), request_info->has_user_gesture(), | 116 request_->net_log(), request_info->has_user_gesture(), |
117 request_info->transition_type())); | 117 request_info->transition_type())); |
118 info->url_chain = request_->url_chain(); | 118 info->url_chain = request_->url_chain(); |
119 info->referrer_url = GURL(request_->referrer()); | 119 info->referrer_url = GURL(request_->referrer()); |
120 info->start_time = base::Time::Now(); | 120 info->start_time = base::Time::Now(); |
121 info->received_bytes = save_info_.offset; | 121 info->received_bytes = save_info_.offset; |
122 info->total_bytes = content_length_; | 122 info->total_bytes = content_length_; |
123 info->state = DownloadItem::IN_PROGRESS; | 123 info->state = DownloadItem::IN_PROGRESS; |
124 info->has_user_gesture = request_info->has_user_gesture(); | 124 info->has_user_gesture = request_info->has_user_gesture(); |
125 info->content_disposition = content_disposition_; | 125 info->content_disposition = content_disposition_; |
126 info->mime_type = response->mime_type; | 126 info->mime_type = response->data.mime_type; |
127 info->remote_address = request_->GetSocketAddress().host(); | 127 info->remote_address = request_->GetSocketAddress().host(); |
128 download_stats::RecordDownloadMimeType(info->mime_type); | 128 download_stats::RecordDownloadMimeType(info->mime_type); |
129 | 129 |
130 DownloadRequestHandle request_handle(global_id_.child_id, | 130 DownloadRequestHandle request_handle(global_id_.child_id, |
131 render_view_id_, global_id_.request_id); | 131 render_view_id_, global_id_.request_id); |
132 | 132 |
133 // Get the last modified time and etag. | 133 // Get the last modified time and etag. |
134 const net::HttpResponseHeaders* headers = request_->response_headers(); | 134 const net::HttpResponseHeaders* headers = request_->response_headers(); |
135 if (headers) { | 135 if (headers) { |
136 std::string last_modified_hdr; | 136 std::string last_modified_hdr; |
137 std::string etag; | 137 std::string etag; |
138 if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr)) | 138 if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr)) |
139 info->last_modified = last_modified_hdr; | 139 info->last_modified = last_modified_hdr; |
140 if (headers->EnumerateHeader(NULL, "ETag", &etag)) | 140 if (headers->EnumerateHeader(NULL, "ETag", &etag)) |
141 info->etag = etag; | 141 info->etag = etag; |
142 } | 142 } |
143 | 143 |
144 std::string content_type_header; | 144 std::string content_type_header; |
145 if (!response->headers || | 145 if (!response->data.headers || |
146 !response->headers->GetMimeType(&content_type_header)) | 146 !response->data.headers->GetMimeType(&content_type_header)) |
147 content_type_header = ""; | 147 content_type_header = ""; |
148 info->original_mime_type = content_type_header; | 148 info->original_mime_type = content_type_header; |
149 | 149 |
150 if (!response->headers || | 150 if (!response->data.headers || |
151 !response->headers->EnumerateHeader(NULL, | 151 !response->data.headers->EnumerateHeader( |
152 "Accept-Ranges", | 152 NULL, "Accept-Ranges", &accept_ranges_)) { |
153 &accept_ranges_)) { | |
154 accept_ranges_ = ""; | 153 accept_ranges_ = ""; |
155 } | 154 } |
156 | 155 |
157 info->prompt_user_for_save_location = | 156 info->prompt_user_for_save_location = |
158 save_info_.prompt_for_save_location && save_info_.file_path.empty(); | 157 save_info_.prompt_for_save_location && save_info_.file_path.empty(); |
159 info->referrer_charset = request_->context()->referrer_charset(); | 158 info->referrer_charset = request_->context()->referrer_charset(); |
160 info->save_info = save_info_; | 159 info->save_info = save_info_; |
161 | 160 |
162 | 161 |
163 BrowserThread::PostTask( | 162 BrowserThread::PostTask( |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 " }", | 432 " }", |
434 request_ ? | 433 request_ ? |
435 request_->url().spec().c_str() : | 434 request_->url().spec().c_str() : |
436 "<NULL request>", | 435 "<NULL request>", |
437 download_id_.local(), | 436 download_id_.local(), |
438 global_id_.child_id, | 437 global_id_.child_id, |
439 global_id_.request_id, | 438 global_id_.request_id, |
440 render_view_id_, | 439 render_view_id_, |
441 save_info_.file_path.value().c_str()); | 440 save_info_.file_path.value().c_str()); |
442 } | 441 } |
OLD | NEW |