Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Unified Diff: content/browser/download/parallel_download_job.h

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: Polish some details. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/download/parallel_download_job.h
diff --git a/content/browser/download/parallel_download_job.h b/content/browser/download/parallel_download_job.h
new file mode 100644
index 0000000000000000000000000000000000000000..3075303d704b566ffe845a3a5cb8009b7c35ff2e
--- /dev/null
+++ b/content/browser/download/parallel_download_job.h
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
+#define CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/macros.h"
+#include "content/browser/download/download_job_impl.h"
+#include "content/browser/download/download_worker.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+// DownloadJob that can create concurrent range requests to fetch different
+// parts of the file.
+// The original request is hold in base class DownloadUrlJob.
+class CONTENT_EXPORT ParallelDownloadJob : public DownloadJobImpl {
+ public:
+ typedef std::vector<std::unique_ptr<DownloadWorker>> WorkerList;
+
+ ParallelDownloadJob(
+ DownloadItemImpl* download_item,
+ std::unique_ptr<DownloadRequestHandleInterface> request_handle);
+ ~ParallelDownloadJob() override;
+
+ // DownloadUrlJob implementation.
+ void Cancel(bool user_cancel) override;
+ void Pause() override;
+ void Resume() override;
+
+ private:
+ friend class ParallelDownloadJobTest;
+
+ // Build multiple http requests for a new download,
+ // the rest of the bytes starting from |bytes_received| will be equally
+ // distributed to each connection, including the original connection.
+ // the last connection may take additional bytes.
+ void ForkRequestsForNewDownload(int64_t bytes_received, int64_t total_bytes);
+
+ // Create one range request, virtual for testing.
+ virtual void CreateRequest(int64_t offset, int64_t length);
+
+ // Number of concurrent requests, include the original request.
+ // Actual number of requests may be less than this, due to |min_length_|.
+ int request_num_;
+
+ // Minimum length for each range request. Requests with only a few bytes are
+ // not preferred.
+ int64_t min_length_;
qinmin 2017/02/22 19:51:23 why is this a member variable? it feels like this
xingliu 2017/02/22 21:22:41 Done. Thanks for this suggestion. Yeah, this one
+
+ // Subsequent tasks to send range requests.
+ WorkerList workers_;
+
+ DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698