Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_URL_TASK_H_ | |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_URL_TASK_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "content/browser/byte_stream.h" | |
| 13 #include "content/browser/download/download_request_handle.h" | |
| 14 #include "content/browser/download/url_downloader.h" | |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 #include "content/public/browser/download_interrupt_reasons.h" | |
| 17 #include "content/public/browser/download_url_parameters.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 // Helper class used to send subsequent range requests to fetch segments of the | |
| 22 // file after handling response of the original non-range request. | |
| 23 class DownloadUrlTask : public UrlDownloader::Delegate { | |
|
asanka
2017/02/16 16:27:39
This class name is pretty confusing given that we
xingliu
2017/02/20 18:59:11
Renamed to DownloadWorker in this patch.
| |
| 24 public: | |
| 25 DownloadUrlTask(); | |
| 26 virtual ~DownloadUrlTask(); | |
| 27 | |
| 28 // Send network request to ask for a download. | |
| 29 void SendRequest(std::unique_ptr<DownloadUrlParameters> params); | |
| 30 | |
| 31 // Download operations. | |
| 32 void Pause(); | |
| 33 void Resume(); | |
| 34 void Cancel(); | |
| 35 | |
| 36 private: | |
| 37 // UrlDownloader::Delegate implementation. | |
| 38 void OnUrlDownloaderStarted( | |
| 39 std::unique_ptr<DownloadCreateInfo> create_info, | |
| 40 std::unique_ptr<ByteStreamReader> stream_reader, | |
| 41 const DownloadUrlParameters::OnStartedCallback& callback) override; | |
| 42 void OnUrlDownloaderStopped(UrlDownloader* downloader) override; | |
| 43 | |
| 44 void AddUrlDownloader( | |
| 45 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | |
| 46 downloader); | |
| 47 | |
| 48 // Used to control the network request. Live on UI thread. | |
| 49 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; | |
| 50 | |
| 51 // Used to handle the url request. Live and die on IO thread. | |
| 52 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | |
| 53 url_downloader_; | |
| 54 | |
| 55 base::WeakPtrFactory<DownloadUrlTask> weak_factory_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(DownloadUrlTask); | |
| 58 }; | |
| 59 | |
| 60 } // namespace content | |
| 61 | |
| 62 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_URL_TASK_H_ | |
| OLD | NEW |