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
3 // found in the LICENSE file.
5 // From ppb_file_io.idl modified Tue Apr 16 11:25:44 2013.
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_file_io.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_file_io_api.h"
13 #include "ppapi/thunk/ppb_instance_api.h"
14 #include "ppapi/thunk/resource_creation_api.h"
15 #include "ppapi/thunk/thunk.h"
22 PP_Resource
Create(PP_Instance instance
) {
23 VLOG(4) << "PPB_FileIO::Create()";
24 EnterResourceCreation
enter(instance
);
27 return enter
.functions()->CreateFileIO(instance
);
30 PP_Bool
IsFileIO(PP_Resource resource
) {
31 VLOG(4) << "PPB_FileIO::IsFileIO()";
32 EnterResource
<PPB_FileIO_API
> enter(resource
, false);
33 return PP_FromBool(enter
.succeeded());
36 int32_t Open(PP_Resource file_io
,
39 struct PP_CompletionCallback callback
) {
40 VLOG(4) << "PPB_FileIO::Open()";
41 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
43 return enter
.retval();
44 return enter
.SetResult(enter
.object()->Open(file_ref
,
49 int32_t Query(PP_Resource file_io
,
50 struct PP_FileInfo
* info
,
51 struct PP_CompletionCallback callback
) {
52 VLOG(4) << "PPB_FileIO::Query()";
53 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
55 return enter
.retval();
56 return enter
.SetResult(enter
.object()->Query(info
, enter
.callback()));
59 int32_t Touch(PP_Resource file_io
,
60 PP_Time last_access_time
,
61 PP_Time last_modified_time
,
62 struct PP_CompletionCallback callback
) {
63 VLOG(4) << "PPB_FileIO::Touch()";
64 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
66 return enter
.retval();
67 return enter
.SetResult(enter
.object()->Touch(last_access_time
,
72 int32_t Read(PP_Resource file_io
,
75 int32_t bytes_to_read
,
76 struct PP_CompletionCallback callback
) {
77 VLOG(4) << "PPB_FileIO::Read()";
78 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
80 return enter
.retval();
81 return enter
.SetResult(enter
.object()->Read(offset
,
87 int32_t Write(PP_Resource file_io
,
90 int32_t bytes_to_write
,
91 struct PP_CompletionCallback callback
) {
92 VLOG(4) << "PPB_FileIO::Write()";
93 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
95 return enter
.retval();
96 return enter
.SetResult(enter
.object()->Write(offset
,
102 int32_t SetLength(PP_Resource file_io
,
104 struct PP_CompletionCallback callback
) {
105 VLOG(4) << "PPB_FileIO::SetLength()";
106 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
108 return enter
.retval();
109 return enter
.SetResult(enter
.object()->SetLength(length
, enter
.callback()));
112 int32_t Flush(PP_Resource file_io
, struct PP_CompletionCallback callback
) {
113 VLOG(4) << "PPB_FileIO::Flush()";
114 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
116 return enter
.retval();
117 return enter
.SetResult(enter
.object()->Flush(enter
.callback()));
120 void Close(PP_Resource file_io
) {
121 VLOG(4) << "PPB_FileIO::Close()";
122 EnterResource
<PPB_FileIO_API
> enter(file_io
, true);
125 enter
.object()->Close();
128 int32_t ReadToArray(PP_Resource file_io
,
130 int32_t max_read_length
,
131 struct PP_ArrayOutput
* output
,
132 struct PP_CompletionCallback callback
) {
133 VLOG(4) << "PPB_FileIO::ReadToArray()";
134 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
136 return enter
.retval();
137 return enter
.SetResult(enter
.object()->ReadToArray(offset
,
143 const PPB_FileIO_1_0 g_ppb_fileio_thunk_1_0
= {
156 const PPB_FileIO_1_1 g_ppb_fileio_thunk_1_1
= {
172 const PPB_FileIO_1_0
* GetPPB_FileIO_1_0_Thunk() {
173 return &g_ppb_fileio_thunk_1_0
;
176 const PPB_FileIO_1_1
* GetPPB_FileIO_1_1_Thunk() {
177 return &g_ppb_fileio_thunk_1_1
;