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