Don't preload rarely seen large images
[chromium-blink-merge.git] / components / nacl / renderer / file_downloader.h
blob02650d4e3a0e39c4ef48678f2ecf6e1aab5dab9c
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.
5 #include <string>
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"
12 namespace blink {
13 struct WebURLError;
14 class WebURLLoader;
15 class WebURLResponse;
18 namespace nacl {
20 // Downloads a file and writes the contents to a specified file open for
21 // writing.
22 class FileDownloader : public blink::WebURLLoaderClient {
23 public:
24 enum Status {
25 SUCCESS,
26 ACCESS_DENIED,
27 FAILED
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
34 // received.
35 typedef base::Callback<void(int64_t, int64_t)> ProgressCallback;
37 FileDownloader(scoped_ptr<blink::WebURLLoader> url_loader,
38 base::File file,
39 StatusCallback status_cb,
40 ProgressCallback progress_cb);
42 virtual ~FileDownloader();
44 void Load(const blink::WebURLRequest& request);
46 private:
47 // WebURLLoaderClient implementation.
48 virtual void didReceiveResponse(blink::WebURLLoader* loader,
49 const blink::WebURLResponse& response);
50 virtual void didReceiveData(blink::WebURLLoader* loader,
51 const char* data,
52 int data_length,
53 int encoded_data_length);
54 virtual void didFinishLoading(blink::WebURLLoader* loader,
55 double finish_time,
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_;
61 base::File file_;
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_;
67 Status status_;
70 } // namespace nacl