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