OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_thread.h" | 8 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/browser/download/download_item.h" | 9 #include "chrome/browser/download/download_item.h" |
10 #include "chrome/browser/download/download_file_manager.h" | 10 #include "chrome/browser/download/download_file_manager.h" |
11 #include "chrome/browser/history/download_create_info.h" | 11 #include "chrome/browser/history/download_create_info.h" |
12 #include "chrome/browser/renderer_host/global_request_id.h" | 12 #include "chrome/browser/renderer_host/global_request_id.h" |
13 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 13 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 14 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
14 #include "chrome/common/resource_response.h" | 15 #include "chrome/common/resource_response.h" |
15 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
16 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
18 | 19 |
19 DownloadResourceHandler::DownloadResourceHandler( | 20 DownloadResourceHandler::DownloadResourceHandler( |
20 ResourceDispatcherHost* rdh, | 21 ResourceDispatcherHost* rdh, |
21 int render_process_host_id, | 22 int render_process_host_id, |
22 int render_view_id, | 23 int render_view_id, |
23 int request_id, | 24 int request_id, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 // Send the download creation information to the download thread. | 59 // Send the download creation information to the download thread. |
59 bool DownloadResourceHandler::OnResponseStarted(int request_id, | 60 bool DownloadResourceHandler::OnResponseStarted(int request_id, |
60 ResourceResponse* response) { | 61 ResourceResponse* response) { |
61 std::string content_disposition; | 62 std::string content_disposition; |
62 request_->GetResponseHeaderByName("content-disposition", | 63 request_->GetResponseHeaderByName("content-disposition", |
63 &content_disposition); | 64 &content_disposition); |
64 set_content_disposition(content_disposition); | 65 set_content_disposition(content_disposition); |
65 set_content_length(response->response_head.content_length); | 66 set_content_length(response->response_head.content_length); |
66 | 67 |
| 68 const ResourceDispatcherHostRequestInfo* request_info = |
| 69 ResourceDispatcherHost::InfoForRequest(request_); |
| 70 |
67 download_id_ = download_file_manager_->GetNextId(); | 71 download_id_ = download_file_manager_->GetNextId(); |
68 // |download_file_manager_| consumes (deletes): | 72 // |download_file_manager_| consumes (deletes): |
69 DownloadCreateInfo* info = new DownloadCreateInfo; | 73 DownloadCreateInfo* info = new DownloadCreateInfo; |
70 info->url = url_; | 74 info->url = url_; |
71 info->referrer_url = GURL(request_->referrer()); | 75 info->referrer_url = GURL(request_->referrer()); |
72 info->start_time = base::Time::Now(); | 76 info->start_time = base::Time::Now(); |
73 info->received_bytes = 0; | 77 info->received_bytes = 0; |
74 info->total_bytes = content_length_; | 78 info->total_bytes = content_length_; |
75 info->state = DownloadItem::IN_PROGRESS; | 79 info->state = DownloadItem::IN_PROGRESS; |
76 info->download_id = download_id_; | 80 info->download_id = download_id_; |
| 81 info->has_user_gesture = request_info->has_user_gesture(); |
77 info->child_id = global_id_.child_id; | 82 info->child_id = global_id_.child_id; |
78 info->render_view_id = render_view_id_; | 83 info->render_view_id = render_view_id_; |
79 info->request_id = global_id_.request_id; | 84 info->request_id = global_id_.request_id; |
80 info->content_disposition = content_disposition_; | 85 info->content_disposition = content_disposition_; |
81 info->mime_type = response->response_head.mime_type; | 86 info->mime_type = response->response_head.mime_type; |
82 | 87 |
83 std::string content_type_header; | 88 std::string content_type_header; |
84 if (!response->response_head.headers || | 89 if (!response->response_head.headers || |
85 !response->response_head.headers->GetMimeType(&content_type_header)) | 90 !response->response_head.headers->GetMimeType(&content_type_header)) |
86 content_type_header = ""; | 91 content_type_header = ""; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 214 } |
210 | 215 |
211 DownloadResourceHandler::~DownloadResourceHandler() { | 216 DownloadResourceHandler::~DownloadResourceHandler() { |
212 } | 217 } |
213 | 218 |
214 void DownloadResourceHandler::StartPauseTimer() { | 219 void DownloadResourceHandler::StartPauseTimer() { |
215 if (!pause_timer_.IsRunning()) | 220 if (!pause_timer_.IsRunning()) |
216 pause_timer_.Start(base::TimeDelta::FromMilliseconds(kThrottleTimeMs), this, | 221 pause_timer_.Start(base::TimeDelta::FromMilliseconds(kThrottleTimeMs), this, |
217 &DownloadResourceHandler::CheckWriteProgress); | 222 &DownloadResourceHandler::CheckWriteProgress); |
218 } | 223 } |
OLD | NEW |