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 "base/files/file.h" |
9 #include "ppapi/c/private/ppb_nacl_private.h" | 9 #include "ppapi/c/private/ppb_nacl_private.h" |
10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // writing. | 21 // writing. |
22 class FileDownloader : public blink::WebURLLoaderClient { | 22 class FileDownloader : public blink::WebURLLoaderClient { |
23 public: | 23 public: |
24 enum Status { | 24 enum Status { |
25 SUCCESS, | 25 SUCCESS, |
26 ACCESS_DENIED, | 26 ACCESS_DENIED, |
27 FAILED | 27 FAILED |
28 }; | 28 }; |
29 | 29 |
30 // Provides the FileDownloader status and the HTTP status code. | 30 // Provides the FileDownloader status and the HTTP status code. |
31 typedef base::Callback<void(Status, int)> StatusCallback; | 31 typedef base::Callback<void(Status, base::File, int)> StatusCallback; |
32 | 32 |
33 // Provides the bytes received so far, and the total bytes expected to be | 33 // Provides the bytes received so far, and the total bytes expected to be |
34 // received. | 34 // received. |
35 typedef base::Callback<void(int64_t, int64_t)> ProgressCallback; | 35 typedef base::Callback<void(int64_t, int64_t)> ProgressCallback; |
36 | 36 |
37 FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader, | 37 FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader, |
38 base::PlatformFile file, | 38 base::File file, |
39 StatusCallback status_cb, | 39 StatusCallback status_cb, |
40 ProgressCallback progress_cb); | 40 ProgressCallback progress_cb); |
41 | 41 |
42 virtual ~FileDownloader(); | 42 virtual ~FileDownloader(); |
43 | 43 |
44 void Load(const blink::WebURLRequest& request); | 44 void Load(const blink::WebURLRequest& request); |
45 | 45 |
46 private: | 46 private: |
47 // WebURLLoaderClient implementation. | 47 // WebURLLoaderClient implementation. |
48 virtual void didReceiveResponse(blink::WebURLLoader* loader, | 48 virtual void didReceiveResponse(blink::WebURLLoader* loader, |
49 const blink::WebURLResponse& response); | 49 const blink::WebURLResponse& response); |
50 virtual void didReceiveData(blink::WebURLLoader* loader, | 50 virtual void didReceiveData(blink::WebURLLoader* loader, |
51 const char* data, | 51 const char* data, |
52 int data_length, | 52 int data_length, |
53 int encoded_data_length); | 53 int encoded_data_length); |
54 virtual void didFinishLoading(blink::WebURLLoader* loader, | 54 virtual void didFinishLoading(blink::WebURLLoader* loader, |
55 double finish_time, | 55 double finish_time, |
56 int64_t total_encoded_data_length); | 56 int64_t total_encoded_data_length); |
57 virtual void didFail(blink::WebURLLoader* loader, | 57 virtual void didFail(blink::WebURLLoader* loader, |
58 const blink::WebURLError& error); | 58 const blink::WebURLError& error); |
59 | 59 |
60 scoped_ptr<blink::WebURLLoader> url_loader_; | 60 scoped_ptr<blink::WebURLLoader> url_loader_; |
61 base::PlatformFile file_; | 61 base::File file_; |
62 StatusCallback status_cb_; | 62 StatusCallback status_cb_; |
63 ProgressCallback progress_cb_; | 63 ProgressCallback progress_cb_; |
64 int http_status_code_; | 64 int http_status_code_; |
65 int64_t total_bytes_received_; | 65 int64_t total_bytes_received_; |
66 int64_t total_bytes_to_be_received_; | 66 int64_t total_bytes_to_be_received_; |
67 Status status_; | 67 Status status_; |
68 }; | 68 }; |
69 | 69 |
70 } // namespace nacl | 70 } // namespace nacl |
OLD | NEW |