| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_io.h" | 5 #include "ppapi/cpp/file_io.h" |
| 6 | 6 |
| 7 #include "ppapi/c/ppb_file_io.h" | 7 #include "ppapi/c/ppb_file_io.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/file_ref.h" | 10 #include "ppapi/cpp/file_ref.h" |
| 11 #include "ppapi/cpp/instance_handle.h" | 11 #include "ppapi/cpp/instance_handle.h" |
| 12 #include "ppapi/cpp/module.h" | 12 #include "ppapi/cpp/module.h" |
| 13 #include "ppapi/cpp/module_impl.h" | 13 #include "ppapi/cpp/module_impl.h" |
| 14 | 14 |
| 15 namespace pp { | 15 namespace pp { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 template <> const char* interface_name<PPB_FileIO>() { | 19 template <> const char* interface_name<PPB_FileIO_1_0>() { |
| 20 return PPB_FILEIO_INTERFACE; | 20 return PPB_FILEIO_INTERFACE_1_0; |
| 21 } | 21 } |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 FileIO::FileIO() { | 25 FileIO::FileIO() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 FileIO::FileIO(const InstanceHandle& instance) { | 28 FileIO::FileIO(const InstanceHandle& instance) { |
| 29 if (!has_interface<PPB_FileIO>()) | 29 if (!has_interface<PPB_FileIO_1_0>()) |
| 30 return; | 30 return; |
| 31 PassRefFromConstructor(get_interface<PPB_FileIO>()->Create( | 31 PassRefFromConstructor(get_interface<PPB_FileIO_1_0>()->Create( |
| 32 instance.pp_instance())); | 32 instance.pp_instance())); |
| 33 } | 33 } |
| 34 | 34 |
| 35 FileIO::FileIO(const FileIO& other) | 35 FileIO::FileIO(const FileIO& other) |
| 36 : Resource(other) { | 36 : Resource(other) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 int32_t FileIO::Open(const FileRef& file_ref, | 39 int32_t FileIO::Open(const FileRef& file_ref, |
| 40 int32_t open_flags, | 40 int32_t open_flags, |
| 41 const CompletionCallback& cc) { | 41 const CompletionCallback& cc) { |
| 42 if (!has_interface<PPB_FileIO>()) | 42 if (!has_interface<PPB_FileIO_1_0>()) |
| 43 return cc.MayForce(PP_ERROR_NOINTERFACE); | 43 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 44 return get_interface<PPB_FileIO>()->Open( | 44 return get_interface<PPB_FileIO_1_0>()->Open( |
| 45 pp_resource(), file_ref.pp_resource(), open_flags, | 45 pp_resource(), file_ref.pp_resource(), open_flags, |
| 46 cc.pp_completion_callback()); | 46 cc.pp_completion_callback()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 int32_t FileIO::Query(PP_FileInfo* result_buf, | 49 int32_t FileIO::Query(PP_FileInfo* result_buf, |
| 50 const CompletionCallback& cc) { | 50 const CompletionCallback& cc) { |
| 51 if (!has_interface<PPB_FileIO>()) | 51 if (!has_interface<PPB_FileIO_1_0>()) |
| 52 return cc.MayForce(PP_ERROR_NOINTERFACE); | 52 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 53 return get_interface<PPB_FileIO>()->Query( | 53 return get_interface<PPB_FileIO_1_0>()->Query( |
| 54 pp_resource(), result_buf, cc.pp_completion_callback()); | 54 pp_resource(), result_buf, cc.pp_completion_callback()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 int32_t FileIO::Touch(PP_Time last_access_time, | 57 int32_t FileIO::Touch(PP_Time last_access_time, |
| 58 PP_Time last_modified_time, | 58 PP_Time last_modified_time, |
| 59 const CompletionCallback& cc) { | 59 const CompletionCallback& cc) { |
| 60 if (!has_interface<PPB_FileIO>()) | 60 if (!has_interface<PPB_FileIO_1_0>()) |
| 61 return cc.MayForce(PP_ERROR_NOINTERFACE); | 61 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 62 return get_interface<PPB_FileIO>()->Touch( | 62 return get_interface<PPB_FileIO_1_0>()->Touch( |
| 63 pp_resource(), last_access_time, last_modified_time, | 63 pp_resource(), last_access_time, last_modified_time, |
| 64 cc.pp_completion_callback()); | 64 cc.pp_completion_callback()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 int32_t FileIO::Read(int64_t offset, | 67 int32_t FileIO::Read(int64_t offset, |
| 68 char* buffer, | 68 char* buffer, |
| 69 int32_t bytes_to_read, | 69 int32_t bytes_to_read, |
| 70 const CompletionCallback& cc) { | 70 const CompletionCallback& cc) { |
| 71 if (!has_interface<PPB_FileIO>()) | 71 if (!has_interface<PPB_FileIO_1_0>()) |
| 72 return cc.MayForce(PP_ERROR_NOINTERFACE); | 72 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 73 return get_interface<PPB_FileIO>()->Read(pp_resource(), | 73 return get_interface<PPB_FileIO_1_0>()->Read(pp_resource(), |
| 74 offset, buffer, bytes_to_read, cc.pp_completion_callback()); | 74 offset, buffer, bytes_to_read, cc.pp_completion_callback()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 int32_t FileIO::Write(int64_t offset, | 77 int32_t FileIO::Write(int64_t offset, |
| 78 const char* buffer, | 78 const char* buffer, |
| 79 int32_t bytes_to_write, | 79 int32_t bytes_to_write, |
| 80 const CompletionCallback& cc) { | 80 const CompletionCallback& cc) { |
| 81 if (!has_interface<PPB_FileIO>()) | 81 if (!has_interface<PPB_FileIO_1_0>()) |
| 82 return cc.MayForce(PP_ERROR_NOINTERFACE); | 82 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 83 return get_interface<PPB_FileIO>()->Write( | 83 return get_interface<PPB_FileIO_1_0>()->Write( |
| 84 pp_resource(), offset, buffer, bytes_to_write, | 84 pp_resource(), offset, buffer, bytes_to_write, |
| 85 cc.pp_completion_callback()); | 85 cc.pp_completion_callback()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 int32_t FileIO::SetLength(int64_t length, | 88 int32_t FileIO::SetLength(int64_t length, |
| 89 const CompletionCallback& cc) { | 89 const CompletionCallback& cc) { |
| 90 if (!has_interface<PPB_FileIO>()) | 90 if (!has_interface<PPB_FileIO_1_0>()) |
| 91 return cc.MayForce(PP_ERROR_NOINTERFACE); | 91 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 92 return get_interface<PPB_FileIO>()->SetLength( | 92 return get_interface<PPB_FileIO_1_0>()->SetLength( |
| 93 pp_resource(), length, cc.pp_completion_callback()); | 93 pp_resource(), length, cc.pp_completion_callback()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 int32_t FileIO::Flush(const CompletionCallback& cc) { | 96 int32_t FileIO::Flush(const CompletionCallback& cc) { |
| 97 if (!has_interface<PPB_FileIO>()) | 97 if (!has_interface<PPB_FileIO_1_0>()) |
| 98 return cc.MayForce(PP_ERROR_NOINTERFACE); | 98 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 99 return get_interface<PPB_FileIO>()->Flush( | 99 return get_interface<PPB_FileIO_1_0>()->Flush( |
| 100 pp_resource(), cc.pp_completion_callback()); | 100 pp_resource(), cc.pp_completion_callback()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void FileIO::Close() { | 103 void FileIO::Close() { |
| 104 if (!has_interface<PPB_FileIO>()) | 104 if (!has_interface<PPB_FileIO_1_0>()) |
| 105 return; | 105 return; |
| 106 get_interface<PPB_FileIO>()->Close(pp_resource()); | 106 get_interface<PPB_FileIO_1_0>()->Close(pp_resource()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace pp | 109 } // namespace pp |
| OLD | NEW |