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_request_core.h" | 5 #include "content/browser/download/download_request_core.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 was_deferred_(false), | 200 was_deferred_(false), |
201 is_partial_request_(false), | 201 is_partial_request_(false), |
202 started_(false), | 202 started_(false), |
203 abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) { | 203 abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) { |
204 DCHECK(request_); | 204 DCHECK(request_); |
205 DCHECK(delegate_); | 205 DCHECK(delegate_); |
206 RecordDownloadCount(UNTHROTTLED_COUNT); | 206 RecordDownloadCount(UNTHROTTLED_COUNT); |
207 power_save_blocker_.reset(new device::PowerSaveBlocker( | 207 power_save_blocker_.reset(new device::PowerSaveBlocker( |
208 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 208 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
209 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 209 device::PowerSaveBlocker::kReasonOther, "Download in progress", |
210 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 210 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
211 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 211 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
212 DownloadRequestData* request_data = DownloadRequestData::Get(request_); | 212 DownloadRequestData* request_data = DownloadRequestData::Get(request_); |
213 if (request_data) { | 213 if (request_data) { |
214 save_info_ = request_data->TakeSaveInfo(); | 214 save_info_ = request_data->TakeSaveInfo(); |
215 download_id_ = request_data->download_id(); | 215 download_id_ = request_data->download_id(); |
216 on_started_callback_ = request_data->callback(); | 216 on_started_callback_ = request_data->callback(); |
217 DownloadRequestData::Detach(request_); | 217 DownloadRequestData::Detach(request_); |
218 is_partial_request_ = save_info_->offset > 0; | 218 is_partial_request_ = save_info_->offset > 0; |
219 } else { | 219 } else { |
220 save_info_.reset(new DownloadSaveInfo); | 220 save_info_.reset(new DownloadSaveInfo); |
221 } | 221 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // If the content-length header is not present (or contains something other | 278 // If the content-length header is not present (or contains something other |
279 // than numbers), the incoming content_length is -1 (unknown size). | 279 // than numbers), the incoming content_length is -1 (unknown size). |
280 // Set the content length to 0 to indicate unknown size to DownloadManager. | 280 // Set the content length to 0 to indicate unknown size to DownloadManager. |
281 int64_t content_length = request()->GetExpectedContentSize() > 0 | 281 int64_t content_length = request()->GetExpectedContentSize() > 0 |
282 ? request()->GetExpectedContentSize() | 282 ? request()->GetExpectedContentSize() |
283 : 0; | 283 : 0; |
284 create_info->total_bytes = content_length; | 284 create_info->total_bytes = content_length; |
285 | 285 |
286 // Create the ByteStream for sending data to the download sink. | 286 // Create the ByteStream for sending data to the download sink. |
287 std::unique_ptr<ByteStreamReader> stream_reader; | 287 std::unique_ptr<ByteStreamReader> stream_reader; |
288 CreateByteStream( | 288 CreateByteStream(base::ThreadTaskRunnerHandle::Get(), |
289 base::ThreadTaskRunnerHandle::Get(), | 289 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
290 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 290 kDownloadByteStreamSize, &stream_writer_, &stream_reader); |
291 kDownloadByteStreamSize, &stream_writer_, &stream_reader); | |
292 stream_writer_->RegisterCallback( | 291 stream_writer_->RegisterCallback( |
293 base::Bind(&DownloadRequestCore::ResumeRequest, AsWeakPtr())); | 292 base::Bind(&DownloadRequestCore::ResumeRequest, AsWeakPtr())); |
294 | 293 |
295 if (!override_mime_type.empty()) | 294 if (!override_mime_type.empty()) |
296 create_info->mime_type = override_mime_type; | 295 create_info->mime_type = override_mime_type; |
297 else | 296 else |
298 request()->GetMimeType(&create_info->mime_type); | 297 request()->GetMimeType(&create_info->mime_type); |
299 | 298 |
300 // Get the last modified time and etag. | 299 // Get the last modified time and etag. |
301 const net::HttpResponseHeaders* headers = request()->response_headers(); | 300 const net::HttpResponseHeaders* headers = request()->response_headers(); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return DOWNLOAD_INTERRUPT_REASON_NONE; | 628 return DOWNLOAD_INTERRUPT_REASON_NONE; |
630 } | 629 } |
631 | 630 |
632 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) | 631 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) |
633 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; | 632 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
634 | 633 |
635 return DOWNLOAD_INTERRUPT_REASON_NONE; | 634 return DOWNLOAD_INTERRUPT_REASON_NONE; |
636 } | 635 } |
637 | 636 |
638 } // namespace content | 637 } // namespace content |
OLD | NEW |