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

Side by Side Diff: content/browser/download/parallel_download_job.h

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

Powered by Google App Engine
This is Rietveld 408576698