Chromium Code Reviews| Index: content/browser/download/download_job_factory.cc |
| diff --git a/content/browser/download/download_job_factory.cc b/content/browser/download/download_job_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3c80b7c04718b0a57480ed59ff0f5db2ffb35ce7 |
| --- /dev/null |
| +++ b/content/browser/download/download_job_factory.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/download/download_job_factory.h" |
| + |
| +#include <memory> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "content/browser/download/download_item_impl.h" |
| +#include "content/browser/download/download_job.h" |
| +#include "content/browser/download/download_job_impl.h" |
| +#include "content/browser/download/parallel_download_job.h" |
| +#include "content/public/common/content_features.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +// Default minimum file size in bytes to enable a parallel download. |
| +const int64_t kMinFileSizeParallelDownload = 2048; |
|
qinmin
2017/02/23 07:26:57
Bytes or KB? 2048 bytes is too small to kick off p
xingliu
2017/02/24 23:43:13
Done, yeah, make sense.
|
| + |
| +bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { |
| + // 1. Accept-Ranges, Content-Length and strong validators response headers. |
| + // 2. Feature |kParallelDownloading| enabled. |
| + // 3. Content-Length is no less than |kMinFileSizeParallelDownload|. |
| + // 3. (Undetermined) Http/1.1 protocol. |
| + // 4. (Undetermined) Not under http proxy, e.g. data saver. |
| + |
| + // Etag and last modified are stored into DownloadCreateInfo in |
| + // DownloadRequestCore only if the response header complies to the strong |
| + // validator rule. |
| + bool has_strong_validator = |
| + !create_info.etag.empty() || !create_info.last_modified.empty(); |
| + |
| + return has_strong_validator && create_info.accept_range && |
| + create_info.total_bytes >= kMinFileSizeParallelDownload && |
| + base::FeatureList::IsEnabled(features::kParallelDownloading); |
| +} |
| + |
| +} // namespace |
| + |
| +std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( |
| + DownloadItemImpl* download_item, |
| + std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
| + const DownloadCreateInfo& create_info) { |
| + std::unique_ptr<DownloadJob> job; |
|
qinmin
2017/02/23 07:26:57
seems this is not needed
xingliu
2017/02/24 23:43:13
Done. Sorry I should change it in the previous pat
|
| + |
| + // Build parallel download job. |
| + if (ShouldUseParallelDownload(create_info)) { |
| + return base::MakeUnique<ParallelDownloadJob>(download_item, |
| + std::move(req_handle)); |
| + } |
| + |
| + // An ordinary download job. |
| + job = base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle)); |
| + return job; |
| +} |
| + |
| +} // namespace |