15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// From ppb_file_io.idl modified Tue Apr 16 11:25:44 2013. 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_completion_callback.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_errors.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/c/ppb_file_io.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/shared_impl/tracked_callback.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/thunk/enter.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/thunk/ppb_file_io_api.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/thunk/ppb_instance_api.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/thunk/resource_creation_api.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/thunk/thunk.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ppapi { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace thunk { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PP_Resource Create(PP_Instance instance) { 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Create()"; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EnterResourceCreation enter(instance); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.functions()->CreateFileIO(instance); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PP_Bool IsFileIO(PP_Resource resource) { 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::IsFileIO()"; 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(resource, false); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return PP_FromBool(enter.succeeded()); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t Open(PP_Resource file_io, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Resource file_ref, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32_t open_flags, 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Open()"; 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return enter.SetResult(enter.object()->Open(file_ref, 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) open_flags, 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enter.callback())); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t Query(PP_Resource file_io, 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_FileInfo* info, 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Query()"; 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.SetResult(enter.object()->Query(info, enter.callback())); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t Touch(PP_Resource file_io, 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Time last_access_time, 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Time last_modified_time, 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Touch()"; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return enter.SetResult(enter.object()->Touch(last_access_time, 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) last_modified_time, 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enter.callback())); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t Read(PP_Resource file_io, 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t offset, 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char* buffer, 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32_t bytes_to_read, 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Read()"; 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return enter.SetResult(enter.object()->Read(offset, 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) buffer, 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bytes_to_read, 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enter.callback())); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t Write(PP_Resource file_io, 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t offset, 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* buffer, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32_t bytes_to_write, 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Write()"; 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return enter.SetResult(enter.object()->Write(offset, 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) buffer, 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bytes_to_write, 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enter.callback())); 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t SetLength(PP_Resource file_io, 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t length, 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::SetLength()"; 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.SetResult(enter.object()->SetLength(length, enter.callback())); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int32_t Flush(PP_Resource file_io, struct PP_CompletionCallback callback) { 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Flush()"; 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (enter.failed()) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.retval(); 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return enter.SetResult(enter.object()->Flush(enter.callback())); 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Close(PP_Resource file_io) { 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::Close()"; 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, true); 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (enter.failed()) 124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) enter.object()->Close(); 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int32_t ReadToArray(PP_Resource file_io, 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64_t offset, 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t max_read_length, 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_ArrayOutput* output, 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct PP_CompletionCallback callback) { 133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) VLOG(4) << "PPB_FileIO::ReadToArray()"; 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnterResource<PPB_FileIO_API> enter(file_io, callback, true); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (enter.failed()) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return enter.retval(); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return enter.SetResult(enter.object()->ReadToArray(offset, 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) max_read_length, 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) output, 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enter.callback())); 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const PPB_FileIO_1_0 g_ppb_fileio_thunk_1_0 = { 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Create, 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &IsFileIO, 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Open, 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Query, 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Touch, 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Read, 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Write, 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &SetLength, 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Flush, 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &Close 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const PPB_FileIO_1_1 g_ppb_fileio_thunk_1_1 = { 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Create, 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &IsFileIO, 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Open, 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Query, 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Touch, 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Read, 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Write, 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &SetLength, 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Flush, 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &Close, 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ReadToArray 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const PPB_FileIO_1_0* GetPPB_FileIO_1_0_Thunk() { 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return &g_ppb_fileio_thunk_1_0; 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const PPB_FileIO_1_1* GetPPB_FileIO_1_1_Thunk() { 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return &g_ppb_fileio_thunk_1_1; 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace thunk 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ppapi 182