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_1>()) { |
|
yzshen1
2013/12/20 18:23:57
Please also check 1_2 first.
nhiroki
2014/01/06 13:24:22
Done.
| |
| 36 PassRefFromConstructor(get_interface<PPB_FileRef_1_1>()->Create( | 41 PassRefFromConstructor(get_interface<PPB_FileRef_1_1>()->Create( |
| 37 file_system.pp_resource(), path)); | 42 file_system.pp_resource(), path)); |
| 38 } else if (has_interface<PPB_FileRef_1_0>()) { | 43 } else if (has_interface<PPB_FileRef_1_0>()) { |
| 39 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create( | 44 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create( |
| 40 file_system.pp_resource(), path)); | 45 file_system.pp_resource(), path)); |
| 41 } | 46 } |
| 42 } | 47 } |
| 43 | 48 |
| 44 FileRef::FileRef(const FileRef& other) | 49 FileRef::FileRef(const FileRef& other) |
| 45 : Resource(other) { | 50 : Resource(other) { |
| 46 } | 51 } |
| 47 | 52 |
| 48 PP_FileSystemType FileRef::GetFileSystemType() const { | 53 PP_FileSystemType FileRef::GetFileSystemType() const { |
| 54 if (has_interface<PPB_FileRef_1_2>()) | |
| 55 return get_interface<PPB_FileRef_1_2>()->GetFileSystemType(pp_resource()); | |
| 49 if (has_interface<PPB_FileRef_1_1>()) | 56 if (has_interface<PPB_FileRef_1_1>()) |
| 50 return get_interface<PPB_FileRef_1_1>()->GetFileSystemType(pp_resource()); | 57 return get_interface<PPB_FileRef_1_1>()->GetFileSystemType(pp_resource()); |
| 51 if (has_interface<PPB_FileRef_1_0>()) | 58 if (has_interface<PPB_FileRef_1_0>()) |
| 52 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource()); | 59 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource()); |
| 53 return PP_FILESYSTEMTYPE_EXTERNAL; | 60 return PP_FILESYSTEMTYPE_EXTERNAL; |
| 54 } | 61 } |
| 55 | 62 |
| 56 Var FileRef::GetName() const { | 63 Var FileRef::GetName() const { |
| 64 if (has_interface<PPB_FileRef_1_2>()) { | |
| 65 return Var(PASS_REF, | |
| 66 get_interface<PPB_FileRef_1_2>()->GetName(pp_resource())); | |
| 67 } | |
| 57 if (has_interface<PPB_FileRef_1_1>()) { | 68 if (has_interface<PPB_FileRef_1_1>()) { |
| 58 return Var(PASS_REF, | 69 return Var(PASS_REF, |
| 59 get_interface<PPB_FileRef_1_1>()->GetName(pp_resource())); | 70 get_interface<PPB_FileRef_1_1>()->GetName(pp_resource())); |
| 60 } | 71 } |
| 61 if (has_interface<PPB_FileRef_1_0>()) { | 72 if (has_interface<PPB_FileRef_1_0>()) { |
| 62 return Var(PASS_REF, | 73 return Var(PASS_REF, |
| 63 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource())); | 74 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource())); |
| 64 } | 75 } |
| 65 return Var(); | 76 return Var(); |
| 66 } | 77 } |
| 67 | 78 |
| 68 Var FileRef::GetPath() const { | 79 Var FileRef::GetPath() const { |
| 80 if (has_interface<PPB_FileRef_1_2>()) { | |
| 81 return Var(PASS_REF, | |
| 82 get_interface<PPB_FileRef_1_2>()->GetPath(pp_resource())); | |
| 83 } | |
| 69 if (has_interface<PPB_FileRef_1_1>()) { | 84 if (has_interface<PPB_FileRef_1_1>()) { |
| 70 return Var(PASS_REF, | 85 return Var(PASS_REF, |
| 71 get_interface<PPB_FileRef_1_1>()->GetPath(pp_resource())); | 86 get_interface<PPB_FileRef_1_1>()->GetPath(pp_resource())); |
| 72 } | 87 } |
| 73 if (has_interface<PPB_FileRef_1_0>()) { | 88 if (has_interface<PPB_FileRef_1_0>()) { |
| 74 return Var(PASS_REF, | 89 return Var(PASS_REF, |
| 75 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource())); | 90 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource())); |
| 76 } | 91 } |
| 77 return Var(); | 92 return Var(); |
| 78 } | 93 } |
| 79 | 94 |
| 80 FileRef FileRef::GetParent() const { | 95 FileRef FileRef::GetParent() const { |
| 96 if (has_interface<PPB_FileRef_1_2>()) { | |
| 97 return FileRef(PASS_REF, | |
| 98 get_interface<PPB_FileRef_1_2>()->GetParent(pp_resource())); | |
| 99 } | |
| 81 if (has_interface<PPB_FileRef_1_1>()) { | 100 if (has_interface<PPB_FileRef_1_1>()) { |
| 82 return FileRef(PASS_REF, | 101 return FileRef(PASS_REF, |
| 83 get_interface<PPB_FileRef_1_1>()->GetParent(pp_resource())); | 102 get_interface<PPB_FileRef_1_1>()->GetParent(pp_resource())); |
| 84 } | 103 } |
| 85 if (has_interface<PPB_FileRef_1_0>()) { | 104 if (has_interface<PPB_FileRef_1_0>()) { |
| 86 return FileRef(PASS_REF, | 105 return FileRef(PASS_REF, |
| 87 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource())); | 106 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource())); |
| 88 } | 107 } |
| 89 return FileRef(); | 108 return FileRef(); |
| 90 } | 109 } |
| 91 | 110 |
| 92 int32_t FileRef::MakeDirectory(const CompletionCallback& cc) { | 111 int32_t FileRef::MakeDirectory(bool exclusive, |
| 112 bool make_ancestors, | |
| 113 const CompletionCallback& cc) { | |
| 114 if (has_interface<PPB_FileRef_1_2>()) { | |
| 115 return get_interface<PPB_FileRef_1_2>()->MakeDirectory( | |
| 116 pp_resource(), | |
| 117 PP_FromBool(exclusive), | |
| 118 PP_FromBool(make_ancestors), | |
| 119 cc.pp_completion_callback()); | |
| 120 } | |
| 93 if (has_interface<PPB_FileRef_1_1>()) { | 121 if (has_interface<PPB_FileRef_1_1>()) { |
| 94 return get_interface<PPB_FileRef_1_1>()->MakeDirectory( | 122 return get_interface<PPB_FileRef_1_1>()->MakeDirectory( |
| 95 pp_resource(), | 123 pp_resource(), |
|
yzshen1
2013/12/20 18:23:57
It seems incorrect to ignore "exclusive" silently.
nhiroki
2014/01/06 13:24:22
Hmm... each of them seems to have its merits and d
yzshen1
2014/01/06 17:53:16
I am fine with (1). Thanks!
WRT (2), I think it i
| |
| 96 PP_FALSE, // make_ancestors | 124 PP_FromBool(make_ancestors), |
| 97 cc.pp_completion_callback()); | 125 cc.pp_completion_callback()); |
| 98 } | 126 } |
| 99 if (has_interface<PPB_FileRef_1_0>()) { | 127 if (has_interface<PPB_FileRef_1_0>()) { |
| 100 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( | 128 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( |
| 101 pp_resource(), | 129 pp_resource(), |
| 102 PP_FALSE, // make_ancestors | 130 PP_Bool(make_ancestors), |
| 103 cc.pp_completion_callback()); | 131 cc.pp_completion_callback()); |
| 104 } | 132 } |
| 105 return cc.MayForce(PP_ERROR_NOINTERFACE); | 133 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 } | 134 } |
| 124 | 135 |
| 125 int32_t FileRef::Touch(PP_Time last_access_time, | 136 int32_t FileRef::Touch(PP_Time last_access_time, |
| 126 PP_Time last_modified_time, | 137 PP_Time last_modified_time, |
| 127 const CompletionCallback& cc) { | 138 const CompletionCallback& cc) { |
| 139 if (has_interface<PPB_FileRef_1_2>()) { | |
| 140 return get_interface<PPB_FileRef_1_2>()->Touch( | |
| 141 pp_resource(), last_access_time, last_modified_time, | |
| 142 cc.pp_completion_callback()); | |
| 143 } | |
| 128 if (has_interface<PPB_FileRef_1_1>()) { | 144 if (has_interface<PPB_FileRef_1_1>()) { |
| 129 return get_interface<PPB_FileRef_1_1>()->Touch( | 145 return get_interface<PPB_FileRef_1_1>()->Touch( |
| 130 pp_resource(), last_access_time, last_modified_time, | 146 pp_resource(), last_access_time, last_modified_time, |
| 131 cc.pp_completion_callback()); | 147 cc.pp_completion_callback()); |
| 132 } | 148 } |
| 133 if (has_interface<PPB_FileRef_1_0>()) { | 149 if (has_interface<PPB_FileRef_1_0>()) { |
| 134 return get_interface<PPB_FileRef_1_0>()->Touch( | 150 return get_interface<PPB_FileRef_1_0>()->Touch( |
| 135 pp_resource(), last_access_time, last_modified_time, | 151 pp_resource(), last_access_time, last_modified_time, |
| 136 cc.pp_completion_callback()); | 152 cc.pp_completion_callback()); |
| 137 } | 153 } |
| 138 return cc.MayForce(PP_ERROR_NOINTERFACE); | 154 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 139 } | 155 } |
| 140 | 156 |
| 141 int32_t FileRef::Delete(const CompletionCallback& cc) { | 157 int32_t FileRef::Delete(const CompletionCallback& cc) { |
| 158 if (has_interface<PPB_FileRef_1_2>()) { | |
| 159 return get_interface<PPB_FileRef_1_2>()->Delete( | |
| 160 pp_resource(), cc.pp_completion_callback()); | |
| 161 } | |
| 142 if (has_interface<PPB_FileRef_1_1>()) { | 162 if (has_interface<PPB_FileRef_1_1>()) { |
| 143 return get_interface<PPB_FileRef_1_1>()->Delete( | 163 return get_interface<PPB_FileRef_1_1>()->Delete( |
| 144 pp_resource(), cc.pp_completion_callback()); | 164 pp_resource(), cc.pp_completion_callback()); |
| 145 } | 165 } |
| 146 if (has_interface<PPB_FileRef_1_0>()) { | 166 if (has_interface<PPB_FileRef_1_0>()) { |
| 147 return get_interface<PPB_FileRef_1_0>()->Delete( | 167 return get_interface<PPB_FileRef_1_0>()->Delete( |
| 148 pp_resource(), cc.pp_completion_callback()); | 168 pp_resource(), cc.pp_completion_callback()); |
| 149 } | 169 } |
| 150 return cc.MayForce(PP_ERROR_NOINTERFACE); | 170 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 151 } | 171 } |
| 152 | 172 |
| 153 int32_t FileRef::Rename(const FileRef& new_file_ref, | 173 int32_t FileRef::Rename(const FileRef& new_file_ref, |
| 154 const CompletionCallback& cc) { | 174 const CompletionCallback& cc) { |
| 175 if (has_interface<PPB_FileRef_1_2>()) { | |
| 176 return get_interface<PPB_FileRef_1_2>()->Rename( | |
| 177 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); | |
| 178 } | |
| 155 if (has_interface<PPB_FileRef_1_1>()) { | 179 if (has_interface<PPB_FileRef_1_1>()) { |
| 156 return get_interface<PPB_FileRef_1_1>()->Rename( | 180 return get_interface<PPB_FileRef_1_1>()->Rename( |
| 157 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); | 181 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); |
| 158 } | 182 } |
| 159 if (has_interface<PPB_FileRef_1_0>()) { | 183 if (has_interface<PPB_FileRef_1_0>()) { |
| 160 return get_interface<PPB_FileRef_1_0>()->Rename( | 184 return get_interface<PPB_FileRef_1_0>()->Rename( |
| 161 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); | 185 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); |
| 162 } | 186 } |
| 163 return cc.MayForce(PP_ERROR_NOINTERFACE); | 187 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 164 } | 188 } |
| 165 | 189 |
| 166 int32_t FileRef::Query(const CompletionCallbackWithOutput<PP_FileInfo>& cc) { | 190 int32_t FileRef::Query(const CompletionCallbackWithOutput<PP_FileInfo>& cc) { |
| 167 if (!has_interface<PPB_FileRef_1_1>()) | 191 if (has_interface<PPB_FileRef_1_2>()) { |
| 168 return cc.MayForce(PP_ERROR_NOINTERFACE); | 192 return get_interface<PPB_FileRef_1_2>()->Query( |
| 169 return get_interface<PPB_FileRef_1_1>()->Query( | 193 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 170 pp_resource(), cc.output(), cc.pp_completion_callback()); | 194 } |
| 195 if (has_interface<PPB_FileRef_1_1>()) { | |
| 196 return get_interface<PPB_FileRef_1_1>()->Query( | |
| 197 pp_resource(), cc.output(), cc.pp_completion_callback()); | |
| 198 } | |
| 199 return cc.MayForce(PP_ERROR_NOINTERFACE); | |
| 171 } | 200 } |
| 172 | 201 |
| 173 int32_t FileRef::ReadDirectoryEntries( | 202 int32_t FileRef::ReadDirectoryEntries( |
| 174 const CompletionCallbackWithOutput<std::vector<DirectoryEntry> >& | 203 const CompletionCallbackWithOutput<std::vector<DirectoryEntry> >& |
| 175 callback) { | 204 callback) { |
| 176 if (!has_interface<PPB_FileRef_1_1>()) | 205 if (has_interface<PPB_FileRef_1_2>()) { |
| 177 return callback.MayForce(PP_ERROR_NOINTERFACE); | 206 return get_interface<PPB_FileRef_1_2>()->ReadDirectoryEntries( |
| 178 return get_interface<PPB_FileRef_1_1>()->ReadDirectoryEntries( | 207 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 179 pp_resource(), callback.output(), callback.pp_completion_callback()); | 208 } |
| 209 if (has_interface<PPB_FileRef_1_1>()) { | |
| 210 return get_interface<PPB_FileRef_1_1>()->ReadDirectoryEntries( | |
| 211 pp_resource(), callback.output(), callback.pp_completion_callback()); | |
| 212 } | |
| 213 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
| 180 } | 214 } |
| 181 | 215 |
| 182 } // namespace pp | 216 } // namespace pp |
| OLD | NEW |