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

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

Issue 2767593003: Handle early pause, cancel for parallel requests. (Closed)
Patch Set: Move is_canceled_ to subclass. 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
« no previous file with comments | « content/browser/download/download_job.cc ('k') | content/browser/download/download_worker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_DOWNLOAD_WORKER_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "content/browser/byte_stream.h" 12 #include "content/browser/byte_stream.h"
13 #include "content/browser/download/download_request_handle.h" 13 #include "content/browser/download/download_request_handle.h"
14 #include "content/browser/download/url_downloader.h" 14 #include "content/browser/download/url_downloader.h"
15 #include "content/common/content_export.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/download_url_parameters.h" 17 #include "content/public/browser/download_url_parameters.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 // Helper class used to send subsequent range requests to fetch slices of the 21 // Helper class used to send subsequent range requests to fetch slices of the
21 // file after handling response of the original non-range request. 22 // file after handling response of the original non-range request.
22 // TODO(xingliu): we should consider to reuse this class for single connection 23 // TODO(xingliu): we should consider to reuse this class for single connection
23 // download. 24 // download.
24 class DownloadWorker : public UrlDownloader::Delegate { 25 class CONTENT_EXPORT DownloadWorker : public UrlDownloader::Delegate {
25 public: 26 public:
26 class Delegate { 27 class Delegate {
27 public: 28 public:
28 // Called when the the byte stream is established after server response is 29 // Called when the the byte stream is established after server response is
29 // handled. The stream contains data starts from |offset| of the 30 // handled. The stream contains data starts from |offset| of the
30 // destination file. 31 // destination file.
31 virtual void OnByteStreamReady( 32 virtual void OnByteStreamReady(
32 DownloadWorker* worker, 33 DownloadWorker* worker,
33 std::unique_ptr<ByteStreamReader> stream_reader) = 0; 34 std::unique_ptr<ByteStreamReader> stream_reader) = 0;
34 // Called when there is an error caused by the server response. 35 // Called when there is an error caused by the server response.
(...skipping 30 matching lines...) Expand all
65 downloader); 66 downloader);
66 67
67 DownloadWorker::Delegate* const delegate_; 68 DownloadWorker::Delegate* const delegate_;
68 69
69 // The starting position of the content for this worker to download. 70 // The starting position of the content for this worker to download.
70 int64_t offset_; 71 int64_t offset_;
71 72
72 // The length of the request. May be 0 to fetch to the end of the file. 73 // The length of the request. May be 0 to fetch to the end of the file.
73 int64_t length_; 74 int64_t length_;
74 75
76 // States of the worker.
77 bool is_paused_;
78 bool is_canceled_;
79
75 // Used to control the network request. Live on UI thread. 80 // Used to control the network request. Live on UI thread.
76 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; 81 std::unique_ptr<DownloadRequestHandleInterface> request_handle_;
77 82
78 // Used to handle the url request. Live and die on IO thread. 83 // Used to handle the url request. Live and die on IO thread.
79 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 84 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
80 url_downloader_; 85 url_downloader_;
81 86
82 base::WeakPtrFactory<DownloadWorker> weak_factory_; 87 base::WeakPtrFactory<DownloadWorker> weak_factory_;
83 88
84 DISALLOW_COPY_AND_ASSIGN(DownloadWorker); 89 DISALLOW_COPY_AND_ASSIGN(DownloadWorker);
85 }; 90 };
86 91
87 } // namespace content 92 } // namespace content
88 93
89 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ 94 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_job.cc ('k') | content/browser/download/download_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698