OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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_URL_DOWNLOADER_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/browser/download/download_request_handle.h" |
| 10 #include "content/common/content_export.h" |
| 11 #include "net/url_request/url_request.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 class DownloadRequestModel; |
| 16 class DownloadUrlParameters; |
| 17 |
| 18 // TODO(asanka): This can't be committed as-is. Figure out which |
| 19 // ResourceThrottles we need to support for explicit downloads and implement |
| 20 // support for those. |
| 21 // |
| 22 // The code is used by Content menu -> Save * As and support for the download |
| 23 // attribute. Requests that are handled by the resource dispatcher host |
| 24 // typically go through a series of resource throttles. These requests need to |
| 25 // at least support some of that functionality. Otherwise using the download |
| 26 // attribute would allow a user to make a request that would otherwise be |
| 27 // blocked by the ManagedModeResourceThrottle. |
| 28 class UrlDownloader : public net::URLRequest::Delegate { |
| 29 public: |
| 30 CONTENT_EXPORT static scoped_ptr<DownloadRequestHandle> CreateDownloadRequest( |
| 31 scoped_ptr<DownloadUrlParameters> params); |
| 32 |
| 33 private: |
| 34 friend class base::DeleteHelper<UrlDownloader>; |
| 35 friend struct base::DefaultDeleter<UrlDownloader>; |
| 36 |
| 37 class RequestHandle; |
| 38 typedef DownloadRequestHandle::RequestStartedCallback RequestStartedCallback; |
| 39 |
| 40 UrlDownloader(scoped_ptr<DownloadUrlParameters> params); |
| 41 virtual ~UrlDownloader(); |
| 42 |
| 43 void Start(const RequestStartedCallback& callback); |
| 44 void PauseRequest(); |
| 45 void ResumeRequest(); |
| 46 void CancelRequest(); |
| 47 |
| 48 void ReadNextChunk(); |
| 49 void HandleCompletedRead(int bytes_read); |
| 50 |
| 51 // net::URLRequest::Delegate. |
| 52 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 53 const GURL& new_url, |
| 54 bool* defer_redirect) OVERRIDE; |
| 55 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 56 virtual void OnReadCompleted(net::URLRequest* request, |
| 57 int bytes_read) OVERRIDE; |
| 58 |
| 59 scoped_ptr<DownloadUrlParameters> params_; |
| 60 scoped_ptr<net::URLRequest> request_; |
| 61 scoped_ptr<DownloadRequestModel> request_model_; |
| 62 RequestStartedCallback started_callback_; |
| 63 |
| 64 // Used with ChildProcessSecurityPolicy to determine whether the download URL |
| 65 // and any redirects are allowed. |
| 66 int child_process_id_; |
| 67 bool is_request_active_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(UrlDownloader); |
| 70 }; |
| 71 |
| 72 } // namespace content |
| 73 |
| 74 #endif |
OLD | NEW |