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/html5fs/html5_fs.h" | 5 #include "nacl_io/html5fs/html5_fs.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Html5Fs::Html5Fs() | 173 Html5Fs::Html5Fs() |
174 : filesystem_iface_(NULL), | 174 : filesystem_iface_(NULL), |
175 file_ref_iface_(NULL), | 175 file_ref_iface_(NULL), |
176 file_io_iface_(NULL), | 176 file_io_iface_(NULL), |
177 filesystem_resource_(0), | 177 filesystem_resource_(0), |
178 filesystem_open_has_result_(false), | 178 filesystem_open_has_result_(false), |
179 filesystem_open_error_(0) { | 179 filesystem_open_error_(0) { |
180 } | 180 } |
181 | 181 |
182 Error Html5Fs::Init(const FsInitArgs& args) { | 182 Error Html5Fs::Init(const FsInitArgs& args) { |
| 183 pthread_cond_init(&filesystem_open_cond_, NULL); |
| 184 |
183 Error error = Filesystem::Init(args); | 185 Error error = Filesystem::Init(args); |
184 if (error) | 186 if (error) |
185 return error; | 187 return error; |
186 | 188 |
187 if (!args.ppapi) { | 189 if (!args.ppapi) { |
188 LOG_ERROR("ppapi is NULL."); | 190 LOG_ERROR("ppapi is NULL."); |
189 return ENOSYS; | 191 return ENOSYS; |
190 } | 192 } |
191 | 193 |
192 core_iface_ = ppapi()->GetCoreInterface(); | 194 core_iface_ = ppapi()->GetCoreInterface(); |
193 filesystem_iface_ = ppapi()->GetFileSystemInterface(); | 195 filesystem_iface_ = ppapi()->GetFileSystemInterface(); |
194 file_io_iface_ = ppapi()->GetFileIoInterface(); | 196 file_io_iface_ = ppapi()->GetFileIoInterface(); |
195 file_ref_iface_ = ppapi()->GetFileRefInterface(); | 197 file_ref_iface_ = ppapi()->GetFileRefInterface(); |
196 | 198 |
197 if (!(core_iface_ && filesystem_iface_ && file_io_iface_ && | 199 if (!(core_iface_ && filesystem_iface_ && file_io_iface_ && |
198 file_ref_iface_)) { | 200 file_ref_iface_)) { |
199 LOG_ERROR("Got NULL interface(s): %s%s%s%s", | 201 LOG_ERROR("Got NULL interface(s): %s%s%s%s", |
200 core_iface_ ? "" : "Core ", | 202 core_iface_ ? "" : "Core ", |
201 filesystem_iface_ ? "" : "FileSystem ", | 203 filesystem_iface_ ? "" : "FileSystem ", |
202 file_ref_iface_ ? "" : "FileRef", | 204 file_ref_iface_ ? "" : "FileRef", |
203 file_io_iface_ ? "" : "FileIo "); | 205 file_io_iface_ ? "" : "FileIo "); |
204 return ENOSYS; | 206 return ENOSYS; |
205 } | 207 } |
206 | 208 |
207 pthread_cond_init(&filesystem_open_cond_, NULL); | |
208 | |
209 // Parse filesystem args. | 209 // Parse filesystem args. |
210 PP_FileSystemType filesystem_type = PP_FILESYSTEMTYPE_LOCALPERSISTENT; | 210 PP_FileSystemType filesystem_type = PP_FILESYSTEMTYPE_LOCALPERSISTENT; |
211 int64_t expected_size = 0; | 211 int64_t expected_size = 0; |
212 for (StringMap_t::const_iterator iter = args.string_map.begin(); | 212 for (StringMap_t::const_iterator iter = args.string_map.begin(); |
213 iter != args.string_map.end(); | 213 iter != args.string_map.end(); |
214 ++iter) { | 214 ++iter) { |
215 if (iter->first == "type") { | 215 if (iter->first == "type") { |
216 if (iter->second == "PERSISTENT") { | 216 if (iter->second == "PERSISTENT") { |
217 filesystem_type = PP_FILESYSTEMTYPE_LOCALPERSISTENT; | 217 filesystem_type = PP_FILESYSTEMTYPE_LOCALPERSISTENT; |
218 } else if (iter->second == "TEMPORARY") { | 218 } else if (iter->second == "TEMPORARY") { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 270 |
271 return filesystem_open_error_; | 271 return filesystem_open_error_; |
272 } | 272 } |
273 | 273 |
274 // We have to assume the call to Open will succeed; there is no better | 274 // We have to assume the call to Open will succeed; there is no better |
275 // result to return here. | 275 // result to return here. |
276 return 0; | 276 return 0; |
277 } | 277 } |
278 | 278 |
279 void Html5Fs::Destroy() { | 279 void Html5Fs::Destroy() { |
280 ppapi_->ReleaseResource(filesystem_resource_); | 280 if (ppapi_ != NULL && filesystem_resource_ != 0) |
| 281 ppapi_->ReleaseResource(filesystem_resource_); |
281 pthread_cond_destroy(&filesystem_open_cond_); | 282 pthread_cond_destroy(&filesystem_open_cond_); |
282 } | 283 } |
283 | 284 |
284 Error Html5Fs::BlockUntilFilesystemOpen() { | 285 Error Html5Fs::BlockUntilFilesystemOpen() { |
285 AUTO_LOCK(filesysem_open_lock_); | 286 AUTO_LOCK(filesysem_open_lock_); |
286 while (!filesystem_open_has_result_) { | 287 while (!filesystem_open_has_result_) { |
287 pthread_cond_wait(&filesystem_open_cond_, filesysem_open_lock_.mutex()); | 288 pthread_cond_wait(&filesystem_open_cond_, filesysem_open_lock_.mutex()); |
288 } | 289 } |
289 return filesystem_open_error_; | 290 return filesystem_open_error_; |
290 } | 291 } |
291 | 292 |
292 // static | 293 // static |
293 void Html5Fs::FilesystemOpenCallbackThunk(void* user_data, int32_t result) { | 294 void Html5Fs::FilesystemOpenCallbackThunk(void* user_data, int32_t result) { |
294 Html5Fs* self = static_cast<Html5Fs*>(user_data); | 295 Html5Fs* self = static_cast<Html5Fs*>(user_data); |
295 self->FilesystemOpenCallback(result); | 296 self->FilesystemOpenCallback(result); |
296 } | 297 } |
297 | 298 |
298 void Html5Fs::FilesystemOpenCallback(int32_t result) { | 299 void Html5Fs::FilesystemOpenCallback(int32_t result) { |
299 AUTO_LOCK(filesysem_open_lock_); | 300 AUTO_LOCK(filesysem_open_lock_); |
300 filesystem_open_has_result_ = true; | 301 filesystem_open_has_result_ = true; |
301 filesystem_open_error_ = PPErrorToErrno(result); | 302 filesystem_open_error_ = PPErrorToErrno(result); |
302 pthread_cond_signal(&filesystem_open_cond_); | 303 pthread_cond_signal(&filesystem_open_cond_); |
303 } | 304 } |
304 | 305 |
305 } // namespace nacl_io | 306 } // namespace nacl_io |
OLD | NEW |