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

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

Issue 2752603002: Propagate server response error and interrupt the download. (Closed)
Patch Set: 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 <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "content/browser/download/download_job_impl.h" 12 #include "content/browser/download/download_job_impl.h"
13 #include "content/browser/download/download_worker.h" 13 #include "content/browser/download/download_worker.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 // DownloadJob that can create concurrent range requests to fetch different 18 // DownloadJob that can create concurrent range requests to fetch different
19 // parts of the file. 19 // parts of the file.
20 // The original request is hold in base class DownloadUrlJob. 20 // The original request is hold in base class DownloadUrlJob.
21 class CONTENT_EXPORT ParallelDownloadJob : public DownloadJobImpl { 21 class CONTENT_EXPORT ParallelDownloadJob : public DownloadJobImpl,
22 public DownloadWorker::Delegate {
22 public: 23 public:
23 ParallelDownloadJob( 24 ParallelDownloadJob(
24 DownloadItemImpl* download_item, 25 DownloadItemImpl* download_item,
25 std::unique_ptr<DownloadRequestHandleInterface> request_handle, 26 std::unique_ptr<DownloadRequestHandleInterface> request_handle,
26 const DownloadCreateInfo& create_info); 27 const DownloadCreateInfo& create_info);
27 ~ParallelDownloadJob() override; 28 ~ParallelDownloadJob() override;
28 29
29 // DownloadUrlJob implementation. 30 // DownloadUrlJob implementation.
30 void Start() override; 31 void Start() override;
31 void Cancel(bool user_cancel) override; 32 void Cancel(bool user_cancel) override;
32 void Pause() override; 33 void Pause() override;
33 void Resume(bool resume_request) override; 34 void Resume(bool resume_request) override;
34 35
35 private: 36 private:
36 friend class ParallelDownloadJobTest; 37 friend class ParallelDownloadJobTest;
37 38
38 typedef std::vector<std::unique_ptr<DownloadWorker>> WorkerList; 39 typedef std::vector<std::unique_ptr<DownloadWorker>> WorkerList;
39 40
41 // DownloadWorker::Delegate implementation.
42 void OnServerResponseError(DownloadWorker* worker,
43 DownloadInterruptReason reason) override;
44
40 // Build multiple http requests for a new download, 45 // Build multiple http requests for a new download,
41 // the rest of the bytes starting from |bytes_received| will be equally 46 // the rest of the bytes starting from |bytes_received| will be equally
42 // distributed to each connection, including the original connection. 47 // distributed to each connection, including the original connection.
43 // the last connection may take additional bytes. 48 // the last connection may take additional bytes.
44 void ForkRequestsForNewDownload(int64_t bytes_received, 49 void ForkRequestsForNewDownload(int64_t bytes_received,
45 int64_t total_bytes, 50 int64_t total_bytes,
46 int request_count); 51 int request_count);
47 52
48 // Build parallel requests to download the remaining slices. 53 // Build parallel requests to download the remaining slices.
49 // TODO(qinmin): remove ForkRequestsForNewDownload() and move the logic into 54 // TODO(qinmin): remove ForkRequestsForNewDownload() and move the logic into
50 // this function. 55 // this function.
51 void BuildParallelRequests(); 56 void BuildParallelRequests();
52 57
53 // Create one range request, virtual for testing. 58 // Create one range request, virtual for testing.
54 virtual void CreateRequest(int64_t offset, int64_t length); 59 virtual void CreateRequest(int64_t offset, int64_t length);
55 60
56 // Information about the initial request when download is started. 61 // Information about the initial request when download is started.
57 int64_t initial_request_offset_; 62 int64_t initial_request_offset_;
58 int64_t initial_request_length_; 63 int64_t initial_request_length_;
59 64
60 // Subsequent tasks to send range requests. 65 // Subsequent tasks to send range requests.
61 WorkerList workers_; 66 WorkerList workers_;
62 67
63 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob); 68 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJob);
64 }; 69 };
65 70
66 } // namespace content 71 } // namespace content
67 72
68 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_ 73 #endif // CONTENT_BROWSER_DOWNLOAD_PARALLEL_DOWNLOAD_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698