| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_file_io.h" | 5 #include "webkit/glue/plugins/pepper_file_io.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/ppapi/c/pp_completion_callback.h" | 8 #include "third_party/ppapi/c/pp_completion_callback.h" |
| 9 #include "third_party/ppapi/c/pp_errors.h" | 9 #include "third_party/ppapi/c/pp_errors.h" |
| 10 #include "third_party/ppapi/c/ppb_file_io.h" | 10 #include "third_party/ppapi/c/ppb_file_io.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 PluginModule* module = PluginModule::FromPPModule(module_id); | 21 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 22 if (!module) | 22 if (!module) |
| 23 return 0; | 23 return 0; |
| 24 | 24 |
| 25 FileIO* file_io = new FileIO(module); | 25 FileIO* file_io = new FileIO(module); |
| 26 file_io->AddRef(); // AddRef for the caller. | 26 file_io->AddRef(); // AddRef for the caller. |
| 27 return file_io->GetResource(); | 27 return file_io->GetResource(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool IsFileIO(PP_Resource resource) { | 30 bool IsFileIO(PP_Resource resource) { |
| 31 return !!ResourceTracker::Get()->GetAsFileIO(resource).get(); | 31 return !!Resource::GetAs<FileIO>(resource).get(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 int32_t Open(PP_Resource file_io_id, | 34 int32_t Open(PP_Resource file_io_id, |
| 35 PP_Resource file_ref_id, | 35 PP_Resource file_ref_id, |
| 36 int32_t open_flags, | 36 int32_t open_flags, |
| 37 PP_CompletionCallback callback) { | 37 PP_CompletionCallback callback) { |
| 38 scoped_refptr<FileIO> file_io( | 38 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 39 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 40 if (!file_io.get()) | 39 if (!file_io.get()) |
| 41 return PP_Error_BadResource; | 40 return PP_Error_BadResource; |
| 42 | 41 |
| 43 scoped_refptr<FileRef> file_ref( | 42 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); |
| 44 ResourceTracker::Get()->GetAsFileRef(file_ref_id)); | |
| 45 if (!file_ref.get()) | 43 if (!file_ref.get()) |
| 46 return PP_Error_BadResource; | 44 return PP_Error_BadResource; |
| 47 | 45 |
| 48 return file_io->Open(file_ref, open_flags, callback); | 46 return file_io->Open(file_ref, open_flags, callback); |
| 49 } | 47 } |
| 50 | 48 |
| 51 int32_t Query(PP_Resource file_io_id, | 49 int32_t Query(PP_Resource file_io_id, |
| 52 PP_FileInfo* info, | 50 PP_FileInfo* info, |
| 53 PP_CompletionCallback callback) { | 51 PP_CompletionCallback callback) { |
| 54 scoped_refptr<FileIO> file_io( | 52 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 55 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 56 if (!file_io.get()) | 53 if (!file_io.get()) |
| 57 return PP_Error_BadResource; | 54 return PP_Error_BadResource; |
| 58 | 55 |
| 59 return file_io->Query(info, callback); | 56 return file_io->Query(info, callback); |
| 60 } | 57 } |
| 61 | 58 |
| 62 int32_t Touch(PP_Resource file_io_id, | 59 int32_t Touch(PP_Resource file_io_id, |
| 63 PP_Time last_access_time, | 60 PP_Time last_access_time, |
| 64 PP_Time last_modified_time, | 61 PP_Time last_modified_time, |
| 65 PP_CompletionCallback callback) { | 62 PP_CompletionCallback callback) { |
| 66 scoped_refptr<FileIO> file_io( | 63 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 67 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 68 if (!file_io.get()) | 64 if (!file_io.get()) |
| 69 return PP_Error_BadResource; | 65 return PP_Error_BadResource; |
| 70 | 66 |
| 71 return file_io->Touch(last_access_time, last_modified_time, callback); | 67 return file_io->Touch(last_access_time, last_modified_time, callback); |
| 72 } | 68 } |
| 73 | 69 |
| 74 int32_t Read(PP_Resource file_io_id, | 70 int32_t Read(PP_Resource file_io_id, |
| 75 int64_t offset, | 71 int64_t offset, |
| 76 char* buffer, | 72 char* buffer, |
| 77 int32_t bytes_to_read, | 73 int32_t bytes_to_read, |
| 78 PP_CompletionCallback callback) { | 74 PP_CompletionCallback callback) { |
| 79 scoped_refptr<FileIO> file_io( | 75 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 80 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 81 if (!file_io.get()) | 76 if (!file_io.get()) |
| 82 return PP_Error_BadResource; | 77 return PP_Error_BadResource; |
| 83 | 78 |
| 84 return file_io->Read(offset, buffer, bytes_to_read, callback); | 79 return file_io->Read(offset, buffer, bytes_to_read, callback); |
| 85 } | 80 } |
| 86 | 81 |
| 87 int32_t Write(PP_Resource file_io_id, | 82 int32_t Write(PP_Resource file_io_id, |
| 88 int64_t offset, | 83 int64_t offset, |
| 89 const char* buffer, | 84 const char* buffer, |
| 90 int32_t bytes_to_write, | 85 int32_t bytes_to_write, |
| 91 PP_CompletionCallback callback) { | 86 PP_CompletionCallback callback) { |
| 92 scoped_refptr<FileIO> file_io( | 87 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 93 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 94 if (!file_io.get()) | 88 if (!file_io.get()) |
| 95 return PP_Error_BadResource; | 89 return PP_Error_BadResource; |
| 96 | 90 |
| 97 return file_io->Write(offset, buffer, bytes_to_write, callback); | 91 return file_io->Write(offset, buffer, bytes_to_write, callback); |
| 98 } | 92 } |
| 99 | 93 |
| 100 int32_t SetLength(PP_Resource file_io_id, | 94 int32_t SetLength(PP_Resource file_io_id, |
| 101 int64_t length, | 95 int64_t length, |
| 102 PP_CompletionCallback callback) { | 96 PP_CompletionCallback callback) { |
| 103 scoped_refptr<FileIO> file_io( | 97 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 104 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 105 if (!file_io.get()) | 98 if (!file_io.get()) |
| 106 return PP_Error_BadResource; | 99 return PP_Error_BadResource; |
| 107 | 100 |
| 108 return file_io->SetLength(length, callback); | 101 return file_io->SetLength(length, callback); |
| 109 } | 102 } |
| 110 | 103 |
| 111 int32_t Flush(PP_Resource file_io_id, | 104 int32_t Flush(PP_Resource file_io_id, |
| 112 PP_CompletionCallback callback) { | 105 PP_CompletionCallback callback) { |
| 113 scoped_refptr<FileIO> file_io( | 106 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 114 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 115 if (!file_io.get()) | 107 if (!file_io.get()) |
| 116 return PP_Error_BadResource; | 108 return PP_Error_BadResource; |
| 117 | 109 |
| 118 return file_io->Flush(callback); | 110 return file_io->Flush(callback); |
| 119 } | 111 } |
| 120 | 112 |
| 121 void Close(PP_Resource file_io_id) { | 113 void Close(PP_Resource file_io_id) { |
| 122 scoped_refptr<FileIO> file_io( | 114 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 123 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 124 if (!file_io.get()) | 115 if (!file_io.get()) |
| 125 return; | 116 return; |
| 126 | 117 |
| 127 file_io->Close(); | 118 file_io->Close(); |
| 128 } | 119 } |
| 129 | 120 |
| 130 const PPB_FileIO ppb_fileio = { | 121 const PPB_FileIO ppb_fileio = { |
| 131 &Create, | 122 &Create, |
| 132 &IsFileIO, | 123 &IsFileIO, |
| 133 &Open, | 124 &Open, |
| 134 &Query, | 125 &Query, |
| 135 &Touch, | 126 &Touch, |
| 136 &Read, | 127 &Read, |
| 137 &Write, | 128 &Write, |
| 138 &SetLength, | 129 &SetLength, |
| 139 &Flush, | 130 &Flush, |
| 140 &Close | 131 &Close |
| 141 }; | 132 }; |
| 142 | 133 |
| 143 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { | 134 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { |
| 144 scoped_refptr<FileIO> file_io( | 135 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 145 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 146 if (!file_io.get()) | 136 if (!file_io.get()) |
| 147 return PP_Error_BadResource; | 137 return PP_Error_BadResource; |
| 148 | 138 |
| 149 return file_io->GetOSFileDescriptor(); | 139 return file_io->GetOSFileDescriptor(); |
| 150 } | 140 } |
| 151 | 141 |
| 152 int32_t WillWrite(PP_Resource file_io_id, | 142 int32_t WillWrite(PP_Resource file_io_id, |
| 153 int64_t offset, | 143 int64_t offset, |
| 154 int32_t bytes_to_write, | 144 int32_t bytes_to_write, |
| 155 PP_CompletionCallback callback) { | 145 PP_CompletionCallback callback) { |
| 156 scoped_refptr<FileIO> file_io( | 146 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 157 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 158 if (!file_io.get()) | 147 if (!file_io.get()) |
| 159 return PP_Error_BadResource; | 148 return PP_Error_BadResource; |
| 160 | 149 |
| 161 return file_io->WillWrite(offset, bytes_to_write, callback); | 150 return file_io->WillWrite(offset, bytes_to_write, callback); |
| 162 } | 151 } |
| 163 | 152 |
| 164 int32_t WillSetLength(PP_Resource file_io_id, | 153 int32_t WillSetLength(PP_Resource file_io_id, |
| 165 int64_t length, | 154 int64_t length, |
| 166 PP_CompletionCallback callback) { | 155 PP_CompletionCallback callback) { |
| 167 scoped_refptr<FileIO> file_io( | 156 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
| 168 ResourceTracker::Get()->GetAsFileIO(file_io_id)); | |
| 169 if (!file_io.get()) | 157 if (!file_io.get()) |
| 170 return PP_Error_BadResource; | 158 return PP_Error_BadResource; |
| 171 | 159 |
| 172 return file_io->WillSetLength(length, callback); | 160 return file_io->WillSetLength(length, callback); |
| 173 } | 161 } |
| 174 | 162 |
| 175 const PPB_FileIOTrusted ppb_fileiotrusted = { | 163 const PPB_FileIOTrusted ppb_fileiotrusted = { |
| 176 &GetOSFileDescriptor, | 164 &GetOSFileDescriptor, |
| 177 &WillWrite, | 165 &WillWrite, |
| 178 &WillSetLength | 166 &WillSetLength |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return PP_Error_Failed; | 247 return PP_Error_Failed; |
| 260 } | 248 } |
| 261 | 249 |
| 262 int32_t FileIO::WillSetLength(int64_t length, | 250 int32_t FileIO::WillSetLength(int64_t length, |
| 263 PP_CompletionCallback callback) { | 251 PP_CompletionCallback callback) { |
| 264 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 252 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 265 return PP_Error_Failed; | 253 return PP_Error_Failed; |
| 266 } | 254 } |
| 267 | 255 |
| 268 } // namespace pepper | 256 } // namespace pepper |
| OLD | NEW |