OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file.h" | |
8 #include "ppapi/c/private/ppb_nacl_private.h" | 9 #include "ppapi/c/private/ppb_nacl_private.h" |
9 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
10 | 11 |
11 namespace blink { | 12 namespace blink { |
12 struct WebURLError; | 13 struct WebURLError; |
13 class WebURLLoader; | 14 class WebURLLoader; |
14 class WebURLResponse; | 15 class WebURLResponse; |
15 } | 16 } |
16 | 17 |
17 namespace nacl { | 18 namespace nacl { |
18 | 19 |
19 // Downloads a NaCl manifest (.nmf) and returns the contents of the file to | 20 // Downloads a file and writes the contents to a specified file open for |
20 // caller through a callback. | 21 // writing. |
21 class ManifestDownloader : public blink::WebURLLoaderClient { | 22 class FileDownloader : public blink::WebURLLoaderClient { |
22 public: | 23 public: |
23 typedef base::Callback<void(PP_NaClError, const std::string&)> | 24 enum Status { |
24 ManifestDownloaderCallback; | 25 SUCCESS, |
26 ACCESS_DENIED, // Access denied | |
27 FAILED // Generic failure | |
28 }; | |
29 typedef base::Callback<void(Status, int)> FileDownloaderCallback; | |
bbudge
2014/05/12 22:32:06
name suggestion: Callback or StatusCallback
teravest
2014/05/13 17:05:32
Done.
| |
30 typedef base::Callback<void(int64_t, int64_t)> ProgressCallback; | |
25 | 31 |
26 ManifestDownloader(bool is_installed, ManifestDownloaderCallback cb); | 32 FileDownloader(base::PlatformFile file, |
27 virtual ~ManifestDownloader(); | 33 FileDownloaderCallback cb); |
bbudge
2014/05/12 22:32:06
nit: fits on a single line.
teravest
2014/05/13 17:05:32
Done.
| |
34 | |
35 // Creates a FileDownloader that notifies the caller about download progress. | |
36 FileDownloader(base::PlatformFile file, | |
37 FileDownloaderCallback cb, | |
38 ProgressCallback progress_cb); | |
39 | |
40 virtual ~FileDownloader(); | |
28 | 41 |
29 private: | 42 private: |
30 // WebURLLoaderClient implementation. | 43 // WebURLLoaderClient implementation. |
31 virtual void didReceiveResponse(blink::WebURLLoader* loader, | 44 virtual void didReceiveResponse(blink::WebURLLoader* loader, |
32 const blink::WebURLResponse& response); | 45 const blink::WebURLResponse& response); |
33 virtual void didReceiveData(blink::WebURLLoader* loader, | 46 virtual void didReceiveData(blink::WebURLLoader* loader, |
34 const char* data, | 47 const char* data, |
35 int data_length, | 48 int data_length, |
36 int encoded_data_length); | 49 int encoded_data_length); |
37 virtual void didFinishLoading(blink::WebURLLoader* loader, | 50 virtual void didFinishLoading(blink::WebURLLoader* loader, |
38 double finish_time, | 51 double finish_time, |
39 int64_t total_encoded_data_length); | 52 int64_t total_encoded_data_length); |
40 virtual void didFail(blink::WebURLLoader* loader, | 53 virtual void didFail(blink::WebURLLoader* loader, |
41 const blink::WebURLError& error); | 54 const blink::WebURLError& error); |
42 | 55 |
43 bool is_installed_; | 56 base::PlatformFile file_; |
44 ManifestDownloaderCallback cb_; | 57 FileDownloaderCallback cb_; |
45 std::string buffer_; | 58 ProgressCallback progress_cb_; |
46 int status_code_; | 59 int status_code_; |
47 PP_NaClError pp_nacl_error_; | 60 int64_t total_bytes_received_; |
61 int64_t total_bytes_to_be_received_; | |
62 Status status_; | |
48 }; | 63 }; |
49 | 64 |
50 } // namespace nacl | 65 } // namespace nacl |
OLD | NEW |