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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: Make windows compiler happy. 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..4733b34ab4af8744392ee7d99c96ff2c0766b22b
--- /dev/null
+++ b/content/browser/download/parallel_download_job.h
@@ -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.
+
+#ifndef CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
+#define CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
+
+#include "base/macros.h"
+#include "content/browser/download/download_url_job.h"
+#include "content/browser/download/download_url_task.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+class DownloadUrlTask;
+
+// 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 DownloadUrlJob {
+ public:
+ typedef std::vector<std::unique_ptr<DownloadUrlTask>> TaskList;
+
+ ParallelDownloadJob(
+ std::unique_ptr<DownloadRequestHandleInterface> request_handle);
asanka 2017/02/16 16:27:39 explicit
xingliu 2017/02/20 18:59:11 Done. Same as DownloadUrlJob, now it also pass Dow
+ ~ParallelDownloadJob() override;
+
+ // DownloadUrlJob implementation.
+ void Cancel(bool user_cancel) override;
+ void Pause() override;
+ void Resume() override;
+
+ private:
+ friend class ParallelDownloadJobTest;
+
+ // Create multiple http connections, the rest of the bytes will be equally
+ // distributed to each connection, the last connection may take additional
+ // bytes.
+ void ForkParallelRequests(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_;
+
+ // Subsequent tasks to send range requests.
+ TaskList tasks_;
+
+ DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698