cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / thunk / ppb_file_ref_thunk.cc
blobbeb0e41f5738e96fd7c8060943e684237d54ff11
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 #include "ppapi/c/pp_file_info.h"
6 #include "ppapi/c/ppb_file_ref.h"
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/private/ppb_file_ref_private.h"
10 #include "ppapi/shared_impl/proxy_lock.h"
11 #include "ppapi/shared_impl/tracked_callback.h"
12 #include "ppapi/thunk/enter.h"
13 #include "ppapi/thunk/thunk.h"
14 #include "ppapi/thunk/ppb_file_ref_api.h"
15 #include "ppapi/thunk/ppb_file_system_api.h"
16 #include "ppapi/thunk/resource_creation_api.h"
18 namespace ppapi {
19 namespace thunk {
21 namespace {
23 typedef EnterResource<PPB_FileRef_API> EnterFileRef;
25 PP_Resource Create(PP_Resource file_system, const char* path) {
26 VLOG(4) << "PPB_FileRef::Create()";
27 ppapi::ProxyAutoLock lock;
28 EnterResourceNoLock<PPB_FileSystem_API> enter_file_system(file_system, true);
29 if (enter_file_system.failed())
30 return 0;
31 PP_Instance instance = enter_file_system.resource()->pp_instance();
32 EnterResourceCreationNoLock enter(instance);
33 if (enter.failed())
34 return 0;
35 return enter.functions()->CreateFileRef(instance, file_system, path);
38 PP_Bool IsFileRef(PP_Resource resource) {
39 VLOG(4) << "PPB_FileRef::IsFileRef()";
40 EnterFileRef enter(resource, false);
41 return PP_FromBool(enter.succeeded());
44 PP_FileSystemType GetFileSystemType(PP_Resource file_ref) {
45 VLOG(4) << "PPB_FileRef::GetFileSystemType()";
46 EnterFileRef enter(file_ref, true);
47 if (enter.failed())
48 return PP_FILESYSTEMTYPE_INVALID;
49 return enter.object()->GetFileSystemType();
52 PP_Var GetName(PP_Resource file_ref) {
53 VLOG(4) << "PPB_FileRef::GetName()";
54 EnterFileRef enter(file_ref, true);
55 if (enter.failed())
56 return PP_MakeUndefined();
57 return enter.object()->GetName();
60 PP_Var GetPath(PP_Resource file_ref) {
61 VLOG(4) << "PPB_FileRef::GetPath()";
62 EnterFileRef enter(file_ref, true);
63 if (enter.failed())
64 return PP_MakeUndefined();
65 return enter.object()->GetPath();
68 PP_Resource GetParent(PP_Resource file_ref) {
69 VLOG(4) << "PPB_FileRef::GetParent()";
70 EnterFileRef enter(file_ref, true);
71 if (enter.failed())
72 return 0;
73 return enter.object()->GetParent();
76 int32_t MakeDirectory(PP_Resource directory_ref,
77 PP_Bool make_ancestors,
78 PP_CompletionCallback callback) {
79 VLOG(4) << "PPB_FileRef::MakeDirectory()";
80 EnterFileRef enter(directory_ref, callback, true);
81 if (enter.failed())
82 return enter.retval();
83 return enter.SetResult(enter.object()->MakeDirectory(make_ancestors,
84 enter.callback()));
87 int32_t Touch(PP_Resource file_ref,
88 PP_Time last_access_time,
89 PP_Time last_modified_time,
90 PP_CompletionCallback callback) {
91 VLOG(4) << "PPB_FileRef::Touch()";
92 EnterFileRef enter(file_ref, callback, true);
93 if (enter.failed())
94 return enter.retval();
95 return enter.SetResult(enter.object()->Touch(
96 last_access_time, last_modified_time, enter.callback()));
99 int32_t Delete(PP_Resource file_ref,
100 PP_CompletionCallback callback) {
101 VLOG(4) << "PPB_FileRef::Delete()";
102 EnterFileRef enter(file_ref, callback, true);
103 if (enter.failed())
104 return enter.retval();
105 return enter.SetResult(enter.object()->Delete(enter.callback()));
108 int32_t Rename(PP_Resource file_ref,
109 PP_Resource new_file_ref,
110 PP_CompletionCallback callback) {
111 VLOG(4) << "PPB_FileRef::Rename()";
112 EnterFileRef enter(file_ref, callback, true);
113 if (enter.failed())
114 return enter.retval();
115 return enter.SetResult(enter.object()->Rename(new_file_ref,
116 enter.callback()));
119 int32_t Query(PP_Resource file_ref,
120 PP_FileInfo* info,
121 PP_CompletionCallback callback) {
122 VLOG(4) << "PPB_FileRef::Query()";
123 EnterFileRef enter(file_ref, callback, true);
124 if (enter.failed())
125 return enter.retval();
126 return enter.SetResult(enter.object()->Query(info,
127 enter.callback()));
130 int32_t ReadDirectoryEntries(PP_Resource file_ref,
131 PP_ArrayOutput output,
132 PP_CompletionCallback callback) {
133 EnterFileRef enter(file_ref, callback, true);
134 if (enter.failed())
135 return enter.retval();
136 return enter.SetResult(enter.object()->ReadDirectoryEntries(
137 output, enter.callback()));
140 PP_Var GetAbsolutePath(PP_Resource file_ref) {
141 VLOG(4) << "PPB_FileRef::GetAbsolutePath";
142 EnterFileRef enter(file_ref, true);
143 if (enter.failed())
144 return PP_MakeUndefined();
145 return enter.object()->GetAbsolutePath();
148 const PPB_FileRef_1_0 g_ppb_file_ref_thunk_1_0 = {
149 &Create,
150 &IsFileRef,
151 &GetFileSystemType,
152 &GetName,
153 &GetPath,
154 &GetParent,
155 &MakeDirectory,
156 &Touch,
157 &Delete,
158 &Rename
161 const PPB_FileRef_1_1 g_ppb_file_ref_thunk_1_1 = {
162 &Create,
163 &IsFileRef,
164 &GetFileSystemType,
165 &GetName,
166 &GetPath,
167 &GetParent,
168 &MakeDirectory,
169 &Touch,
170 &Delete,
171 &Rename,
172 &Query,
173 &ReadDirectoryEntries
176 const PPB_FileRefPrivate g_ppb_file_ref_private_thunk = {
177 &GetAbsolutePath
180 } // namespace
182 const PPB_FileRef_1_0* GetPPB_FileRef_1_0_Thunk() {
183 return &g_ppb_file_ref_thunk_1_0;
186 const PPB_FileRef_1_1* GetPPB_FileRef_1_1_Thunk() {
187 return &g_ppb_file_ref_thunk_1_1;
190 const PPB_FileRefPrivate_0_1* GetPPB_FileRefPrivate_0_1_Thunk() {
191 return &g_ppb_file_ref_private_thunk;
194 } // namespace thunk
195 } // namespace ppapi