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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/metrics/stats_counters.h" | 12 #include "base/metrics/stats_counters.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.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_stats.h" | 19 #include "content/browser/download/download_stats.h" |
20 #include "content/browser/download/interrupt_reasons.h" | 20 #include "content/browser/download/interrupt_reasons.h" |
21 #include "content/browser/renderer_host/global_request_id.h" | 21 #include "content/browser/renderer_host/global_request_id.h" |
22 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 22 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
23 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 23 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
24 #include "content/common/resource_response.h" | |
25 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/common/resource_response.h" |
26 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
28 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
29 #include "net/url_request/url_request_context.h" | 29 #include "net/url_request/url_request_context.h" |
30 | 30 |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
32 | 32 |
33 DownloadResourceHandler::DownloadResourceHandler( | 33 DownloadResourceHandler::DownloadResourceHandler( |
34 ResourceDispatcherHost* rdh, | 34 ResourceDispatcherHost* rdh, |
35 int render_process_host_id, | 35 int render_process_host_id, |
(...skipping 22 matching lines...) Expand all Loading... |
58 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); | 58 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); |
59 } | 59 } |
60 | 60 |
61 bool DownloadResourceHandler::OnUploadProgress(int request_id, | 61 bool DownloadResourceHandler::OnUploadProgress(int request_id, |
62 uint64 position, | 62 uint64 position, |
63 uint64 size) { | 63 uint64 size) { |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 // Not needed, as this event handler ought to be the final resource. | 67 // Not needed, as this event handler ought to be the final resource. |
68 bool DownloadResourceHandler::OnRequestRedirected(int request_id, | 68 bool DownloadResourceHandler::OnRequestRedirected( |
69 const GURL& url, | 69 int request_id, |
70 ResourceResponse* response, | 70 const GURL& url, |
71 bool* defer) { | 71 content::ResourceResponse* response, |
| 72 bool* defer) { |
72 return true; | 73 return true; |
73 } | 74 } |
74 | 75 |
75 // Send the download creation information to the download thread. | 76 // Send the download creation information to the download thread. |
76 bool DownloadResourceHandler::OnResponseStarted(int request_id, | 77 bool DownloadResourceHandler::OnResponseStarted( |
77 ResourceResponse* response) { | 78 int request_id, |
| 79 content::ResourceResponse* response) { |
78 DCHECK(download_id_.IsValid()); | 80 DCHECK(download_id_.IsValid()); |
79 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 81 VLOG(20) << __FUNCTION__ << "()" << DebugString() |
80 << " request_id = " << request_id; | 82 << " request_id = " << request_id; |
81 download_start_time_ = base::TimeTicks::Now(); | 83 download_start_time_ = base::TimeTicks::Now(); |
82 | 84 |
83 // If it's a download, we don't want to poison the cache with it. | 85 // If it's a download, we don't want to poison the cache with it. |
84 request_->StopCaching(); | 86 request_->StopCaching(); |
85 | 87 |
86 std::string content_disposition; | 88 std::string content_disposition; |
87 request_->GetResponseHeaderByName("content-disposition", | 89 request_->GetResponseHeaderByName("content-disposition", |
88 &content_disposition); | 90 &content_disposition); |
89 set_content_disposition(content_disposition); | 91 set_content_disposition(content_disposition); |
90 set_content_length(response->response_head.content_length); | 92 set_content_length(response->content_length); |
91 | 93 |
92 const ResourceDispatcherHostRequestInfo* request_info = | 94 const ResourceDispatcherHostRequestInfo* request_info = |
93 ResourceDispatcherHost::InfoForRequest(request_); | 95 ResourceDispatcherHost::InfoForRequest(request_); |
94 | 96 |
95 // Deleted in DownloadManager. | 97 // Deleted in DownloadManager. |
96 DownloadCreateInfo* info = new DownloadCreateInfo(FilePath(), GURL(), | 98 DownloadCreateInfo* info = new DownloadCreateInfo(FilePath(), GURL(), |
97 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, | 99 base::Time::Now(), 0, content_length_, DownloadItem::IN_PROGRESS, |
98 download_id_, request_info->has_user_gesture(), | 100 download_id_, request_info->has_user_gesture(), |
99 request_info->transition_type()); | 101 request_info->transition_type()); |
100 info->url_chain = request_->url_chain(); | 102 info->url_chain = request_->url_chain(); |
101 info->referrer_url = GURL(request_->referrer()); | 103 info->referrer_url = GURL(request_->referrer()); |
102 info->start_time = base::Time::Now(); | 104 info->start_time = base::Time::Now(); |
103 info->received_bytes = 0; | 105 info->received_bytes = 0; |
104 info->total_bytes = content_length_; | 106 info->total_bytes = content_length_; |
105 info->state = DownloadItem::IN_PROGRESS; | 107 info->state = DownloadItem::IN_PROGRESS; |
106 info->download_id = download_id_; | 108 info->download_id = download_id_; |
107 info->has_user_gesture = request_info->has_user_gesture(); | 109 info->has_user_gesture = request_info->has_user_gesture(); |
108 info->content_disposition = content_disposition_; | 110 info->content_disposition = content_disposition_; |
109 info->mime_type = response->response_head.mime_type; | 111 info->mime_type = response->mime_type; |
110 download_stats::RecordDownloadMimeType(info->mime_type); | 112 download_stats::RecordDownloadMimeType(info->mime_type); |
111 | 113 |
112 DownloadRequestHandle request_handle(rdh_, global_id_.child_id, | 114 DownloadRequestHandle request_handle(rdh_, global_id_.child_id, |
113 render_view_id_, global_id_.request_id); | 115 render_view_id_, global_id_.request_id); |
114 | 116 |
115 // TODO(ahendrickson) -- Get the last modified time and etag, so we can | 117 // TODO(ahendrickson) -- Get the last modified time and etag, so we can |
116 // resume downloading. | 118 // resume downloading. |
117 | 119 |
118 CallStartedCB(net::OK); | 120 CallStartedCB(net::OK); |
119 | 121 |
120 std::string content_type_header; | 122 std::string content_type_header; |
121 if (!response->response_head.headers || | 123 if (!response->headers || |
122 !response->response_head.headers->GetMimeType(&content_type_header)) | 124 !response->headers->GetMimeType(&content_type_header)) |
123 content_type_header = ""; | 125 content_type_header = ""; |
124 info->original_mime_type = content_type_header; | 126 info->original_mime_type = content_type_header; |
125 | 127 |
126 info->prompt_user_for_save_location = | 128 info->prompt_user_for_save_location = |
127 save_as_ && save_info_.file_path.empty(); | 129 save_as_ && save_info_.file_path.empty(); |
128 info->referrer_charset = request_->context()->referrer_charset(); | 130 info->referrer_charset = request_->context()->referrer_charset(); |
129 info->save_info = save_info_; | 131 info->save_info = save_info_; |
130 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
131 BrowserThread::UI, FROM_HERE, | 133 BrowserThread::UI, FROM_HERE, |
132 base::Bind(&DownloadFileManager::StartDownload, | 134 base::Bind(&DownloadFileManager::StartDownload, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 " render_view_id_ = " "%d" | 310 " render_view_id_ = " "%d" |
309 " save_info_.file_path = \"%" PRFilePath "\"" | 311 " save_info_.file_path = \"%" PRFilePath "\"" |
310 " }", | 312 " }", |
311 request_->url().spec().c_str(), | 313 request_->url().spec().c_str(), |
312 download_id_.local(), | 314 download_id_.local(), |
313 global_id_.child_id, | 315 global_id_.child_id, |
314 global_id_.request_id, | 316 global_id_.request_id, |
315 render_view_id_, | 317 render_view_id_, |
316 save_info_.file_path.value().c_str()); | 318 save_info_.file_path.value().c_str()); |
317 } | 319 } |
OLD | NEW |