| 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_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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 class DownloadWorker : public UrlDownloader::Delegate { | 24 class DownloadWorker : public UrlDownloader::Delegate { |
| 25 public: | 25 public: |
| 26 class Delegate { | 26 class Delegate { |
| 27 public: | 27 public: |
| 28 // Called when the the byte stream is established after server response is | 28 // Called when the the byte stream is established after server response is |
| 29 // handled. The stream contains data starts from |offset| of the | 29 // handled. The stream contains data starts from |offset| of the |
| 30 // destination file. | 30 // destination file. |
| 31 virtual void OnByteStreamReady( | 31 virtual void OnByteStreamReady( |
| 32 DownloadWorker* worker, | 32 DownloadWorker* worker, |
| 33 std::unique_ptr<ByteStreamReader> stream_reader) = 0; | 33 std::unique_ptr<ByteStreamReader> stream_reader) = 0; |
| 34 // Called when there is an error caused by the server response. |
| 35 virtual void OnServerResponseError(DownloadWorker* worker, |
| 36 DownloadInterruptReason reason) = 0; |
| 34 }; | 37 }; |
| 35 | 38 |
| 36 DownloadWorker(DownloadWorker::Delegate* delegate, | 39 DownloadWorker(DownloadWorker::Delegate* delegate, |
| 37 int64_t offset, | 40 int64_t offset, |
| 38 int64_t length); | 41 int64_t length); |
| 39 virtual ~DownloadWorker(); | 42 virtual ~DownloadWorker(); |
| 40 | 43 |
| 41 int64_t offset() const { return offset_; } | 44 int64_t offset() const { return offset_; } |
| 42 int64_t length() const { return length_; } | 45 int64_t length() const { return length_; } |
| 43 | 46 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 void OnUrlDownloaderStarted( | 57 void OnUrlDownloaderStarted( |
| 55 std::unique_ptr<DownloadCreateInfo> create_info, | 58 std::unique_ptr<DownloadCreateInfo> create_info, |
| 56 std::unique_ptr<ByteStreamReader> stream_reader, | 59 std::unique_ptr<ByteStreamReader> stream_reader, |
| 57 const DownloadUrlParameters::OnStartedCallback& callback) override; | 60 const DownloadUrlParameters::OnStartedCallback& callback) override; |
| 58 void OnUrlDownloaderStopped(UrlDownloader* downloader) override; | 61 void OnUrlDownloaderStopped(UrlDownloader* downloader) override; |
| 59 | 62 |
| 60 void AddUrlDownloader( | 63 void AddUrlDownloader( |
| 61 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | 64 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> |
| 62 downloader); | 65 downloader); |
| 63 | 66 |
| 64 DownloadWorker::Delegate* delegate_; | 67 DownloadWorker::Delegate* const delegate_; |
| 65 | 68 |
| 66 // The starting position of the content for this worker to download. | 69 // The starting position of the content for this worker to download. |
| 67 int64_t offset_; | 70 int64_t offset_; |
| 68 | 71 |
| 69 // The length of the request. May be 0 to fetch to the end of the file. | 72 // The length of the request. May be 0 to fetch to the end of the file. |
| 70 int64_t length_; | 73 int64_t length_; |
| 71 | 74 |
| 72 // Used to control the network request. Live on UI thread. | 75 // Used to control the network request. Live on UI thread. |
| 73 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; | 76 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; |
| 74 | 77 |
| 75 // Used to handle the url request. Live and die on IO thread. | 78 // Used to handle the url request. Live and die on IO thread. |
| 76 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | 79 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> |
| 77 url_downloader_; | 80 url_downloader_; |
| 78 | 81 |
| 79 base::WeakPtrFactory<DownloadWorker> weak_factory_; | 82 base::WeakPtrFactory<DownloadWorker> weak_factory_; |
| 80 | 83 |
| 81 DISALLOW_COPY_AND_ASSIGN(DownloadWorker); | 84 DISALLOW_COPY_AND_ASSIGN(DownloadWorker); |
| 82 }; | 85 }; |
| 83 | 86 |
| 84 } // namespace content | 87 } // namespace content |
| 85 | 88 |
| 86 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ | 89 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ |
| OLD | NEW |