| 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 22 matching lines...) Expand all Loading... |
| 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 | 42 |
| 43 using WorkerMap = |
| 44 std::unordered_map<int64_t, std::unique_ptr<DownloadWorker>>; |
| 45 |
| 46 // Map from the offset position of the slice to the worker that downloads the |
| 47 // slice. |
| 48 WorkerMap workers_; |
| 49 |
| 43 private: | 50 private: |
| 44 friend class ParallelDownloadJobTest; | 51 friend class ParallelDownloadJobTest; |
| 45 | 52 |
| 46 using WorkerMap = | |
| 47 std::unordered_map<int64_t, std::unique_ptr<DownloadWorker>>; | |
| 48 | |
| 49 // DownloadWorker::Delegate implementation. | 53 // DownloadWorker::Delegate implementation. |
| 50 void OnByteStreamReady( | 54 void OnByteStreamReady( |
| 51 DownloadWorker* worker, | 55 DownloadWorker* worker, |
| 52 std::unique_ptr<ByteStreamReader> stream_reader) override; | 56 std::unique_ptr<ByteStreamReader> stream_reader) override; |
| 53 void OnServerResponseError(DownloadWorker* worker, | 57 void OnServerResponseError(DownloadWorker* worker, |
| 54 DownloadInterruptReason reason) override; | 58 DownloadInterruptReason reason) override; |
| 55 | 59 |
| 56 // Build parallel requests after a delay, to effectively measure the single | 60 // Build parallel requests after a delay, to effectively measure the single |
| 57 // stream bandwidth. | 61 // stream bandwidth. |
| 58 void BuildParallelRequestAfterDelay(); | 62 void BuildParallelRequestAfterDelay(); |
| 59 | 63 |
| 60 // Build parallel requests to download. This function is the entry point for | 64 // Build parallel requests to download. This function is the entry point for |
| 61 // all parallel downloads. | 65 // all parallel downloads. |
| 62 void BuildParallelRequests(); | 66 void BuildParallelRequests(); |
| 63 | 67 |
| 64 // Build one http request for each slice from the second slice. | 68 // Build one http request for each slice from the second slice. |
| 65 // The first slice represents the original request. | 69 // The first slice represents the original request. |
| 66 void ForkSubRequests(const DownloadItem::ReceivedSlices& slices_to_download); | 70 void ForkSubRequests(const DownloadItem::ReceivedSlices& slices_to_download); |
| 67 | 71 |
| 68 // Create one range request, virtual for testing. | 72 // Create one range request, virtual for testing. |
| 69 virtual void CreateRequest(int64_t offset, int64_t length); | 73 virtual void CreateRequest(int64_t offset, int64_t length); |
| 70 | 74 |
| 71 // Information about the initial request when download is started. | 75 // Information about the initial request when download is started. |
| 72 int64_t initial_request_offset_; | 76 int64_t initial_request_offset_; |
| 73 | 77 |
| 74 // The length of the response body of the original request. May be less than | 78 // The length of the response body of the original request. May be less than |
| 75 // the size of the target file if the request starts from non-zero offset. | 79 // the size of the target file if the request starts from non-zero offset. |
| 76 int64_t content_length_; | 80 int64_t content_length_; |
| 77 | 81 |
| 78 // Map from the offset position of the slice to the worker that downloads the | |
| 79 // slice. | |
| 80 WorkerMap workers_; | |
| 81 | |
| 82 // Used to send parallel requests after a delay based on Finch config. | 82 // Used to send parallel requests after a delay based on Finch config. |
| 83 base::OneShotTimer timer_; | 83 base::OneShotTimer timer_; |
| 84 | 84 |
| 85 // If we have sent parallel requests. | 85 // If we have sent parallel requests. |
| 86 bool requests_sent_; | 86 bool requests_sent_; |
| 87 | 87 |
| 88 // If the download progress is canceled. |
| 89 bool is_canceled_; |
| 90 |
| 88 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob); | 91 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob); |
| 89 }; | 92 }; |
| 90 | 93 |
| 91 } // namespace content | 94 } // namespace content |
| 92 | 95 |
| 93 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ | 96 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ |
| OLD | NEW |