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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
6 #define CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "content/browser/download/download_job_impl.h"
13 #include "content/browser/download/download_worker.h"
14 #include "content/common/content_export.h"
15
16 namespace content {
17
18 // DownloadJob that can create concurrent range requests to fetch different
19 // parts of the file.
20 // The original request is hold in base class DownloadUrlJob.
21 class CONTENT_EXPORT ParallelDownloadJob : public DownloadJobImpl {
22 public:
23 typedef std::vector<std::unique_ptr<DownloadWorker>> WorkerList;
24
25 ParallelDownloadJob(
26 DownloadItemImpl* download_item,
27 std::unique_ptr<DownloadRequestHandleInterface> request_handle);
28 ~ParallelDownloadJob() override;
29
30 // DownloadUrlJob implementation.
31 void Cancel(bool user_cancel) override;
32 void Pause() override;
33 void Resume() override;
34
35 private:
36 friend class ParallelDownloadJobTest;
37
38 // Build multiple http requests for a new download,
39 // the rest of the bytes starting from |bytes_received| will be equally
40 // distributed to each connection, including the original connection.
41 // the last connection may take additional bytes.
42 void ForkRequestsForNewDownload(int64_t bytes_received, int64_t total_bytes);
43
44 // Create one range request, virtual for testing.
45 virtual void CreateRequest(int64_t offset, int64_t length);
46
47 // Number of concurrent requests, include the original request.
48 // Actual number of requests may be less than this, due to |min_length_|.
49 int request_num_;
50
51 // Minimum length for each range request. Requests with only a few bytes are
52 // not preferred.
53 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
54
55 // Subsequent tasks to send range requests.
56 WorkerList workers_;
57
58 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob);
59 };
60
61 } // namespace content
62
63 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698