Index: components/nacl/renderer/file_downloader.h |
diff --git a/components/nacl/renderer/manifest_downloader.h b/components/nacl/renderer/file_downloader.h |
similarity index 52% |
copy from components/nacl/renderer/manifest_downloader.h |
copy to components/nacl/renderer/file_downloader.h |
index 7488cab0c2dfb0e40df5092deb4bafd586784ae0..a26504390e911f0d0e8dd1818038882278a8ce2e 100644 |
--- a/components/nacl/renderer/manifest_downloader.h |
+++ b/components/nacl/renderer/file_downloader.h |
@@ -5,6 +5,7 @@ |
#include <string> |
#include "base/callback.h" |
+#include "base/files/file.h" |
#include "ppapi/c/private/ppb_nacl_private.h" |
#include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
@@ -16,21 +17,31 @@ class WebURLResponse; |
namespace nacl { |
-// Downloads a NaCl manifest (.nmf) and returns the contents of the file to |
-// caller through a callback. |
-class ManifestDownloader : public blink::WebURLLoaderClient { |
+// Downloads a file and writes the contents to a specified file open for |
+// writing. |
+class FileDownloader : public blink::WebURLLoaderClient { |
public: |
- typedef base::Callback<void(PP_NaClError, const std::string&)> |
- ManifestDownloaderCallback; |
+ enum Status { |
+ SUCCESS, |
+ ACCESS_DENIED, |
+ FAILED |
+ }; |
- ManifestDownloader(bool is_installed, ManifestDownloaderCallback cb); |
- virtual ~ManifestDownloader(); |
+ // Provides the FileDownloader status and the HTTP status code. |
+ typedef base::Callback<void(Status, int)> StatusCallback; |
- // This is a pretty arbitrary limit on the byte size of the NaCl manifest |
- // file. |
- // Note that the resulting string object has to have at least one byte extra |
- // for the null termination character. |
- static const size_t kNaClManifestMaxFileBytes = 1024 * 1024; |
+ // Provides the bytes received so far, and the total bytes expected to be |
+ // received. |
+ typedef base::Callback<void(int64_t, int64_t)> ProgressCallback; |
+ |
+ FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader, |
+ base::PlatformFile file, |
+ StatusCallback status_cb, |
+ ProgressCallback progress_cb); |
+ |
+ virtual ~FileDownloader(); |
+ |
+ void Load(const blink::WebURLRequest& request); |
private: |
// WebURLLoaderClient implementation. |
@@ -46,11 +57,14 @@ class ManifestDownloader : public blink::WebURLLoaderClient { |
virtual void didFail(blink::WebURLLoader* loader, |
const blink::WebURLError& error); |
- bool is_installed_; |
- ManifestDownloaderCallback cb_; |
- std::string buffer_; |
- int status_code_; |
- PP_NaClError pp_nacl_error_; |
+ scoped_ptr<blink::WebURLLoader> url_loader_; |
+ base::PlatformFile file_; |
+ StatusCallback status_cb_; |
+ ProgressCallback progress_cb_; |
+ int http_status_code_; |
+ int64_t total_bytes_received_; |
+ int64_t total_bytes_to_be_received_; |
+ Status status_; |
}; |
} // namespace nacl |