Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / ppapi / thunk / ppb_file_io_thunk.cc
blob50f302e738fda860739b9535d4e474d26ed55e98
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 Mon Nov 11 16:02:07 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/ppapi_thunk_export.h"
13 #include "ppapi/thunk/ppb_file_io_api.h"
15 namespace ppapi {
16 namespace thunk {
18 namespace {
20 PP_Resource Create(PP_Instance instance) {
21 VLOG(4) << "PPB_FileIO::Create()";
22 EnterResourceCreation enter(instance);
23 if (enter.failed())
24 return 0;
25 return enter.functions()->CreateFileIO(instance);
28 PP_Bool IsFileIO(PP_Resource resource) {
29 VLOG(4) << "PPB_FileIO::IsFileIO()";
30 EnterResource<PPB_FileIO_API> enter(resource, false);
31 return PP_FromBool(enter.succeeded());
34 int32_t Open(PP_Resource file_io,
35 PP_Resource file_ref,
36 int32_t open_flags,
37 struct PP_CompletionCallback callback) {
38 VLOG(4) << "PPB_FileIO::Open()";
39 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
40 if (enter.failed())
41 return enter.retval();
42 return enter.SetResult(
43 enter.object()->Open(file_ref, open_flags, enter.callback()));
46 int32_t Query(PP_Resource file_io,
47 struct PP_FileInfo* info,
48 struct PP_CompletionCallback callback) {
49 VLOG(4) << "PPB_FileIO::Query()";
50 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
51 if (enter.failed())
52 return enter.retval();
53 return enter.SetResult(enter.object()->Query(info, enter.callback()));
56 int32_t Touch(PP_Resource file_io,
57 PP_Time last_access_time,
58 PP_Time last_modified_time,
59 struct PP_CompletionCallback callback) {
60 VLOG(4) << "PPB_FileIO::Touch()";
61 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
62 if (enter.failed())
63 return enter.retval();
64 return enter.SetResult(enter.object()->Touch(
65 last_access_time, last_modified_time, enter.callback()));
68 int32_t Read(PP_Resource file_io,
69 int64_t offset,
70 char* buffer,
71 int32_t bytes_to_read,
72 struct PP_CompletionCallback callback) {
73 VLOG(4) << "PPB_FileIO::Read()";
74 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
75 if (enter.failed())
76 return enter.retval();
77 return enter.SetResult(
78 enter.object()->Read(offset, buffer, bytes_to_read, enter.callback()));
81 int32_t Write(PP_Resource file_io,
82 int64_t offset,
83 const char* buffer,
84 int32_t bytes_to_write,
85 struct PP_CompletionCallback callback) {
86 VLOG(4) << "PPB_FileIO::Write()";
87 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
88 if (enter.failed())
89 return enter.retval();
90 return enter.SetResult(
91 enter.object()->Write(offset, buffer, bytes_to_write, enter.callback()));
94 int32_t SetLength(PP_Resource file_io,
95 int64_t length,
96 struct PP_CompletionCallback callback) {
97 VLOG(4) << "PPB_FileIO::SetLength()";
98 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
99 if (enter.failed())
100 return enter.retval();
101 return enter.SetResult(enter.object()->SetLength(length, enter.callback()));
104 int32_t Flush(PP_Resource file_io, struct PP_CompletionCallback callback) {
105 VLOG(4) << "PPB_FileIO::Flush()";
106 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
107 if (enter.failed())
108 return enter.retval();
109 return enter.SetResult(enter.object()->Flush(enter.callback()));
112 void Close(PP_Resource file_io) {
113 VLOG(4) << "PPB_FileIO::Close()";
114 EnterResource<PPB_FileIO_API> enter(file_io, true);
115 if (enter.failed())
116 return;
117 enter.object()->Close();
120 int32_t ReadToArray(PP_Resource file_io,
121 int64_t offset,
122 int32_t max_read_length,
123 struct PP_ArrayOutput* output,
124 struct PP_CompletionCallback callback) {
125 VLOG(4) << "PPB_FileIO::ReadToArray()";
126 EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
127 if (enter.failed())
128 return enter.retval();
129 return enter.SetResult(enter.object()->ReadToArray(offset, max_read_length,
130 output, enter.callback()));
133 const PPB_FileIO_1_0 g_ppb_fileio_thunk_1_0 = {&Create,
134 &IsFileIO,
135 &Open,
136 &Query,
137 &Touch,
138 &Read,
139 &Write,
140 &SetLength,
141 &Flush,
142 &Close};
144 const PPB_FileIO_1_1 g_ppb_fileio_thunk_1_1 = {&Create,
145 &IsFileIO,
146 &Open,
147 &Query,
148 &Touch,
149 &Read,
150 &Write,
151 &SetLength,
152 &Flush,
153 &Close,
154 &ReadToArray};
156 } // namespace
158 PPAPI_THUNK_EXPORT const PPB_FileIO_1_0* GetPPB_FileIO_1_0_Thunk() {
159 return &g_ppb_fileio_thunk_1_0;
162 PPAPI_THUNK_EXPORT const PPB_FileIO_1_1* GetPPB_FileIO_1_1_Thunk() {
163 return &g_ppb_fileio_thunk_1_1;
166 } // namespace thunk
167 } // namespace ppapi