[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 5 | #include "ppapi/c/pp_completion_callback.h" |
| 6 | #include "ppapi/c/pp_errors.h" |
[email protected] | ea505a9d | 2011-07-07 18:34:40 | [diff] [blame] | 7 | #include "ppapi/c/trusted/ppb_file_io_trusted.h" |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 8 | #include "ppapi/thunk/enter.h" |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 9 | #include "ppapi/thunk/thunk.h" |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 10 | #include "ppapi/thunk/ppb_file_io_api.h" |
| 11 | #include "ppapi/thunk/resource_creation_api.h" |
| 12 | |
| 13 | namespace ppapi { |
| 14 | namespace thunk { |
| 15 | |
| 16 | namespace { |
| 17 | |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 18 | typedef EnterResource<PPB_FileIO_API> EnterFileIO; |
| 19 | |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 20 | int32_t GetOSFileDescriptor(PP_Resource file_io) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 21 | EnterFileIO enter(file_io, true); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 22 | if (enter.failed()) |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 23 | return enter.retval(); |
| 24 | return enter.SetResult(enter.object()->GetOSFileDescriptor()); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | int32_t WillWrite(PP_Resource file_io, |
| 28 | int64_t offset, |
| 29 | int32_t bytes_to_write, |
| 30 | PP_CompletionCallback callback) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 31 | EnterFileIO enter(file_io, callback, true); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 32 | if (enter.failed()) |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 33 | return enter.retval(); |
| 34 | return enter.SetResult(enter.object()->WillWrite(offset, bytes_to_write, |
| 35 | callback)); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | int32_t WillSetLength(PP_Resource file_io, |
| 39 | int64_t length, |
| 40 | PP_CompletionCallback callback) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 41 | EnterFileIO enter(file_io, callback, true); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 42 | if (enter.failed()) |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 43 | return enter.retval(); |
| 44 | return enter.SetResult(enter.object()->WillSetLength(length, callback)); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | ea505a9d | 2011-07-07 18:34:40 | [diff] [blame] | 47 | const PPB_FileIOTrusted g_ppb_file_io_trusted_thunk = { |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 48 | &GetOSFileDescriptor, |
| 49 | &WillWrite, |
| 50 | &WillSetLength |
| 51 | }; |
| 52 | |
| 53 | } // namespace |
| 54 | |
[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 55 | const PPB_FileIOTrusted_0_4* GetPPB_FileIOTrusted_0_4_Thunk() { |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 56 | return &g_ppb_file_io_trusted_thunk; |
| 57 | } |
| 58 | |
| 59 | } // namespace thunk |
| 60 | } // namespace ppapi |