| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 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 | 5 |
| 6 #include "nacl_mounts/mount_html5fs.h" | 6 #include "nacl_mounts/mount_html5fs.h" |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <ppapi/c/pp_completion_callback.h> | 9 #include <ppapi/c/pp_completion_callback.h> |
| 10 #include <ppapi/c/pp_errors.h> | 10 #include <ppapi/c/pp_errors.h> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 int MountHtml5Fs::Unlink(const Path& path) { | 62 int MountHtml5Fs::Unlink(const Path& path) { |
| 63 return Remove(path); | 63 return Remove(path); |
| 64 } | 64 } |
| 65 | 65 |
| 66 int MountHtml5Fs::Mkdir(const Path& path, int permissions) { | 66 int MountHtml5Fs::Mkdir(const Path& path, int permissions) { |
| 67 if (!IsFilesystemOpen()) { | 67 if (!IsFilesystemOpen()) { |
| 68 errno = EINVAL; | 68 errno = EINVAL; |
| 69 return -1; | 69 return -1; |
| 70 } | 70 } |
| 71 | 71 |
| 72 PP_Resource fileref_resource = ppapi()->GetFileRefInterface()->Create( | 72 ScopedResource fileref_resource( |
| 73 filesystem_resource_, path.Join().c_str()); | 73 ppapi(), ppapi()->GetFileRefInterface()->Create(filesystem_resource_, |
| 74 if (!fileref_resource) { | 74 path.Join().c_str())); |
| 75 if (!fileref_resource.pp_resource()) { |
| 75 errno = EINVAL; | 76 errno = EINVAL; |
| 76 return -1; | 77 return -1; |
| 77 } | 78 } |
| 78 | 79 |
| 79 ScopedResource scoped_resource(ppapi_, fileref_resource, | |
| 80 ScopedResource::NoAddRef()); | |
| 81 | |
| 82 int32_t result = ppapi()->GetFileRefInterface()->MakeDirectory( | 80 int32_t result = ppapi()->GetFileRefInterface()->MakeDirectory( |
| 83 fileref_resource, PP_FALSE, PP_BlockUntilComplete()); | 81 fileref_resource.pp_resource(), PP_FALSE, PP_BlockUntilComplete()); |
| 84 if (result != PP_OK) { | 82 if (result != PP_OK) { |
| 85 errno = PPErrorToErrno(result); | 83 errno = PPErrorToErrno(result); |
| 86 return -1; | 84 return -1; |
| 87 } | 85 } |
| 88 | 86 |
| 89 return 0; | 87 return 0; |
| 90 } | 88 } |
| 91 | 89 |
| 92 int MountHtml5Fs::Rmdir(const Path& path) { | 90 int MountHtml5Fs::Rmdir(const Path& path) { |
| 93 return Remove(path); | 91 return Remove(path); |
| 94 } | 92 } |
| 95 | 93 |
| 96 int MountHtml5Fs::Remove(const Path& path) { | 94 int MountHtml5Fs::Remove(const Path& path) { |
| 97 if (!IsFilesystemOpen()) { | 95 if (!IsFilesystemOpen()) { |
| 98 errno = EINVAL; | 96 errno = EINVAL; |
| 99 return -1; | 97 return -1; |
| 100 } | 98 } |
| 101 | 99 |
| 102 PP_Resource fileref_resource = ppapi()->GetFileRefInterface()->Create( | 100 ScopedResource fileref_resource( |
| 103 filesystem_resource_, path.Join().c_str()); | 101 ppapi(), ppapi()->GetFileRefInterface()->Create(filesystem_resource_, |
| 104 if (!fileref_resource) { | 102 path.Join().c_str())); |
| 103 if (!fileref_resource.pp_resource()) { |
| 105 errno = EINVAL; | 104 errno = EINVAL; |
| 106 return -1; | 105 return -1; |
| 107 } | 106 } |
| 108 | 107 |
| 109 ScopedResource scoped_resource(ppapi_, fileref_resource, | |
| 110 ScopedResource::NoAddRef()); | |
| 111 | |
| 112 int32_t result = ppapi()->GetFileRefInterface()->Delete( | 108 int32_t result = ppapi()->GetFileRefInterface()->Delete( |
| 113 fileref_resource, | 109 fileref_resource.pp_resource(), |
| 114 PP_BlockUntilComplete()); | 110 PP_BlockUntilComplete()); |
| 115 if (result != PP_OK) { | 111 if (result != PP_OK) { |
| 116 errno = PPErrorToErrno(result); | 112 errno = PPErrorToErrno(result); |
| 117 return -1; | 113 return -1; |
| 118 } | 114 } |
| 119 | 115 |
| 120 return 0; | 116 return 0; |
| 121 } | 117 } |
| 122 | 118 |
| 123 | 119 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void MountHtml5Fs::FilesystemOpenCallbackThunk(void* user_data, | 174 void MountHtml5Fs::FilesystemOpenCallbackThunk(void* user_data, |
| 179 int32_t result) { | 175 int32_t result) { |
| 180 MountHtml5Fs* self = static_cast<MountHtml5Fs*>(user_data); | 176 MountHtml5Fs* self = static_cast<MountHtml5Fs*>(user_data); |
| 181 self->FilesystemOpenCallback(result); | 177 self->FilesystemOpenCallback(result); |
| 182 } | 178 } |
| 183 | 179 |
| 184 void MountHtml5Fs::FilesystemOpenCallback(int32_t result) { | 180 void MountHtml5Fs::FilesystemOpenCallback(int32_t result) { |
| 185 AutoLock lock(&lock_); | 181 AutoLock lock(&lock_); |
| 186 filesystem_open_ = result == PP_OK; | 182 filesystem_open_ = result == PP_OK; |
| 187 } | 183 } |
| OLD | NEW |