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_request_handle.h" |
19 #include "content/browser/download/download_stats.h" | 20 #include "content/browser/download/download_stats.h" |
20 #include "content/browser/download/interrupt_reasons.h" | 21 #include "content/browser/download/interrupt_reasons.h" |
21 #include "content/browser/renderer_host/global_request_id.h" | 22 #include "content/browser/renderer_host/global_request_id.h" |
22 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 23 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
23 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 24 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
24 #include "content/common/resource_response.h" | 25 #include "content/common/resource_response.h" |
25 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
27 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
28 #include "net/url_request/url_request_context.h" | 29 #include "net/url_request/url_request_context.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 download_id_.local(), request_info->has_user_gesture(), | 92 download_id_.local(), request_info->has_user_gesture(), |
92 request_info->transition_type()); | 93 request_info->transition_type()); |
93 info->url_chain = request_->url_chain(); | 94 info->url_chain = request_->url_chain(); |
94 info->referrer_url = GURL(request_->referrer()); | 95 info->referrer_url = GURL(request_->referrer()); |
95 info->start_time = base::Time::Now(); | 96 info->start_time = base::Time::Now(); |
96 info->received_bytes = 0; | 97 info->received_bytes = 0; |
97 info->total_bytes = content_length_; | 98 info->total_bytes = content_length_; |
98 info->state = DownloadItem::IN_PROGRESS; | 99 info->state = DownloadItem::IN_PROGRESS; |
99 info->download_id = download_id_.local(); | 100 info->download_id = download_id_.local(); |
100 info->has_user_gesture = request_info->has_user_gesture(); | 101 info->has_user_gesture = request_info->has_user_gesture(); |
101 info->request_handle = DownloadRequestHandle(rdh_, | |
102 global_id_.child_id, | |
103 render_view_id_, | |
104 global_id_.request_id); | |
105 info->content_disposition = content_disposition_; | 102 info->content_disposition = content_disposition_; |
106 info->mime_type = response->response_head.mime_type; | 103 info->mime_type = response->response_head.mime_type; |
107 download_stats::RecordDownloadMimeType(info->mime_type); | 104 download_stats::RecordDownloadMimeType(info->mime_type); |
| 105 |
| 106 DownloadRequestHandle request_handle(rdh_, global_id_.child_id, |
| 107 render_view_id_, global_id_.request_id); |
| 108 |
108 // TODO(ahendrickson) -- Get the last modified time and etag, so we can | 109 // TODO(ahendrickson) -- Get the last modified time and etag, so we can |
109 // resume downloading. | 110 // resume downloading. |
110 | 111 |
111 CallStartedCB(net::OK); | 112 CallStartedCB(net::OK); |
112 | 113 |
113 std::string content_type_header; | 114 std::string content_type_header; |
114 if (!response->response_head.headers || | 115 if (!response->response_head.headers || |
115 !response->response_head.headers->GetMimeType(&content_type_header)) | 116 !response->response_head.headers->GetMimeType(&content_type_header)) |
116 content_type_header = ""; | 117 content_type_header = ""; |
117 info->original_mime_type = content_type_header; | 118 info->original_mime_type = content_type_header; |
118 | 119 |
119 info->prompt_user_for_save_location = | 120 info->prompt_user_for_save_location = |
120 save_as_ && save_info_.file_path.empty(); | 121 save_as_ && save_info_.file_path.empty(); |
121 info->referrer_charset = request_->context()->referrer_charset(); | 122 info->referrer_charset = request_->context()->referrer_charset(); |
122 info->save_info = save_info_; | 123 info->save_info = save_info_; |
123 BrowserThread::PostTask( | 124 BrowserThread::PostTask( |
124 BrowserThread::UI, FROM_HERE, | 125 BrowserThread::UI, FROM_HERE, |
125 NewRunnableMethod( | 126 NewRunnableMethod( |
126 download_file_manager_, &DownloadFileManager::StartDownload, info)); | 127 download_file_manager_, &DownloadFileManager::StartDownload, |
| 128 info, request_handle)); |
127 | 129 |
128 // We can't start saving the data before we create the file on disk. | 130 // We can't start saving the data before we create the file on disk. |
129 // The request will be un-paused in DownloadFileManager::CreateDownloadFile. | 131 // The request will be un-paused in DownloadFileManager::CreateDownloadFile. |
130 rdh_->PauseRequest(global_id_.child_id, global_id_.request_id, true); | 132 rdh_->PauseRequest(global_id_.child_id, global_id_.request_id, true); |
131 | 133 |
132 return true; | 134 return true; |
133 } | 135 } |
134 | 136 |
135 void DownloadResourceHandler::CallStartedCB(net::Error error) { | 137 void DownloadResourceHandler::CallStartedCB(net::Error error) { |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 " render_view_id_ = " "%d" | 293 " render_view_id_ = " "%d" |
292 " save_info_.file_path = \"%" PRFilePath "\"" | 294 " save_info_.file_path = \"%" PRFilePath "\"" |
293 " }", | 295 " }", |
294 request_->url().spec().c_str(), | 296 request_->url().spec().c_str(), |
295 download_id_.local(), | 297 download_id_.local(), |
296 global_id_.child_id, | 298 global_id_.child_id, |
297 global_id_.request_id, | 299 global_id_.request_id, |
298 render_view_id_, | 300 render_view_id_, |
299 save_info_.file_path.value().c_str()); | 301 save_info_.file_path.value().c_str()); |
300 } | 302 } |
OLD | NEW |