| 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 #include "ppapi/cpp/file_ref.h" | 5 #include "ppapi/cpp/file_ref.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_bool.h" | |
| 8 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 8 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/directory_entry.h" | 9 #include "ppapi/cpp/directory_entry.h" |
| 11 #include "ppapi/cpp/file_system.h" | 10 #include "ppapi/cpp/file_system.h" |
| 12 #include "ppapi/cpp/module_impl.h" | 11 #include "ppapi/cpp/module_impl.h" |
| 13 | 12 |
| 14 namespace pp { | 13 namespace pp { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 template <> const char* interface_name<PPB_FileRef_1_0>() { | 17 template <> const char* interface_name<PPB_FileRef_1_0>() { |
| 19 return PPB_FILEREF_INTERFACE_1_0; | 18 return PPB_FILEREF_INTERFACE_1_0; |
| 20 } | 19 } |
| 21 | 20 |
| 22 template <> const char* interface_name<PPB_FileRef_1_1>() { | 21 template <> const char* interface_name<PPB_FileRef_1_1>() { |
| 23 return PPB_FILEREF_INTERFACE_1_1; | 22 return PPB_FILEREF_INTERFACE_1_1; |
| 24 } | 23 } |
| 25 | 24 |
| 26 template <> const char* interface_name<PPB_FileRef_1_2>() { | |
| 27 return PPB_FILEREF_INTERFACE_1_2; | |
| 28 } | |
| 29 | |
| 30 } // namespace | 25 } // namespace |
| 31 | 26 |
| 32 FileRef::FileRef(PP_Resource resource) : Resource(resource) { | 27 FileRef::FileRef(PP_Resource resource) : Resource(resource) { |
| 33 } | 28 } |
| 34 | 29 |
| 35 FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) { | 30 FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) { |
| 36 } | 31 } |
| 37 | 32 |
| 38 FileRef::FileRef(const FileSystem& file_system, | 33 FileRef::FileRef(const FileSystem& file_system, |
| 39 const char* path) { | 34 const char* path) { |
| 40 if (has_interface<PPB_FileRef_1_2>()) { | 35 if (has_interface<PPB_FileRef_1_1>()) { |
| 41 PassRefFromConstructor(get_interface<PPB_FileRef_1_2>()->Create( | |
| 42 file_system.pp_resource(), path)); | |
| 43 } else if (has_interface<PPB_FileRef_1_1>()) { | |
| 44 PassRefFromConstructor(get_interface<PPB_FileRef_1_1>()->Create( | 36 PassRefFromConstructor(get_interface<PPB_FileRef_1_1>()->Create( |
| 45 file_system.pp_resource(), path)); | 37 file_system.pp_resource(), path)); |
| 46 } else if (has_interface<PPB_FileRef_1_0>()) { | 38 } else if (has_interface<PPB_FileRef_1_0>()) { |
| 47 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create( | 39 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create( |
| 48 file_system.pp_resource(), path)); | 40 file_system.pp_resource(), path)); |
| 49 } | 41 } |
| 50 } | 42 } |
| 51 | 43 |
| 52 FileRef::FileRef(const FileRef& other) | 44 FileRef::FileRef(const FileRef& other) |
| 53 : Resource(other) { | 45 : Resource(other) { |
| 54 } | 46 } |
| 55 | 47 |
| 56 PP_FileSystemType FileRef::GetFileSystemType() const { | 48 PP_FileSystemType FileRef::GetFileSystemType() const { |
| 57 if (has_interface<PPB_FileRef_1_2>()) | |
| 58 return get_interface<PPB_FileRef_1_2>()->GetFileSystemType(pp_resource()); | |
| 59 if (has_interface<PPB_FileRef_1_1>()) | 49 if (has_interface<PPB_FileRef_1_1>()) |
| 60 return get_interface<PPB_FileRef_1_1>()->GetFileSystemType(pp_resource()); | 50 return get_interface<PPB_FileRef_1_1>()->GetFileSystemType(pp_resource()); |
| 61 if (has_interface<PPB_FileRef_1_0>()) | 51 if (has_interface<PPB_FileRef_1_0>()) |
| 62 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource()); | 52 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource()); |
| 63 return PP_FILESYSTEMTYPE_EXTERNAL; | 53 return PP_FILESYSTEMTYPE_EXTERNAL; |
| 64 } | 54 } |
| 65 | 55 |
| 66 Var FileRef::GetName() const { | 56 Var FileRef::GetName() const { |
| 67 if (has_interface<PPB_FileRef_1_2>()) { | |
| 68 return Var(PASS_REF, | |
| 69 get_interface<PPB_FileRef_1_2>()->GetName(pp_resource())); | |
| 70 } | |
| 71 if (has_interface<PPB_FileRef_1_1>()) { | 57 if (has_interface<PPB_FileRef_1_1>()) { |
| 72 return Var(PASS_REF, | 58 return Var(PASS_REF, |
| 73 get_interface<PPB_FileRef_1_1>()->GetName(pp_resource())); | 59 get_interface<PPB_FileRef_1_1>()->GetName(pp_resource())); |
| 74 } | 60 } |
| 75 if (has_interface<PPB_FileRef_1_0>()) { | 61 if (has_interface<PPB_FileRef_1_0>()) { |
| 76 return Var(PASS_REF, | 62 return Var(PASS_REF, |
| 77 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource())); | 63 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource())); |
| 78 } | 64 } |
| 79 return Var(); | 65 return Var(); |
| 80 } | 66 } |
| 81 | 67 |
| 82 Var FileRef::GetPath() const { | 68 Var FileRef::GetPath() const { |
| 83 if (has_interface<PPB_FileRef_1_2>()) { | |
| 84 return Var(PASS_REF, | |
| 85 get_interface<PPB_FileRef_1_2>()->GetPath(pp_resource())); | |
| 86 } | |
| 87 if (has_interface<PPB_FileRef_1_1>()) { | 69 if (has_interface<PPB_FileRef_1_1>()) { |
| 88 return Var(PASS_REF, | 70 return Var(PASS_REF, |
| 89 get_interface<PPB_FileRef_1_1>()->GetPath(pp_resource())); | 71 get_interface<PPB_FileRef_1_1>()->GetPath(pp_resource())); |
| 90 } | 72 } |
| 91 if (has_interface<PPB_FileRef_1_0>()) { | 73 if (has_interface<PPB_FileRef_1_0>()) { |
| 92 return Var(PASS_REF, | 74 return Var(PASS_REF, |
| 93 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource())); | 75 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource())); |
| 94 } | 76 } |
| 95 return Var(); | 77 return Var(); |
| 96 } | 78 } |
| 97 | 79 |
| 98 FileRef FileRef::GetParent() const { | 80 FileRef FileRef::GetParent() const { |
| 99 if (has_interface<PPB_FileRef_1_2>()) { | |
| 100 return FileRef(PASS_REF, | |
| 101 get_interface<PPB_FileRef_1_2>()->GetParent(pp_resource())); | |
| 102 } | |
| 103 if (has_interface<PPB_FileRef_1_1>()) { | 81 if (has_interface<PPB_FileRef_1_1>()) { |
| 104 return FileRef(PASS_REF, | 82 return FileRef(PASS_REF, |
| 105 get_interface<PPB_FileRef_1_1>()->GetParent(pp_resource())); | 83 get_interface<PPB_FileRef_1_1>()->GetParent(pp_resource())); |
| 106 } | 84 } |
| 107 if (has_interface<PPB_FileRef_1_0>()) { | 85 if (has_interface<PPB_FileRef_1_0>()) { |
| 108 return FileRef(PASS_REF, | 86 return FileRef(PASS_REF, |
| 109 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource())); | 87 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource())); |
| 110 } | 88 } |
| 111 return FileRef(); | 89 return FileRef(); |
| 112 } | 90 } |
| 113 | 91 |
| 114 int32_t FileRef::MakeDirectory(int32_t make_directory_flags, | 92 int32_t FileRef::MakeDirectory(const CompletionCallback& cc) { |
| 115 const CompletionCallback& cc) { | |
| 116 if (has_interface<PPB_FileRef_1_2>()) { | |
| 117 return get_interface<PPB_FileRef_1_2>()->MakeDirectory( | |
| 118 pp_resource(), | |
| 119 make_directory_flags, | |
| 120 cc.pp_completion_callback()); | |
| 121 } | |
| 122 if (has_interface<PPB_FileRef_1_1>()) { | 93 if (has_interface<PPB_FileRef_1_1>()) { |
| 123 if (make_directory_flags & ~PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS) | |
| 124 return cc.MayForce(PP_ERROR_NOTSUPPORTED); | |
| 125 return get_interface<PPB_FileRef_1_1>()->MakeDirectory( | 94 return get_interface<PPB_FileRef_1_1>()->MakeDirectory( |
| 126 pp_resource(), | 95 pp_resource(), |
| 127 PP_FromBool(make_directory_flags & PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS), | 96 PP_FALSE, // make_ancestors |
| 128 cc.pp_completion_callback()); | 97 cc.pp_completion_callback()); |
| 129 } | 98 } |
| 130 if (has_interface<PPB_FileRef_1_0>()) { | 99 if (has_interface<PPB_FileRef_1_0>()) { |
| 131 if (make_directory_flags & ~PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS) | |
| 132 return cc.MayForce(PP_ERROR_NOTSUPPORTED); | |
| 133 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( | 100 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( |
| 134 pp_resource(), | 101 pp_resource(), |
| 135 PP_FromBool(make_directory_flags & PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS), | 102 PP_FALSE, // make_ancestors |
| 136 cc.pp_completion_callback()); | 103 cc.pp_completion_callback()); |
| 137 } | 104 } |
| 138 return cc.MayForce(PP_ERROR_NOINTERFACE); | 105 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 106 } |
| 107 |
| 108 int32_t FileRef::MakeDirectoryIncludingAncestors( |
| 109 const CompletionCallback& cc) { |
| 110 if (has_interface<PPB_FileRef_1_1>()) { |
| 111 return get_interface<PPB_FileRef_1_1>()->MakeDirectory( |
| 112 pp_resource(), |
| 113 PP_TRUE, // make_ancestors |
| 114 cc.pp_completion_callback()); |
| 115 } |
| 116 if (has_interface<PPB_FileRef_1_0>()) { |
| 117 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( |
| 118 pp_resource(), |
| 119 PP_TRUE, // make_ancestors |
| 120 cc.pp_completion_callback()); |
| 121 } |
| 122 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 139 } | 123 } |
| 140 | 124 |
| 141 int32_t FileRef::Touch(PP_Time last_access_time, | 125 int32_t FileRef::Touch(PP_Time last_access_time, |
| 142 PP_Time last_modified_time, | 126 PP_Time last_modified_time, |
| 143 const CompletionCallback& cc) { | 127 const CompletionCallback& cc) { |
| 144 if (has_interface<PPB_FileRef_1_2>()) { | |
| 145 return get_interface<PPB_FileRef_1_2>()->Touch( | |
| 146 pp_resource(), last_access_time, last_modified_time, | |
| 147 cc.pp_completion_callback()); | |
| 148 } | |
| 149 if (has_interface<PPB_FileRef_1_1>()) { | 128 if (has_interface<PPB_FileRef_1_1>()) { |
| 150 return get_interface<PPB_FileRef_1_1>()->Touch( | 129 return get_interface<PPB_FileRef_1_1>()->Touch( |
| 151 pp_resource(), last_access_time, last_modified_time, | 130 pp_resource(), last_access_time, last_modified_time, |
| 152 cc.pp_completion_callback()); | 131 cc.pp_completion_callback()); |
| 153 } | 132 } |
| 154 if (has_interface<PPB_FileRef_1_0>()) { | 133 if (has_interface<PPB_FileRef_1_0>()) { |
| 155 return get_interface<PPB_FileRef_1_0>()->Touch( | 134 return get_interface<PPB_FileRef_1_0>()->Touch( |
| 156 pp_resource(), last_access_time, last_modified_time, | 135 pp_resource(), last_access_time, last_modified_time, |
| 157 cc.pp_completion_callback()); | 136 cc.pp_completion_callback()); |
| 158 } | 137 } |
| 159 return cc.MayForce(PP_ERROR_NOINTERFACE); | 138 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 160 } | 139 } |
| 161 | 140 |
| 162 int32_t FileRef::Delete(const CompletionCallback& cc) { | 141 int32_t FileRef::Delete(const CompletionCallback& cc) { |
| 163 if (has_interface<PPB_FileRef_1_2>()) { | |
| 164 return get_interface<PPB_FileRef_1_2>()->Delete( | |
| 165 pp_resource(), cc.pp_completion_callback()); | |
| 166 } | |
| 167 if (has_interface<PPB_FileRef_1_1>()) { | 142 if (has_interface<PPB_FileRef_1_1>()) { |
| 168 return get_interface<PPB_FileRef_1_1>()->Delete( | 143 return get_interface<PPB_FileRef_1_1>()->Delete( |
| 169 pp_resource(), cc.pp_completion_callback()); | 144 pp_resource(), cc.pp_completion_callback()); |
| 170 } | 145 } |
| 171 if (has_interface<PPB_FileRef_1_0>()) { | 146 if (has_interface<PPB_FileRef_1_0>()) { |
| 172 return get_interface<PPB_FileRef_1_0>()->Delete( | 147 return get_interface<PPB_FileRef_1_0>()->Delete( |
| 173 pp_resource(), cc.pp_completion_callback()); | 148 pp_resource(), cc.pp_completion_callback()); |
| 174 } | 149 } |
| 175 return cc.MayForce(PP_ERROR_NOINTERFACE); | 150 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 176 } | 151 } |
| 177 | 152 |
| 178 int32_t FileRef::Rename(const FileRef& new_file_ref, | 153 int32_t FileRef::Rename(const FileRef& new_file_ref, |
| 179 const CompletionCallback& cc) { | 154 const CompletionCallback& cc) { |
| 180 if (has_interface<PPB_FileRef_1_2>()) { | |
| 181 return get_interface<PPB_FileRef_1_2>()->Rename( | |
| 182 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); | |
| 183 } | |
| 184 if (has_interface<PPB_FileRef_1_1>()) { | 155 if (has_interface<PPB_FileRef_1_1>()) { |
| 185 return get_interface<PPB_FileRef_1_1>()->Rename( | 156 return get_interface<PPB_FileRef_1_1>()->Rename( |
| 186 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); | 157 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); |
| 187 } | 158 } |
| 188 if (has_interface<PPB_FileRef_1_0>()) { | 159 if (has_interface<PPB_FileRef_1_0>()) { |
| 189 return get_interface<PPB_FileRef_1_0>()->Rename( | 160 return get_interface<PPB_FileRef_1_0>()->Rename( |
| 190 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); | 161 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); |
| 191 } | 162 } |
| 192 return cc.MayForce(PP_ERROR_NOINTERFACE); | 163 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 193 } | 164 } |
| 194 | 165 |
| 195 int32_t FileRef::Query(const CompletionCallbackWithOutput<PP_FileInfo>& cc) { | 166 int32_t FileRef::Query(const CompletionCallbackWithOutput<PP_FileInfo>& cc) { |
| 196 if (has_interface<PPB_FileRef_1_2>()) { | 167 if (!has_interface<PPB_FileRef_1_1>()) |
| 197 return get_interface<PPB_FileRef_1_2>()->Query( | 168 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 198 pp_resource(), cc.output(), cc.pp_completion_callback()); | 169 return get_interface<PPB_FileRef_1_1>()->Query( |
| 199 } | 170 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 200 if (has_interface<PPB_FileRef_1_1>()) { | |
| 201 return get_interface<PPB_FileRef_1_1>()->Query( | |
| 202 pp_resource(), cc.output(), cc.pp_completion_callback()); | |
| 203 } | |
| 204 return cc.MayForce(PP_ERROR_NOINTERFACE); | |
| 205 } | 171 } |
| 206 | 172 |
| 207 int32_t FileRef::ReadDirectoryEntries( | 173 int32_t FileRef::ReadDirectoryEntries( |
| 208 const CompletionCallbackWithOutput<std::vector<DirectoryEntry> >& | 174 const CompletionCallbackWithOutput<std::vector<DirectoryEntry> >& |
| 209 callback) { | 175 callback) { |
| 210 if (has_interface<PPB_FileRef_1_2>()) { | 176 if (!has_interface<PPB_FileRef_1_1>()) |
| 211 return get_interface<PPB_FileRef_1_2>()->ReadDirectoryEntries( | 177 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 212 pp_resource(), callback.output(), callback.pp_completion_callback()); | 178 return get_interface<PPB_FileRef_1_1>()->ReadDirectoryEntries( |
| 213 } | 179 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 214 if (has_interface<PPB_FileRef_1_1>()) { | |
| 215 return get_interface<PPB_FileRef_1_1>()->ReadDirectoryEntries( | |
| 216 pp_resource(), callback.output(), callback.pp_completion_callback()); | |
| 217 } | |
| 218 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
| 219 } | 180 } |
| 220 | 181 |
| 221 } // namespace pp | 182 } // namespace pp |
| OLD | NEW |