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"
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())
31 PP_Instance instance
= enter_file_system
.resource()->pp_instance();
32 EnterResourceCreationNoLock
enter(instance
);
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);
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);
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);
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);
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);
82 return enter
.retval();
83 return enter
.SetResult(enter
.object()->MakeDirectory(make_ancestors
,
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);
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);
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);
114 return enter
.retval();
115 return enter
.SetResult(enter
.object()->Rename(new_file_ref
,
119 int32_t Query(PP_Resource file_ref
,
121 PP_CompletionCallback callback
) {
122 VLOG(4) << "PPB_FileRef::Query()";
123 EnterFileRef
enter(file_ref
, callback
, true);
125 return enter
.retval();
126 return enter
.SetResult(enter
.object()->Query(info
,
130 int32_t ReadDirectoryEntries(PP_Resource file_ref
,
131 PP_ArrayOutput output
,
132 PP_CompletionCallback callback
) {
133 EnterFileRef
enter(file_ref
, callback
, true);
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);
144 return PP_MakeUndefined();
145 return enter
.object()->GetAbsolutePath();
148 const PPB_FileRef_1_0 g_ppb_file_ref_thunk_1_0
= {
161 const PPB_FileRef_1_1 g_ppb_file_ref_thunk_1_1
= {
173 &ReadDirectoryEntries
176 const PPB_FileRefPrivate g_ppb_file_ref_private_thunk
= {
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
;