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