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 "chrome/browser/renderer_host/download_resource_handler.h" | 5 #include "chrome/browser/renderer_host/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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
24 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
25 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
26 | 26 |
27 DownloadResourceHandler::DownloadResourceHandler( | 27 DownloadResourceHandler::DownloadResourceHandler( |
28 ResourceDispatcherHost* rdh, | 28 ResourceDispatcherHost* rdh, |
29 int render_process_host_id, | 29 int render_process_host_id, |
30 int render_view_id, | 30 int render_view_id, |
31 int request_id, | 31 int request_id, |
32 const GURL& url, | 32 const GURL& url, |
| 33 DownloadId dl_id, |
33 DownloadFileManager* download_file_manager, | 34 DownloadFileManager* download_file_manager, |
34 net::URLRequest* request, | 35 net::URLRequest* request, |
35 bool save_as, | 36 bool save_as, |
36 const DownloadSaveInfo& save_info) | 37 const DownloadSaveInfo& save_info) |
37 : download_id_(-1), | 38 : download_id_(dl_id), |
38 global_id_(render_process_host_id, request_id), | 39 global_id_(render_process_host_id, request_id), |
39 render_view_id_(render_view_id), | 40 render_view_id_(render_view_id), |
40 content_length_(0), | 41 content_length_(0), |
41 download_file_manager_(download_file_manager), | 42 download_file_manager_(download_file_manager), |
42 request_(request), | 43 request_(request), |
43 save_as_(save_as), | 44 save_as_(save_as), |
44 save_info_(save_info), | 45 save_info_(save_info), |
45 buffer_(new DownloadBuffer), | 46 buffer_(new DownloadBuffer), |
46 rdh_(rdh), | 47 rdh_(rdh), |
47 is_paused_(false) { | 48 is_paused_(false) { |
| 49 DCHECK(dl_id.IsValid()); |
48 download_util::RecordDownloadCount(download_util::UNTHROTTLED_COUNT); | 50 download_util::RecordDownloadCount(download_util::UNTHROTTLED_COUNT); |
49 } | 51 } |
50 | 52 |
51 bool DownloadResourceHandler::OnUploadProgress(int request_id, | 53 bool DownloadResourceHandler::OnUploadProgress(int request_id, |
52 uint64 position, | 54 uint64 position, |
53 uint64 size) { | 55 uint64 size) { |
54 return true; | 56 return true; |
55 } | 57 } |
56 | 58 |
57 // Not needed, as this event handler ought to be the final resource. | 59 // Not needed, as this event handler ought to be the final resource. |
58 bool DownloadResourceHandler::OnRequestRedirected(int request_id, | 60 bool DownloadResourceHandler::OnRequestRedirected(int request_id, |
59 const GURL& url, | 61 const GURL& url, |
60 ResourceResponse* response, | 62 ResourceResponse* response, |
61 bool* defer) { | 63 bool* defer) { |
62 return true; | 64 return true; |
63 } | 65 } |
64 | 66 |
65 // Send the download creation information to the download thread. | 67 // Send the download creation information to the download thread. |
66 bool DownloadResourceHandler::OnResponseStarted(int request_id, | 68 bool DownloadResourceHandler::OnResponseStarted(int request_id, |
67 ResourceResponse* response) { | 69 ResourceResponse* response) { |
| 70 DCHECK(download_id_.IsValid()); |
68 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 71 VLOG(20) << __FUNCTION__ << "()" << DebugString() |
69 << " request_id = " << request_id; | 72 << " request_id = " << request_id; |
70 download_start_time_ = base::TimeTicks::Now(); | 73 download_start_time_ = base::TimeTicks::Now(); |
71 std::string content_disposition; | 74 std::string content_disposition; |
72 request_->GetResponseHeaderByName("content-disposition", | 75 request_->GetResponseHeaderByName("content-disposition", |
73 &content_disposition); | 76 &content_disposition); |
74 set_content_disposition(content_disposition); | 77 set_content_disposition(content_disposition); |
75 set_content_length(response->response_head.content_length); | 78 set_content_length(response->response_head.content_length); |
76 | 79 |
77 const ResourceDispatcherHostRequestInfo* request_info = | 80 const ResourceDispatcherHostRequestInfo* request_info = |
78 ResourceDispatcherHost::InfoForRequest(request_); | 81 ResourceDispatcherHost::InfoForRequest(request_); |
79 | 82 |
80 download_id_ = download_file_manager_->GetNextId(); | |
81 | |
82 // Deleted in DownloadManager. | 83 // Deleted in DownloadManager. |
83 DownloadCreateInfo* info = new DownloadCreateInfo; | 84 DownloadCreateInfo* info = new DownloadCreateInfo; |
84 info->url_chain = request_->url_chain(); | 85 info->url_chain = request_->url_chain(); |
85 info->referrer_url = GURL(request_->referrer()); | 86 info->referrer_url = GURL(request_->referrer()); |
86 info->start_time = base::Time::Now(); | 87 info->start_time = base::Time::Now(); |
87 info->received_bytes = 0; | 88 info->received_bytes = 0; |
88 info->total_bytes = content_length_; | 89 info->total_bytes = content_length_; |
89 info->state = DownloadItem::IN_PROGRESS; | 90 info->state = DownloadItem::IN_PROGRESS; |
90 info->download_id = download_id_; | 91 info->download_id = download_id_.local(); |
91 info->has_user_gesture = request_info->has_user_gesture(); | 92 info->has_user_gesture = request_info->has_user_gesture(); |
92 info->request_handle = DownloadRequestHandle(rdh_, | 93 info->request_handle = DownloadRequestHandle(rdh_, |
93 global_id_.child_id, | 94 global_id_.child_id, |
94 render_view_id_, | 95 render_view_id_, |
95 global_id_.request_id); | 96 global_id_.request_id); |
96 info->content_disposition = content_disposition_; | 97 info->content_disposition = content_disposition_; |
97 info->mime_type = response->response_head.mime_type; | 98 info->mime_type = response->response_head.mime_type; |
98 // TODO(ahendrickson) -- Get the last modified time and etag, so we can | 99 // TODO(ahendrickson) -- Get the last modified time and etag, so we can |
99 // resume downloading. | 100 // resume downloading. |
100 | 101 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 " url_ = " "\"%s\"" | 250 " url_ = " "\"%s\"" |
250 " download_id_ = " "%d" | 251 " download_id_ = " "%d" |
251 " global_id_ = {" | 252 " global_id_ = {" |
252 " child_id = " "%d" | 253 " child_id = " "%d" |
253 " request_id = " "%d" | 254 " request_id = " "%d" |
254 " }" | 255 " }" |
255 " render_view_id_ = " "%d" | 256 " render_view_id_ = " "%d" |
256 " save_info_.file_path = \"%" PRFilePath "\"" | 257 " save_info_.file_path = \"%" PRFilePath "\"" |
257 " }", | 258 " }", |
258 request_->url().spec().c_str(), | 259 request_->url().spec().c_str(), |
259 download_id_, | 260 download_id_.local(), |
260 global_id_.child_id, | 261 global_id_.child_id, |
261 global_id_.request_id, | 262 global_id_.request_id, |
262 render_view_id_, | 263 render_view_id_, |
263 save_info_.file_path.value().c_str()); | 264 save_info_.file_path.value().c_str()); |
264 } | 265 } |
OLD | NEW |