OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 if (!started_cb.is_null()) | 76 if (!started_cb.is_null()) |
77 started_cb.Run(download_id, net::OK); | 77 started_cb.Run(download_id, net::OK); |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 DownloadResourceHandler::DownloadResourceHandler( | 82 DownloadResourceHandler::DownloadResourceHandler( |
83 net::URLRequest* request, | 83 net::URLRequest* request, |
84 const DownloadResourceHandler::OnStartedCallback& started_cb, | 84 const DownloadResourceHandler::OnStartedCallback& started_cb, |
85 const content::DownloadSaveInfo& save_info) | 85 scoped_ptr<content::DownloadSaveInfo> save_info) |
86 : render_view_id_(0), // Actually initialized below. | 86 : render_view_id_(0), // Actually initialized below. |
87 content_length_(0), | 87 content_length_(0), |
88 request_(request), | 88 request_(request), |
89 started_cb_(started_cb), | 89 started_cb_(started_cb), |
90 save_info_(save_info), | 90 save_info_(save_info.Pass()), |
91 last_buffer_size_(0), | 91 last_buffer_size_(0), |
92 bytes_read_(0), | 92 bytes_read_(0), |
93 pause_count_(0), | 93 pause_count_(0), |
94 was_deferred_(false), | 94 was_deferred_(false), |
95 on_response_started_called_(false) { | 95 on_response_started_called_(false) { |
96 ResourceRequestInfoImpl* info(ResourceRequestInfoImpl::ForRequest(request)); | 96 ResourceRequestInfoImpl* info(ResourceRequestInfoImpl::ForRequest(request)); |
97 global_id_ = info->GetGlobalRequestID(); | 97 global_id_ = info->GetGlobalRequestID(); |
98 render_view_id_ = info->GetRouteID(); | 98 render_view_id_ = info->GetRouteID(); |
99 | 99 |
100 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); | 100 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 CreateByteStream( | 152 CreateByteStream( |
153 base::MessageLoopProxy::current(), | 153 base::MessageLoopProxy::current(), |
154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
155 kDownloadByteStreamSize, &stream_writer_, &stream_reader); | 155 kDownloadByteStreamSize, &stream_writer_, &stream_reader); |
156 stream_writer_->RegisterCallback( | 156 stream_writer_->RegisterCallback( |
157 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); | 157 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); |
158 | 158 |
159 info->url_chain = request_->url_chain(); | 159 info->url_chain = request_->url_chain(); |
160 info->referrer_url = GURL(request_->referrer()); | 160 info->referrer_url = GURL(request_->referrer()); |
161 info->start_time = base::Time::Now(); | 161 info->start_time = base::Time::Now(); |
162 info->received_bytes = save_info_.offset; | 162 info->received_bytes = save_info_->offset; |
163 info->total_bytes = content_length_; | 163 info->total_bytes = content_length_; |
164 info->state = DownloadItem::IN_PROGRESS; | 164 info->state = DownloadItem::IN_PROGRESS; |
165 info->has_user_gesture = request_info->HasUserGesture(); | 165 info->has_user_gesture = request_info->HasUserGesture(); |
166 info->content_disposition = content_disposition_; | 166 info->content_disposition = content_disposition_; |
167 info->mime_type = response->head.mime_type; | 167 info->mime_type = response->head.mime_type; |
168 info->remote_address = request_->GetSocketAddress().host(); | 168 info->remote_address = request_->GetSocketAddress().host(); |
169 download_stats::RecordDownloadMimeType(info->mime_type); | 169 download_stats::RecordDownloadMimeType(info->mime_type); |
170 | 170 |
171 info->request_handle = | 171 info->request_handle = |
172 DownloadRequestHandle(AsWeakPtr(), global_id_.child_id, | 172 DownloadRequestHandle(AsWeakPtr(), global_id_.child_id, |
(...skipping 16 matching lines...) Expand all Loading... |
189 content_type_header = ""; | 189 content_type_header = ""; |
190 info->original_mime_type = content_type_header; | 190 info->original_mime_type = content_type_header; |
191 | 191 |
192 if (!response->head.headers || | 192 if (!response->head.headers || |
193 !response->head.headers->EnumerateHeader( | 193 !response->head.headers->EnumerateHeader( |
194 NULL, "Accept-Ranges", &accept_ranges_)) { | 194 NULL, "Accept-Ranges", &accept_ranges_)) { |
195 accept_ranges_ = ""; | 195 accept_ranges_ = ""; |
196 } | 196 } |
197 | 197 |
198 info->prompt_user_for_save_location = | 198 info->prompt_user_for_save_location = |
199 save_info_.prompt_for_save_location && save_info_.file_path.empty(); | 199 save_info_->prompt_for_save_location && save_info_->file_path.empty(); |
200 info->referrer_charset = request_->context()->referrer_charset(); | 200 info->referrer_charset = request_->context()->referrer_charset(); |
201 info->save_info = save_info_; | 201 info->save_info = save_info_.Pass(); |
202 | 202 |
203 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
204 BrowserThread::UI, FROM_HERE, | 204 BrowserThread::UI, FROM_HERE, |
205 base::Bind(&StartOnUIThread, | 205 base::Bind(&StartOnUIThread, |
206 base::Passed(info.Pass()), | 206 base::Passed(info.Pass()), |
207 base::Passed(stream_reader.Pass()), | 207 base::Passed(stream_reader.Pass()), |
208 // Pass to StartOnUIThread so that variable | 208 // Pass to StartOnUIThread so that variable |
209 // access is always on IO thread but function | 209 // access is always on IO thread but function |
210 // is called on UI thread. | 210 // is called on UI thread. |
211 started_cb_)); | 211 started_cb_)); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 421 } |
422 | 422 |
423 std::string DownloadResourceHandler::DebugString() const { | 423 std::string DownloadResourceHandler::DebugString() const { |
424 return base::StringPrintf("{" | 424 return base::StringPrintf("{" |
425 " url_ = " "\"%s\"" | 425 " url_ = " "\"%s\"" |
426 " global_id_ = {" | 426 " global_id_ = {" |
427 " child_id = " "%d" | 427 " child_id = " "%d" |
428 " request_id = " "%d" | 428 " request_id = " "%d" |
429 " }" | 429 " }" |
430 " render_view_id_ = " "%d" | 430 " render_view_id_ = " "%d" |
431 " save_info_.file_path = \"%" PRFilePath "\"" | |
432 " }", | 431 " }", |
433 request_ ? | 432 request_ ? |
434 request_->url().spec().c_str() : | 433 request_->url().spec().c_str() : |
435 "<NULL request>", | 434 "<NULL request>", |
436 global_id_.child_id, | 435 global_id_.child_id, |
437 global_id_.request_id, | 436 global_id_.request_id, |
438 render_view_id_, | 437 render_view_id_); |
439 save_info_.file_path.value().c_str()); | |
440 } | 438 } |
441 | 439 |
442 DownloadResourceHandler::~DownloadResourceHandler() { | 440 DownloadResourceHandler::~DownloadResourceHandler() { |
443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
444 | 442 |
445 // This won't do anything if the callback was called before. | 443 // This won't do anything if the callback was called before. |
446 // If it goes through, it will likely be because OnWillStart() returned | 444 // If it goes through, it will likely be because OnWillStart() returned |
447 // false somewhere in the chain of resource handlers. | 445 // false somewhere in the chain of resource handlers. |
448 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); | 446 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); |
449 | 447 |
450 // Remove output stream callback if a stream exists. | 448 // Remove output stream callback if a stream exists. |
451 if (stream_writer_.get()) | 449 if (stream_writer_.get()) |
452 stream_writer_->RegisterCallback(base::Closure()); | 450 stream_writer_->RegisterCallback(base::Closure()); |
453 | 451 |
454 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 452 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
455 base::TimeTicks::Now() - download_start_time_); | 453 base::TimeTicks::Now() - download_start_time_); |
456 } | 454 } |
OLD | NEW |