| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nacl_io/httpfs/http_fs_node.h" | 5 #include "nacl_io/httpfs/http_fs_node.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return EIO; | 145 return EIO; |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace | 148 } // namespace |
| 149 | 149 |
| 150 void HttpFsNode::SetCachedSize(off_t size) { | 150 void HttpFsNode::SetCachedSize(off_t size) { |
| 151 has_cached_size_ = true; | 151 has_cached_size_ = true; |
| 152 stat_.st_size = size; | 152 stat_.st_size = size; |
| 153 } | 153 } |
| 154 | 154 |
| 155 Error HttpFsNode::FSync() { return EACCES; } | 155 Error HttpFsNode::FSync() { |
| 156 return EACCES; |
| 157 } |
| 156 | 158 |
| 157 Error HttpFsNode::GetDents(size_t offs, | 159 Error HttpFsNode::GetDents(size_t offs, |
| 158 struct dirent* pdir, | 160 struct dirent* pdir, |
| 159 size_t count, | 161 size_t count, |
| 160 int* out_bytes) { | 162 int* out_bytes) { |
| 161 *out_bytes = 0; | 163 *out_bytes = 0; |
| 162 return EACCES; | 164 return EACCES; |
| 163 } | 165 } |
| 164 | 166 |
| 165 Error HttpFsNode::GetStat(struct stat* stat) { | 167 Error HttpFsNode::GetStat(struct stat* stat) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 180 if (error) | 182 if (error) |
| 181 return error; | 183 return error; |
| 182 } | 184 } |
| 183 | 185 |
| 184 return ReadPartialFromCache(attr, buf, count, out_bytes); | 186 return ReadPartialFromCache(attr, buf, count, out_bytes); |
| 185 } | 187 } |
| 186 | 188 |
| 187 return DownloadPartial(attr, buf, count, out_bytes); | 189 return DownloadPartial(attr, buf, count, out_bytes); |
| 188 } | 190 } |
| 189 | 191 |
| 190 Error HttpFsNode::FTruncate(off_t size) { return EACCES; } | 192 Error HttpFsNode::FTruncate(off_t size) { |
| 193 return EACCES; |
| 194 } |
| 191 | 195 |
| 192 Error HttpFsNode::Write(const HandleAttr& attr, | 196 Error HttpFsNode::Write(const HandleAttr& attr, |
| 193 const void* buf, | 197 const void* buf, |
| 194 size_t count, | 198 size_t count, |
| 195 int* out_bytes) { | 199 int* out_bytes) { |
| 196 // TODO(binji): support POST? | 200 // TODO(binji): support POST? |
| 197 *out_bytes = 0; | 201 *out_bytes = 0; |
| 198 return EACCES; | 202 return EACCES; |
| 199 } | 203 } |
| 200 | 204 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 212 *out_size = stat_.st_size; | 216 *out_size = stat_.st_size; |
| 213 return 0; | 217 return 0; |
| 214 } | 218 } |
| 215 | 219 |
| 216 HttpFsNode::HttpFsNode(Filesystem* filesystem, | 220 HttpFsNode::HttpFsNode(Filesystem* filesystem, |
| 217 const std::string& url, | 221 const std::string& url, |
| 218 bool cache_content) | 222 bool cache_content) |
| 219 : Node(filesystem), | 223 : Node(filesystem), |
| 220 url_(url), | 224 url_(url), |
| 221 cache_content_(cache_content), | 225 cache_content_(cache_content), |
| 222 has_cached_size_(false) {} | 226 has_cached_size_(false) { |
| 227 } |
| 223 | 228 |
| 224 void HttpFsNode::SetMode(int mode) { stat_.st_mode = mode; } | 229 void HttpFsNode::SetMode(int mode) { |
| 230 stat_.st_mode = mode; |
| 231 } |
| 225 | 232 |
| 226 Error HttpFsNode::GetStat_Locked(struct stat* stat) { | 233 Error HttpFsNode::GetStat_Locked(struct stat* stat) { |
| 227 // Assume we need to 'HEAD' if we do not know the size, otherwise, assume | 234 // Assume we need to 'HEAD' if we do not know the size, otherwise, assume |
| 228 // that the information is constant. We can add a timeout if needed. | 235 // that the information is constant. We can add a timeout if needed. |
| 229 HttpFs* filesystem = static_cast<HttpFs*>(filesystem_); | 236 HttpFs* filesystem = static_cast<HttpFs*>(filesystem_); |
| 230 if (!has_cached_size_ || !filesystem->cache_stat_) { | 237 if (!has_cached_size_ || !filesystem->cache_stat_) { |
| 231 StringMap_t headers; | 238 StringMap_t headers; |
| 232 ScopedResource loader(filesystem_->ppapi()); | 239 ScopedResource loader(filesystem_->ppapi()); |
| 233 ScopedResource request(filesystem_->ppapi()); | 240 ScopedResource request(filesystem_->ppapi()); |
| 234 ScopedResource response(filesystem_->ppapi()); | 241 ScopedResource response(filesystem_->ppapi()); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 assert(bytes_read <= bytes_to_read); | 640 assert(bytes_read <= bytes_to_read); |
| 634 bytes_to_read -= bytes_read; | 641 bytes_to_read -= bytes_read; |
| 635 out_buffer += bytes_read; | 642 out_buffer += bytes_read; |
| 636 } | 643 } |
| 637 | 644 |
| 638 *out_bytes = count; | 645 *out_bytes = count; |
| 639 return 0; | 646 return 0; |
| 640 } | 647 } |
| 641 | 648 |
| 642 } // namespace nacl_io | 649 } // namespace nacl_io |
| OLD | NEW |