Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / httpfs / http_fs_node.h
blobf9cabf0595372e8cc042a83452e1453640f6b980
1 // Copyright 2013 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 #ifndef LIBRARIES_NACL_IO_HTTPFS_HTTP_FS_NODE_H_
6 #define LIBRARIES_NACL_IO_HTTPFS_HTTP_FS_NODE_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "nacl_io/error.h"
13 #include "nacl_io/node.h"
14 #include "nacl_io/pepper_interface.h"
16 namespace nacl_io {
18 typedef std::map<std::string, std::string> StringMap_t;
20 class HttpFsNode : public Node {
21 public:
22 virtual Error FSync();
23 virtual Error GetDents(size_t offs,
24 struct dirent* pdir,
25 size_t count,
26 int* out_bytes);
27 virtual Error GetStat(struct stat* stat);
28 virtual Error Read(const HandleAttr& attr,
29 void* buf,
30 size_t count,
31 int* out_bytes);
32 virtual Error FTruncate(off_t size);
33 virtual Error Write(const HandleAttr& attr,
34 const void* buf,
35 size_t count,
36 int* out_bytes);
37 virtual Error GetSize(off_t* out_size);
39 void SetCachedSize(off_t size);
41 protected:
42 HttpFsNode(Filesystem* filesystem,
43 const std::string& url,
44 bool cache_content);
46 virtual ~HttpFsNode();
48 private:
49 Error GetStat_Locked(struct stat* stat);
50 Error OpenUrl(const char* method,
51 StringMap_t* request_headers,
52 ScopedResource* out_loader,
53 ScopedResource* out_request,
54 ScopedResource* out_response,
55 int32_t* out_statuscode,
56 StringMap_t* out_response_headers);
58 Error DownloadToCache();
59 Error ReadPartialFromCache(const HandleAttr& attr,
60 void* buf,
61 int count,
62 int* out_bytes);
63 Error DownloadPartial(const HandleAttr& attr,
64 void* buf,
65 off_t count,
66 int* out_bytes);
68 Error DownloadToTemp(off_t* out_bytes);
70 // Read as much as possible from |loader|, using |buffer_| as a scratch area.
71 Error ReadEntireResponseToTemp(const ScopedResource& loader,
72 off_t* out_bytes);
73 // Read as much as possible from |loader|, storing the result in
74 // |cached_data_|.
75 Error ReadEntireResponseToCache(const ScopedResource& loader, int* out_bytes);
77 // Read up to |count| bytes from |loader|, using |buffer_| as a scratch area.
78 Error ReadResponseToTemp(const ScopedResource& loader,
79 int count,
80 int* out_bytes);
82 // Read up to |count| bytes from |loader|, and store the result in |buf|,
83 // which is assumed to have |count| bytes free.
84 Error ReadResponseToBuffer(const ScopedResource& loader,
85 void* buf,
86 int count,
87 int* out_bytes);
89 std::string url_;
90 char* buffer_;
91 int buffer_len_;
93 bool cache_content_;
94 bool has_cached_size_;
95 std::vector<char> cached_data_;
97 friend class HttpFs;
100 } // namespace nacl_io
102 #endif // LIBRARIES_NACL_IO_HTTPFS_HTTP_FS_NODE_H_