Index: content/browser/download/url_downloader.h |
diff --git a/content/browser/download/url_downloader.h b/content/browser/download/url_downloader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7cdd4e307838ca72852bce7dcf6e03db0ed2ed1e |
--- /dev/null |
+++ b/content/browser/download/url_downloader.h |
@@ -0,0 +1,74 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
+#define CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "content/browser/download/download_request_handle.h" |
+#include "content/common/content_export.h" |
+#include "net/url_request/url_request.h" |
+ |
+namespace content { |
+ |
+class DownloadRequestModel; |
+class DownloadUrlParameters; |
+ |
+// TODO(asanka): This can't be committed as-is. Figure out which |
+// ResourceThrottles we need to support for explicit downloads and implement |
+// support for those. |
+// |
+// The code is used by Content menu -> Save * As and support for the download |
+// attribute. Requests that are handled by the resource dispatcher host |
+// typically go through a series of resource throttles. These requests need to |
+// at least support some of that functionality. Otherwise using the download |
+// attribute would allow a user to make a request that would otherwise be |
+// blocked by the ManagedModeResourceThrottle. |
+class UrlDownloader : public net::URLRequest::Delegate { |
+ public: |
+ CONTENT_EXPORT static scoped_ptr<DownloadRequestHandle> CreateDownloadRequest( |
+ scoped_ptr<DownloadUrlParameters> params); |
+ |
+ private: |
+ friend class base::DeleteHelper<UrlDownloader>; |
+ friend struct base::DefaultDeleter<UrlDownloader>; |
+ |
+ class RequestHandle; |
+ typedef DownloadRequestHandle::RequestStartedCallback RequestStartedCallback; |
+ |
+ UrlDownloader(scoped_ptr<DownloadUrlParameters> params); |
+ virtual ~UrlDownloader(); |
+ |
+ void Start(const RequestStartedCallback& callback); |
+ void PauseRequest(); |
+ void ResumeRequest(); |
+ void CancelRequest(); |
+ |
+ void ReadNextChunk(); |
+ void HandleCompletedRead(int bytes_read); |
+ |
+ // net::URLRequest::Delegate. |
+ virtual void OnReceivedRedirect(net::URLRequest* request, |
+ const GURL& new_url, |
+ bool* defer_redirect) OVERRIDE; |
+ virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
+ virtual void OnReadCompleted(net::URLRequest* request, |
+ int bytes_read) OVERRIDE; |
+ |
+ scoped_ptr<DownloadUrlParameters> params_; |
+ scoped_ptr<net::URLRequest> request_; |
+ scoped_ptr<DownloadRequestModel> request_model_; |
+ RequestStartedCallback started_callback_; |
+ |
+ // Used with ChildProcessSecurityPolicy to determine whether the download URL |
+ // and any redirects are allowed. |
+ int child_process_id_; |
+ bool is_request_active_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(UrlDownloader); |
+}; |
+ |
+} // namespace content |
+ |
+#endif |