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
3 // found in the LICENSE file.
7 #include "base/callback.h"
8 #include "base/files/file.h"
9 #include "components/nacl/renderer/ppb_nacl_private.h"
10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
20 // Downloads a file and writes the contents to a specified file open for
22 class FileDownloader
: public blink::WebURLLoaderClient
{
30 // Provides the FileDownloader status and the HTTP status code.
31 typedef base::Callback
<void(Status
, base::File
, int)> StatusCallback
;
33 // Provides the bytes received so far, and the total bytes expected to be
35 typedef base::Callback
<void(int64_t, int64_t)> ProgressCallback
;
37 FileDownloader(scoped_ptr
<blink::WebURLLoader
> url_loader
,
39 StatusCallback status_cb
,
40 ProgressCallback progress_cb
);
42 virtual ~FileDownloader();
44 void Load(const blink::WebURLRequest
& request
);
47 // WebURLLoaderClient implementation.
48 virtual void didReceiveResponse(blink::WebURLLoader
* loader
,
49 const blink::WebURLResponse
& response
);
50 virtual void didReceiveData(blink::WebURLLoader
* loader
,
53 int encoded_data_length
);
54 virtual void didFinishLoading(blink::WebURLLoader
* loader
,
56 int64_t total_encoded_data_length
);
57 virtual void didFail(blink::WebURLLoader
* loader
,
58 const blink::WebURLError
& error
);
60 scoped_ptr
<blink::WebURLLoader
> url_loader_
;
62 StatusCallback status_cb_
;
63 ProgressCallback progress_cb_
;
64 int http_status_code_
;
65 int64_t total_bytes_received_
;
66 int64_t total_bytes_to_be_received_
;