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

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

Issue 2767593003: Handle early pause, cancel for parallel requests. (Closed)
Patch Set: Work on feedback. 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;
58 bool IsPaused() const override;
qinmin 2017/03/22 05:50:29 nit: worker can remember whether pause() is called
xingliu 2017/03/22 23:54:06 We may pause/cancel before the worker is construct
qinmin 2017/03/24 19:52:58 wait, if we pause/cancel before worker is construc
59 bool IsCanceled() const override;
54 60
55 // Build parallel requests after a delay, to effectively measure the single 61 // Build parallel requests after a delay, to effectively measure the single
56 // stream bandwidth. 62 // stream bandwidth.
57 void BuildParallelRequestAfterDelay(); 63 void BuildParallelRequestAfterDelay();
58 64
59 // Build parallel requests to download. This function is the entry point for 65 // Build parallel requests to download. This function is the entry point for
60 // all parallel downloads. 66 // all parallel downloads.
61 void BuildParallelRequests(); 67 void BuildParallelRequests();
62 68
63 // Build one http request for each slice from the second slice. 69 // Build one http request for each slice from the second slice.
64 // The first slice represents the original request. 70 // The first slice represents the original request.
65 void ForkSubRequests(const DownloadItem::ReceivedSlices& slices_to_download); 71 void ForkSubRequests(const DownloadItem::ReceivedSlices& slices_to_download);
66 72
67 // Create one range request, virtual for testing. 73 // Create one range request, virtual for testing.
68 virtual void CreateRequest(int64_t offset, int64_t length); 74 virtual void CreateRequest(int64_t offset, int64_t length);
69 75
70 // Information about the initial request when download is started. 76 // Information about the initial request when download is started.
71 int64_t initial_request_offset_; 77 int64_t initial_request_offset_;
72 78
73 // The length of the response body of the original request. May be less than 79 // 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. 80 // the size of the target file if the request starts from non-zero offset.
75 int64_t content_length_; 81 int64_t content_length_;
76 82
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. 83 // Used to send parallel requests after a delay based on Finch config.
82 base::OneShotTimer timer_; 84 base::OneShotTimer timer_;
83 85
84 // If we have sent parallel requests. 86 // If we have sent parallel requests.
85 bool requests_sent_; 87 bool requests_sent_;
86 88
87 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob); 89 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob);
88 }; 90 };
89 91
90 } // namespace content 92 } // namespace content
91 93
92 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ 94 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698