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> |
| 9 |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
10 #include "content/browser/download/download_request_core.h" | 12 #include "content/browser/download/download_request_core.h" |
11 #include "content/public/browser/download_save_info.h" | 13 #include "content/public/browser/download_save_info.h" |
12 #include "content/public/browser/download_url_parameters.h" | 14 #include "content/public/browser/download_url_parameters.h" |
13 #include "content/public/common/referrer.h" | 15 #include "content/public/common/referrer.h" |
14 #include "net/url_request/redirect_info.h" | 16 #include "net/url_request/redirect_info.h" |
15 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 class DownloadManagerImpl; | 20 class DownloadManagerImpl; |
19 | 21 |
20 class UrlDownloader : public net::URLRequest::Delegate { | 22 class UrlDownloader : public net::URLRequest::Delegate { |
21 public: | 23 public: |
22 UrlDownloader( | 24 UrlDownloader( |
23 scoped_ptr<net::URLRequest> request, | 25 scoped_ptr<net::URLRequest> request, |
24 base::WeakPtr<DownloadManagerImpl> manager, | 26 base::WeakPtr<DownloadManagerImpl> manager, |
25 scoped_ptr<DownloadSaveInfo> save_info, | 27 scoped_ptr<DownloadSaveInfo> save_info, |
26 uint32 download_id, | 28 uint32_t download_id, |
27 const DownloadUrlParameters::OnStartedCallback& on_started_callback); | 29 const DownloadUrlParameters::OnStartedCallback& on_started_callback); |
28 ~UrlDownloader() override; | 30 ~UrlDownloader() override; |
29 | 31 |
30 static scoped_ptr<UrlDownloader> BeginDownload( | 32 static scoped_ptr<UrlDownloader> BeginDownload( |
31 base::WeakPtr<DownloadManagerImpl> download_manager, | 33 base::WeakPtr<DownloadManagerImpl> download_manager, |
32 scoped_ptr<net::URLRequest> request, | 34 scoped_ptr<net::URLRequest> request, |
33 const Referrer& referrer, | 35 const Referrer& referrer, |
34 bool prefer_cache, | 36 bool prefer_cache, |
35 scoped_ptr<DownloadSaveInfo> save_info, | 37 scoped_ptr<DownloadSaveInfo> save_info, |
36 uint32 download_id, | 38 uint32_t download_id, |
37 const DownloadUrlParameters::OnStartedCallback& started_callback); | 39 const DownloadUrlParameters::OnStartedCallback& started_callback); |
38 | 40 |
39 // URLRequest::Delegate: | 41 // URLRequest::Delegate: |
40 void OnReceivedRedirect(net::URLRequest* request, | 42 void OnReceivedRedirect(net::URLRequest* request, |
41 const net::RedirectInfo& redirect_info, | 43 const net::RedirectInfo& redirect_info, |
42 bool* defer_redirect) override; | 44 bool* defer_redirect) override; |
43 void OnResponseStarted(net::URLRequest* request) override; | 45 void OnResponseStarted(net::URLRequest* request) override; |
44 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 46 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
45 | 47 |
46 void StartReading(bool is_continuation); | 48 void StartReading(bool is_continuation); |
47 void ResponseCompleted(); | 49 void ResponseCompleted(); |
48 | 50 |
49 void Start(); | 51 void Start(); |
50 void ResumeReading(); | 52 void ResumeReading(); |
51 | 53 |
52 void CallStartedCallbackOnFailure(DownloadInterruptReason result); | 54 void CallStartedCallbackOnFailure(DownloadInterruptReason result); |
53 | 55 |
54 private: | 56 private: |
55 class RequestHandle; | 57 class RequestHandle; |
56 | 58 |
57 void PauseRequest(); | 59 void PauseRequest(); |
58 void ResumeRequest(); | 60 void ResumeRequest(); |
59 void CancelRequest(); | 61 void CancelRequest(); |
60 | 62 |
61 scoped_ptr<net::URLRequest> request_; | 63 scoped_ptr<net::URLRequest> request_; |
62 base::WeakPtr<DownloadManagerImpl> manager_; | 64 base::WeakPtr<DownloadManagerImpl> manager_; |
63 uint32 download_id_; | 65 uint32_t download_id_; |
64 DownloadUrlParameters::OnStartedCallback on_started_callback_; | 66 DownloadUrlParameters::OnStartedCallback on_started_callback_; |
65 | 67 |
66 DownloadRequestCore handler_; | 68 DownloadRequestCore handler_; |
67 | 69 |
68 base::WeakPtrFactory<UrlDownloader> weak_ptr_factory_; | 70 base::WeakPtrFactory<UrlDownloader> weak_ptr_factory_; |
69 }; | 71 }; |
70 | 72 |
71 } // namespace content | 73 } // namespace content |
72 | 74 |
73 #endif // CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ | 75 #endif // CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
OLD | NEW |