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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "components/nacl/renderer/ppb_nacl_private.h" | 11 #include "components/nacl/renderer/ppb_nacl_private.h" |
12 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 12 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderClient.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
| 15 class WebAssociatedURLLoader; |
15 struct WebURLError; | 16 struct WebURLError; |
16 class WebURLLoader; | 17 class WebURLLoader; |
17 class WebURLResponse; | 18 class WebURLResponse; |
18 } | 19 } |
19 | 20 |
20 namespace nacl { | 21 namespace nacl { |
21 | 22 |
22 // Downloads a file and writes the contents to a specified file open for | 23 // Downloads a file and writes the contents to a specified file open for |
23 // writing. | 24 // writing. |
24 class FileDownloader : public blink::WebURLLoaderClient { | 25 class FileDownloader : public blink::WebAssociatedURLLoaderClient { |
25 public: | 26 public: |
26 enum Status { | 27 enum Status { |
27 SUCCESS, | 28 SUCCESS, |
28 ACCESS_DENIED, | 29 ACCESS_DENIED, |
29 FAILED | 30 FAILED |
30 }; | 31 }; |
31 | 32 |
32 // Provides the FileDownloader status and the HTTP status code. | 33 // Provides the FileDownloader status and the HTTP status code. |
33 typedef base::Callback<void(Status, base::File, int)> StatusCallback; | 34 typedef base::Callback<void(Status, base::File, int)> StatusCallback; |
34 | 35 |
35 // Provides the bytes received so far, and the total bytes expected to be | 36 // Provides the bytes received so far, and the total bytes expected to be |
36 // received. | 37 // received. |
37 typedef base::Callback<void(int64_t, int64_t)> ProgressCallback; | 38 typedef base::Callback<void(int64_t, int64_t)> ProgressCallback; |
38 | 39 |
39 FileDownloader(std::unique_ptr<blink::WebURLLoader> url_loader, | 40 FileDownloader(std::unique_ptr<blink::WebAssociatedURLLoader> url_loader, |
40 base::File file, | 41 base::File file, |
41 StatusCallback status_cb, | 42 StatusCallback status_cb, |
42 ProgressCallback progress_cb); | 43 ProgressCallback progress_cb); |
43 | 44 |
44 ~FileDownloader() override; | 45 ~FileDownloader() override; |
45 | 46 |
46 void Load(const blink::WebURLRequest& request); | 47 void Load(const blink::WebURLRequest& request); |
47 | 48 |
48 private: | 49 private: |
49 // WebURLLoaderClient implementation. | 50 // WebAssociatedURLLoaderClient implementation. |
50 void didReceiveResponse(blink::WebURLLoader* loader, | 51 void didReceiveResponse(const blink::WebURLResponse& response) override; |
51 const blink::WebURLResponse& response) override; | 52 void didReceiveData(const char* data, int data_length) override; |
52 void didReceiveData(blink::WebURLLoader* loader, | 53 void didFinishLoading(double finish_time) override; |
53 const char* data, | 54 void didFail(const blink::WebURLError& error) override; |
54 int data_length, | |
55 int encoded_data_length, | |
56 int encoded_body_length) override; | |
57 void didFinishLoading(blink::WebURLLoader* loader, | |
58 double finish_time, | |
59 int64_t total_encoded_data_length) override; | |
60 void didFail(blink::WebURLLoader* loader, | |
61 const blink::WebURLError& error) override; | |
62 | 55 |
63 std::unique_ptr<blink::WebURLLoader> url_loader_; | 56 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader_; |
64 base::File file_; | 57 base::File file_; |
65 StatusCallback status_cb_; | 58 StatusCallback status_cb_; |
66 ProgressCallback progress_cb_; | 59 ProgressCallback progress_cb_; |
67 int http_status_code_; | 60 int http_status_code_; |
68 int64_t total_bytes_received_; | 61 int64_t total_bytes_received_; |
69 int64_t total_bytes_to_be_received_; | 62 int64_t total_bytes_to_be_received_; |
70 Status status_; | 63 Status status_; |
71 }; | 64 }; |
72 | 65 |
73 } // namespace nacl | 66 } // namespace nacl |
OLD | NEW |