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