OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_URL_DOWNLOADER_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "content/browser/download/download_request_core.h" | 12 #include "content/browser/download/download_request_core.h" |
| 13 #include "content/public/browser/download_interrupt_reasons.h" |
13 #include "content/public/browser/download_save_info.h" | 14 #include "content/public/browser/download_save_info.h" |
14 #include "content/public/browser/download_url_parameters.h" | 15 #include "content/public/browser/download_url_parameters.h" |
15 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
16 #include "net/url_request/redirect_info.h" | 17 #include "net/url_request/redirect_info.h" |
17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
| 21 class ByteStreamReader; |
| 22 struct DownloadCreateInfo; |
20 class DownloadManagerImpl; | 23 class DownloadManagerImpl; |
21 | 24 |
22 class UrlDownloader : public net::URLRequest::Delegate { | 25 class UrlDownloader : public net::URLRequest::Delegate, |
| 26 public DownloadRequestCore::Delegate { |
23 public: | 27 public: |
24 UrlDownloader( | 28 UrlDownloader(scoped_ptr<net::URLRequest> request, |
25 scoped_ptr<net::URLRequest> request, | 29 base::WeakPtr<DownloadManagerImpl> manager); |
26 base::WeakPtr<DownloadManagerImpl> manager, | |
27 scoped_ptr<DownloadSaveInfo> save_info, | |
28 uint32_t download_id, | |
29 const DownloadUrlParameters::OnStartedCallback& on_started_callback); | |
30 ~UrlDownloader() override; | 30 ~UrlDownloader() override; |
31 | 31 |
32 static scoped_ptr<UrlDownloader> BeginDownload( | 32 static scoped_ptr<UrlDownloader> BeginDownload( |
33 base::WeakPtr<DownloadManagerImpl> download_manager, | 33 base::WeakPtr<DownloadManagerImpl> download_manager, |
34 scoped_ptr<net::URLRequest> request, | 34 scoped_ptr<net::URLRequest> request, |
35 const Referrer& referrer, | 35 const Referrer& referrer); |
36 bool prefer_cache, | 36 |
37 scoped_ptr<DownloadSaveInfo> save_info, | 37 private: |
38 uint32_t download_id, | 38 class RequestHandle; |
39 const DownloadUrlParameters::OnStartedCallback& started_callback); | 39 |
| 40 void Start(); |
40 | 41 |
41 // URLRequest::Delegate: | 42 // URLRequest::Delegate: |
42 void OnReceivedRedirect(net::URLRequest* request, | 43 void OnReceivedRedirect(net::URLRequest* request, |
43 const net::RedirectInfo& redirect_info, | 44 const net::RedirectInfo& redirect_info, |
44 bool* defer_redirect) override; | 45 bool* defer_redirect) override; |
45 void OnResponseStarted(net::URLRequest* request) override; | 46 void OnResponseStarted(net::URLRequest* request) override; |
46 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 47 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
47 | 48 |
48 void StartReading(bool is_continuation); | 49 void StartReading(bool is_continuation); |
49 void ResponseCompleted(); | 50 void ResponseCompleted(); |
50 | 51 |
51 void Start(); | 52 // DownloadRequestCore::Delegate |
52 void ResumeReading(); | 53 void OnStart( |
53 | 54 scoped_ptr<DownloadCreateInfo> download_create_info, |
54 void CallStartedCallbackOnFailure(DownloadInterruptReason result); | 55 scoped_ptr<ByteStreamReader> stream_reader, |
55 | 56 const DownloadUrlParameters::OnStartedCallback& callback) override; |
56 private: | 57 void OnReadyToRead() override; |
57 class RequestHandle; | |
58 | 58 |
59 void PauseRequest(); | 59 void PauseRequest(); |
60 void ResumeRequest(); | 60 void ResumeRequest(); |
61 void CancelRequest(); | 61 void CancelRequest(); |
62 | 62 |
| 63 // Called when the UrlDownloader is done with the request. Posts a task to |
| 64 // remove itself from its download manager, which in turn would cause the |
| 65 // UrlDownloader to be freed. |
| 66 void Destroy(); |
| 67 |
63 scoped_ptr<net::URLRequest> request_; | 68 scoped_ptr<net::URLRequest> request_; |
64 base::WeakPtr<DownloadManagerImpl> manager_; | 69 base::WeakPtr<DownloadManagerImpl> manager_; |
65 uint32_t download_id_; | 70 DownloadRequestCore core_; |
66 DownloadUrlParameters::OnStartedCallback on_started_callback_; | |
67 | |
68 DownloadRequestCore handler_; | |
69 | 71 |
70 base::WeakPtrFactory<UrlDownloader> weak_ptr_factory_; | 72 base::WeakPtrFactory<UrlDownloader> weak_ptr_factory_; |
71 }; | 73 }; |
72 | 74 |
73 } // namespace content | 75 } // namespace content |
74 | 76 |
75 #endif // CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ | 77 #endif // CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
OLD | NEW |