blob: c291ec8c9869171687990393b13dc9dfee2f0669 [file] [log] [blame]
[email protected]256513872012-01-05 15:41:521// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]cd910b92011-06-01 07:19:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cd910b92011-06-01 07:19:315#include "ppapi/c/pp_completion_callback.h"
6#include "ppapi/c/pp_errors.h"
[email protected]ea505a9d2011-07-07 18:34:407#include "ppapi/c/trusted/ppb_file_io_trusted.h"
[email protected]cd910b92011-06-01 07:19:318#include "ppapi/thunk/enter.h"
[email protected]917e86a2011-06-30 21:42:379#include "ppapi/thunk/thunk.h"
[email protected]cd910b92011-06-01 07:19:3110#include "ppapi/thunk/ppb_file_io_api.h"
11#include "ppapi/thunk/resource_creation_api.h"
12
13namespace ppapi {
14namespace thunk {
15
16namespace {
17
[email protected]1bea0d22012-02-05 03:07:2918typedef EnterResource<PPB_FileIO_API> EnterFileIO;
19
[email protected]cd910b92011-06-01 07:19:3120int32_t GetOSFileDescriptor(PP_Resource file_io) {
[email protected]1bea0d22012-02-05 03:07:2921 EnterFileIO enter(file_io, true);
[email protected]cd910b92011-06-01 07:19:3122 if (enter.failed())
[email protected]1bea0d22012-02-05 03:07:2923 return enter.retval();
24 return enter.SetResult(enter.object()->GetOSFileDescriptor());
[email protected]cd910b92011-06-01 07:19:3125}
26
27int32_t WillWrite(PP_Resource file_io,
28 int64_t offset,
29 int32_t bytes_to_write,
30 PP_CompletionCallback callback) {
[email protected]1bea0d22012-02-05 03:07:2931 EnterFileIO enter(file_io, callback, true);
[email protected]cd910b92011-06-01 07:19:3132 if (enter.failed())
[email protected]1bea0d22012-02-05 03:07:2933 return enter.retval();
34 return enter.SetResult(enter.object()->WillWrite(offset, bytes_to_write,
35 callback));
[email protected]cd910b92011-06-01 07:19:3136}
37
38int32_t WillSetLength(PP_Resource file_io,
39 int64_t length,
40 PP_CompletionCallback callback) {
[email protected]1bea0d22012-02-05 03:07:2941 EnterFileIO enter(file_io, callback, true);
[email protected]cd910b92011-06-01 07:19:3142 if (enter.failed())
[email protected]1bea0d22012-02-05 03:07:2943 return enter.retval();
44 return enter.SetResult(enter.object()->WillSetLength(length, callback));
[email protected]cd910b92011-06-01 07:19:3145}
46
[email protected]ea505a9d2011-07-07 18:34:4047const PPB_FileIOTrusted g_ppb_file_io_trusted_thunk = {
[email protected]cd910b92011-06-01 07:19:3148 &GetOSFileDescriptor,
49 &WillWrite,
50 &WillSetLength
51};
52
53} // namespace
54
[email protected]256513872012-01-05 15:41:5255const PPB_FileIOTrusted_0_4* GetPPB_FileIOTrusted_0_4_Thunk() {
[email protected]cd910b92011-06-01 07:19:3156 return &g_ppb_file_io_trusted_thunk;
57}
58
59} // namespace thunk
60} // namespace ppapi