| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/parallel_download_job.h" | 5 #include "content/browser/download/parallel_download_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 void ParallelDownloadJob::CreateRequest(int64_t offset, int64_t length) { | 202 void ParallelDownloadJob::CreateRequest(int64_t offset, int64_t length) { |
| 203 DCHECK(download_item_); | 203 DCHECK(download_item_); |
| 204 | 204 |
| 205 std::unique_ptr<DownloadWorker> worker = | 205 std::unique_ptr<DownloadWorker> worker = |
| 206 base::MakeUnique<DownloadWorker>(this, offset, length); | 206 base::MakeUnique<DownloadWorker>(this, offset, length); |
| 207 | 207 |
| 208 StoragePartition* storage_partition = | 208 StoragePartition* storage_partition = |
| 209 BrowserContext::GetStoragePartitionForSite( | 209 BrowserContext::GetStoragePartitionForSite( |
| 210 download_item_->GetBrowserContext(), download_item_->GetSiteUrl()); | 210 download_item_->GetBrowserContext(), download_item_->GetSiteUrl()); |
| 211 | 211 |
| 212 // The parallel requests only use GET method. |
| 212 std::unique_ptr<DownloadUrlParameters> download_params( | 213 std::unique_ptr<DownloadUrlParameters> download_params( |
| 213 new DownloadUrlParameters(download_item_->GetURL(), | 214 new DownloadUrlParameters(download_item_->GetURL(), |
| 214 storage_partition->GetURLRequestContext())); | 215 storage_partition->GetURLRequestContext())); |
| 215 download_params->set_file_path(download_item_->GetFullPath()); | 216 download_params->set_file_path(download_item_->GetFullPath()); |
| 216 download_params->set_last_modified(download_item_->GetLastModifiedTime()); | 217 download_params->set_last_modified(download_item_->GetLastModifiedTime()); |
| 217 download_params->set_etag(download_item_->GetETag()); | 218 download_params->set_etag(download_item_->GetETag()); |
| 218 download_params->set_offset(offset); | 219 download_params->set_offset(offset); |
| 219 | 220 |
| 220 // Setting the length will result in range request to fetch a slice of the | 221 // Setting the length will result in range request to fetch a slice of the |
| 221 // file. | 222 // file. |
| 222 download_params->set_length(length); | 223 download_params->set_length(length); |
| 223 | 224 |
| 224 // Subsequent range requests don't need the "If-Range" header. | 225 // Subsequent range requests don't need the "If-Range" header. |
| 225 download_params->set_use_if_range(false); | 226 download_params->set_use_if_range(false); |
| 226 | 227 |
| 227 // Subsequent range requests have the same referrer URL as the original | 228 // Subsequent range requests have the same referrer URL as the original |
| 228 // download request. | 229 // download request. |
| 229 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 230 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 230 blink::kWebReferrerPolicyAlways)); | 231 blink::kWebReferrerPolicyAlways)); |
| 231 // Send the request. | 232 // Send the request. |
| 232 worker->SendRequest(std::move(download_params)); | 233 worker->SendRequest(std::move(download_params)); |
| 233 DCHECK(workers_.find(offset) == workers_.end()); | 234 DCHECK(workers_.find(offset) == workers_.end()); |
| 234 workers_[offset] = std::move(worker); | 235 workers_[offset] = std::move(worker); |
| 235 } | 236 } |
| 236 | 237 |
| 237 } // namespace content | 238 } // namespace content |
| OLD | NEW |