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.
5 #include "ppapi/cpp/trusted/file_io_trusted.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/trusted/ppb_file_io_trusted.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/file_io.h"
11 #include "ppapi/cpp/module_impl.h"
17 template <> const char* interface_name
<PPB_FileIOTrusted
>() {
18 return PPB_FILEIOTRUSTED_INTERFACE_0_4
;
23 FileIO_Trusted::FileIO_Trusted() {
26 int32_t FileIO_Trusted::GetOSFileDescriptor(const FileIO
& file_io
) {
27 const int32_t kInvalidOSFileDescriptor
= -1;
28 if (!has_interface
<PPB_FileIOTrusted
>())
29 return kInvalidOSFileDescriptor
;
30 return get_interface
<PPB_FileIOTrusted
>()->GetOSFileDescriptor(
31 file_io
.pp_resource());
34 int32_t FileIO_Trusted::WillWrite(const FileIO
& file_io
,
36 int32_t bytes_to_write
,
37 const CompletionCallback
& callback
) {
38 if (!has_interface
<PPB_FileIOTrusted
>())
39 return callback
.MayForce(PP_ERROR_NOINTERFACE
);
40 return get_interface
<PPB_FileIOTrusted
>()->WillWrite(
41 file_io
.pp_resource(), offset
, bytes_to_write
,
42 callback
.pp_completion_callback());
45 int32_t FileIO_Trusted::WillSetLength(const FileIO
& file_io
,
47 const CompletionCallback
& callback
) {
48 if (!has_interface
<PPB_FileIOTrusted
>())
49 return callback
.MayForce(PP_ERROR_NOINTERFACE
);
50 return get_interface
<PPB_FileIOTrusted
>()->WillSetLength(
51 file_io
.pp_resource(), length
, callback
.pp_completion_callback());