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 "chrome/browser/download/download_util.h" | |
14 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
15 #include "content/browser/download/download_create_info.h" | 14 #include "content/browser/download/download_create_info.h" |
16 #include "content/browser/download/download_file_manager.h" | 15 #include "content/browser/download/download_file_manager.h" |
17 #include "content/browser/download/download_item.h" | 16 #include "content/browser/download/download_item.h" |
18 #include "content/browser/download/download_request_handle.h" | 17 #include "content/browser/download/download_request_handle.h" |
| 18 #include "content/browser/download/download_stats.h" |
19 #include "content/browser/renderer_host/global_request_id.h" | 19 #include "content/browser/renderer_host/global_request_id.h" |
20 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 20 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
22 #include "content/common/resource_response.h" | 22 #include "content/common/resource_response.h" |
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 DownloadFileManager* download_file_manager, | 33 DownloadFileManager* download_file_manager, |
34 net::URLRequest* request, | 34 net::URLRequest* request, |
35 bool save_as, | 35 bool save_as, |
36 const DownloadSaveInfo& save_info) | 36 const DownloadSaveInfo& save_info) |
37 : download_id_(-1), | 37 : download_id_(-1), |
38 global_id_(render_process_host_id, request_id), | 38 global_id_(render_process_host_id, request_id), |
39 render_view_id_(render_view_id), | 39 render_view_id_(render_view_id), |
40 content_length_(0), | 40 content_length_(0), |
41 download_file_manager_(download_file_manager), | 41 download_file_manager_(download_file_manager), |
42 request_(request), | 42 request_(request), |
43 save_as_(save_as), | 43 save_as_(save_as), |
44 save_info_(save_info), | 44 save_info_(save_info), |
45 buffer_(new DownloadBuffer), | 45 buffer_(new DownloadBuffer), |
46 rdh_(rdh), | 46 rdh_(rdh), |
47 is_paused_(false) { | 47 is_paused_(false) { |
48 download_util::RecordDownloadCount(download_util::UNTHROTTLED_COUNT); | 48 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); |
49 } | 49 } |
50 | 50 |
51 bool DownloadResourceHandler::OnUploadProgress(int request_id, | 51 bool DownloadResourceHandler::OnUploadProgress(int request_id, |
52 uint64 position, | 52 uint64 position, |
53 uint64 size) { | 53 uint64 size) { |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 // Not needed, as this event handler ought to be the final resource. | 57 // Not needed, as this event handler ought to be the final resource. |
58 bool DownloadResourceHandler::OnRequestRedirected(int request_id, | 58 bool DownloadResourceHandler::OnRequestRedirected(int request_id, |
(...skipping 29 matching lines...) Expand all Loading... |
88 info->total_bytes = content_length_; | 88 info->total_bytes = content_length_; |
89 info->state = DownloadItem::IN_PROGRESS; | 89 info->state = DownloadItem::IN_PROGRESS; |
90 info->download_id = download_id_; | 90 info->download_id = download_id_; |
91 info->has_user_gesture = request_info->has_user_gesture(); | 91 info->has_user_gesture = request_info->has_user_gesture(); |
92 info->request_handle = DownloadRequestHandle(rdh_, | 92 info->request_handle = DownloadRequestHandle(rdh_, |
93 global_id_.child_id, | 93 global_id_.child_id, |
94 render_view_id_, | 94 render_view_id_, |
95 global_id_.request_id); | 95 global_id_.request_id); |
96 info->content_disposition = content_disposition_; | 96 info->content_disposition = content_disposition_; |
97 info->mime_type = response->response_head.mime_type; | 97 info->mime_type = response->response_head.mime_type; |
98 download_util::RecordDownloadMimeType(info->mime_type); | 98 download_stats::RecordDownloadMimeType(info->mime_type); |
99 // 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 |
100 // resume downloading. | 100 // resume downloading. |
101 | 101 |
102 std::string content_type_header; | 102 std::string content_type_header; |
103 if (!response->response_head.headers || | 103 if (!response->response_head.headers || |
104 !response->response_head.headers->GetMimeType(&content_type_header)) | 104 !response->response_head.headers->GetMimeType(&content_type_header)) |
105 content_type_header = ""; | 105 content_type_header = ""; |
106 info->original_mime_type = content_type_header; | 106 info->original_mime_type = content_type_header; |
107 | 107 |
108 info->prompt_user_for_save_location = | 108 info->prompt_user_for_save_location = |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 " render_view_id_ = " "%d" | 256 " render_view_id_ = " "%d" |
257 " save_info_.file_path = \"%" PRFilePath "\"" | 257 " save_info_.file_path = \"%" PRFilePath "\"" |
258 " }", | 258 " }", |
259 request_->url().spec().c_str(), | 259 request_->url().spec().c_str(), |
260 download_id_, | 260 download_id_, |
261 global_id_.child_id, | 261 global_id_.child_id, |
262 global_id_.request_id, | 262 global_id_.request_id, |
263 render_view_id_, | 263 render_view_id_, |
264 save_info_.file_path.value().c_str()); | 264 save_info_.file_path.value().c_str()); |
265 } | 265 } |
OLD | NEW |