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 #ifndef CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 21 matching lines...) Expand all Loading... |
32 // DownloadJobImpl implementation. | 32 // DownloadJobImpl implementation. |
33 void Start() override; | 33 void Start() override; |
34 void Cancel(bool user_cancel) override; | 34 void Cancel(bool user_cancel) override; |
35 void Pause() override; | 35 void Pause() override; |
36 void Resume(bool resume_request) override; | 36 void Resume(bool resume_request) override; |
37 bool UsesParallelRequests() const override; | 37 bool UsesParallelRequests() const override; |
38 | 38 |
39 protected: | 39 protected: |
40 // Virtual for testing. | 40 // Virtual for testing. |
41 virtual int GetParallelRequestCount() const; | 41 virtual int GetParallelRequestCount() const; |
| 42 virtual int64_t GetMinSliceSize() const; |
42 | 43 |
43 using WorkerMap = | 44 using WorkerMap = |
44 std::unordered_map<int64_t, std::unique_ptr<DownloadWorker>>; | 45 std::unordered_map<int64_t, std::unique_ptr<DownloadWorker>>; |
45 | 46 |
46 // Map from the offset position of the slice to the worker that downloads the | 47 // Map from the offset position of the slice to the worker that downloads the |
47 // slice. | 48 // slice. |
48 WorkerMap workers_; | 49 WorkerMap workers_; |
49 | 50 |
50 private: | 51 private: |
51 friend class ParallelDownloadJobTest; | 52 friend class ParallelDownloadJobTest; |
(...skipping 15 matching lines...) Expand all Loading... |
67 | 68 |
68 // Build one http request for each slice from the second slice. | 69 // Build one http request for each slice from the second slice. |
69 // The first slice represents the original request. | 70 // The first slice represents the original request. |
70 void ForkSubRequests(const DownloadItem::ReceivedSlices& slices_to_download); | 71 void ForkSubRequests(const DownloadItem::ReceivedSlices& slices_to_download); |
71 | 72 |
72 // Create one range request, virtual for testing. | 73 // Create one range request, virtual for testing. |
73 virtual void CreateRequest(int64_t offset, int64_t length); | 74 virtual void CreateRequest(int64_t offset, int64_t length); |
74 | 75 |
75 // Information about the initial request when download is started. | 76 // Information about the initial request when download is started. |
76 int64_t initial_request_offset_; | 77 int64_t initial_request_offset_; |
| 78 int64_t initial_request_length_; |
77 | 79 |
78 // The length of the response body of the original request. May be less than | 80 // The length of the response body of the original request. |
79 // the size of the target file if the request starts from non-zero offset. | 81 // Used to estimate the remaining size of the content when the initial |
| 82 // request is half open, i.e, |initial_request_length_| is |
| 83 // DownloadSaveInfo::kLengthFullContent. |
80 int64_t content_length_; | 84 int64_t content_length_; |
81 | 85 |
82 // Used to send parallel requests after a delay based on Finch config. | 86 // Used to send parallel requests after a delay based on Finch config. |
83 base::OneShotTimer timer_; | 87 base::OneShotTimer timer_; |
84 | 88 |
85 // If we have sent parallel requests. | 89 // If we have sent parallel requests. |
86 bool requests_sent_; | 90 bool requests_sent_; |
87 | 91 |
88 // If the download progress is canceled. | 92 // If the download progress is canceled. |
89 bool is_canceled_; | 93 bool is_canceled_; |
90 | 94 |
91 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob); | 95 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob); |
92 }; | 96 }; |
93 | 97 |
94 } // namespace content | 98 } // namespace content |
95 | 99 |
96 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ | 100 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ |
OLD | NEW |