OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 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. |
| 4 */ |
| 5 |
| 6 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_HTTP_H_ |
| 7 #define LIBRARIES_NACL_IO_MOUNT_NODE_HTTP_H_ |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "nacl_io/error.h" |
| 14 #include "nacl_io/mount_node.h" |
| 15 #include "nacl_io/pepper_interface.h" |
| 16 |
| 17 typedef std::map<std::string, std::string> StringMap_t; |
| 18 |
| 19 class MountNodeHttp : public MountNode { |
| 20 public: |
| 21 virtual Error FSync(); |
| 22 virtual Error GetDents(size_t offs, |
| 23 struct dirent* pdir, |
| 24 size_t count, |
| 25 int* out_bytes); |
| 26 virtual Error GetStat(struct stat* stat); |
| 27 virtual Error Read(size_t offs, void* buf, size_t count, int* out_bytes); |
| 28 virtual Error FTruncate(off_t size); |
| 29 virtual Error Write(size_t offs, |
| 30 const void* buf, |
| 31 size_t count, |
| 32 int* out_bytes); |
| 33 virtual Error GetSize(size_t* out_size); |
| 34 |
| 35 void SetCachedSize(off_t size); |
| 36 |
| 37 protected: |
| 38 MountNodeHttp(Mount* mount, const std::string& url, bool cache_content); |
| 39 |
| 40 private: |
| 41 Error OpenUrl(const char* method, |
| 42 StringMap_t* request_headers, |
| 43 PP_Resource* out_loader, |
| 44 PP_Resource* out_request, |
| 45 PP_Resource* out_response, |
| 46 int32_t* out_statuscode, |
| 47 StringMap_t* out_response_headers); |
| 48 |
| 49 Error DownloadToCache(); |
| 50 Error ReadPartialFromCache(size_t offs, |
| 51 void* buf, |
| 52 size_t count, |
| 53 int* out_bytes); |
| 54 Error DownloadPartial(size_t offs, void* buf, size_t count, int* out_bytes); |
| 55 Error DownloadToBuffer(PP_Resource loader, |
| 56 void* buf, |
| 57 size_t count, |
| 58 int* out_bytes); |
| 59 |
| 60 std::string url_; |
| 61 std::vector<char> buffer_; |
| 62 |
| 63 bool cache_content_; |
| 64 bool has_cached_size_; |
| 65 std::vector<char> cached_data_; |
| 66 |
| 67 friend class MountHttp; |
| 68 }; |
| 69 |
| 70 #endif // LIBRARIES_NACL_IO_MOUNT_NODE_HTTP_H_ |
OLD | NEW |