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/file_ref_create_info.h"
11 #include "ppapi/shared_impl/proxy_lock.h"
12 #include "ppapi/shared_impl/tracked_callback.h"
13 #include "ppapi/thunk/enter.h"
14 #include "ppapi/thunk/thunk.h"
15 #include "ppapi/thunk/ppb_file_ref_api.h"
16 #include "ppapi/thunk/ppb_file_system_api.h"
17 #include "ppapi/thunk/resource_creation_api.h"
24 typedef EnterResource
<PPB_FileRef_API
> EnterFileRef
;
26 PP_Resource
Create(PP_Resource file_system
, const char* path
) {
27 VLOG(4) << "PPB_FileRef::Create()";
28 ppapi::ProxyAutoLock lock
;
29 EnterResourceNoLock
<PPB_FileSystem_API
> enter_file_system(file_system
, true);
30 if (enter_file_system
.failed())
32 PP_Instance instance
= enter_file_system
.resource()->pp_instance();
33 EnterResourceCreationNoLock
enter(instance
);
36 FileRefCreateInfo info
;
37 info
.file_system_type
= enter_file_system
.object()->GetType();
38 info
.internal_path
= std::string(path
);
39 info
.browser_pending_host_resource_id
= 0;
40 info
.renderer_pending_host_resource_id
= 0;
41 info
.file_system_plugin_resource
= file_system
;
42 return enter
.functions()->CreateFileRef(instance
, info
);
45 PP_Bool
IsFileRef(PP_Resource resource
) {
46 VLOG(4) << "PPB_FileRef::IsFileRef()";
47 EnterFileRef
enter(resource
, false);
48 return PP_FromBool(enter
.succeeded());
51 PP_FileSystemType
GetFileSystemType(PP_Resource file_ref
) {
52 VLOG(4) << "PPB_FileRef::GetFileSystemType()";
53 EnterFileRef
enter(file_ref
, true);
55 return PP_FILESYSTEMTYPE_INVALID
;
56 return enter
.object()->GetFileSystemType();
59 PP_Var
GetName(PP_Resource file_ref
) {
60 VLOG(4) << "PPB_FileRef::GetName()";
61 EnterFileRef
enter(file_ref
, true);
63 return PP_MakeUndefined();
64 return enter
.object()->GetName();
67 PP_Var
GetPath(PP_Resource file_ref
) {
68 VLOG(4) << "PPB_FileRef::GetPath()";
69 EnterFileRef
enter(file_ref
, true);
71 return PP_MakeUndefined();
72 return enter
.object()->GetPath();
75 PP_Resource
GetParent(PP_Resource file_ref
) {
76 VLOG(4) << "PPB_FileRef::GetParent()";
77 EnterFileRef
enter(file_ref
, true);
80 return enter
.object()->GetParent();
83 int32_t MakeDirectory(PP_Resource directory_ref
,
84 PP_Bool make_ancestors
,
85 PP_CompletionCallback callback
) {
86 VLOG(4) << "PPB_FileRef::MakeDirectory()";
87 EnterFileRef
enter(directory_ref
, callback
, true);
89 return enter
.retval();
90 int32_t flag
= make_ancestors
? PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS
91 : PP_MAKEDIRECTORYFLAG_NONE
;
92 return enter
.SetResult(enter
.object()->MakeDirectory(
93 flag
, enter
.callback()));
96 int32_t MakeDirectory_1_2(PP_Resource directory_ref
,
97 int32_t make_directory_flags
,
98 PP_CompletionCallback callback
) {
99 VLOG(4) << "PPB_FileRef::MakeDirectory()";
100 EnterFileRef
enter(directory_ref
, callback
, true);
102 return enter
.retval();
103 return enter
.SetResult(enter
.object()->MakeDirectory(
104 make_directory_flags
, enter
.callback()));
107 int32_t Touch(PP_Resource file_ref
,
108 PP_Time last_access_time
,
109 PP_Time last_modified_time
,
110 PP_CompletionCallback callback
) {
111 VLOG(4) << "PPB_FileRef::Touch()";
112 EnterFileRef
enter(file_ref
, callback
, true);
114 return enter
.retval();
115 return enter
.SetResult(enter
.object()->Touch(
116 last_access_time
, last_modified_time
, enter
.callback()));
119 int32_t Delete(PP_Resource file_ref
,
120 PP_CompletionCallback callback
) {
121 VLOG(4) << "PPB_FileRef::Delete()";
122 EnterFileRef
enter(file_ref
, callback
, true);
124 return enter
.retval();
125 return enter
.SetResult(enter
.object()->Delete(enter
.callback()));
128 int32_t Rename(PP_Resource file_ref
,
129 PP_Resource new_file_ref
,
130 PP_CompletionCallback callback
) {
131 VLOG(4) << "PPB_FileRef::Rename()";
132 EnterFileRef
enter(file_ref
, callback
, true);
134 return enter
.retval();
135 return enter
.SetResult(enter
.object()->Rename(new_file_ref
,
139 int32_t Query(PP_Resource file_ref
,
141 PP_CompletionCallback callback
) {
142 VLOG(4) << "PPB_FileRef::Query()";
143 EnterFileRef
enter(file_ref
, callback
, true);
145 return enter
.retval();
146 return enter
.SetResult(enter
.object()->Query(info
,
150 int32_t ReadDirectoryEntries(PP_Resource file_ref
,
151 PP_ArrayOutput output
,
152 PP_CompletionCallback callback
) {
153 EnterFileRef
enter(file_ref
, callback
, true);
155 return enter
.retval();
156 return enter
.SetResult(enter
.object()->ReadDirectoryEntries(
157 output
, enter
.callback()));
160 PP_Var
GetAbsolutePath(PP_Resource file_ref
) {
161 VLOG(4) << "PPB_FileRef::GetAbsolutePath";
162 EnterFileRef
enter(file_ref
, true);
164 return PP_MakeUndefined();
165 return enter
.object()->GetAbsolutePath();
168 const PPB_FileRef_1_0 g_ppb_file_ref_thunk_1_0
= {
181 const PPB_FileRef_1_1 g_ppb_file_ref_thunk_1_1
= {
193 &ReadDirectoryEntries
196 const PPB_FileRef_1_2 g_ppb_file_ref_thunk_1_2
= {
208 &ReadDirectoryEntries
211 const PPB_FileRefPrivate g_ppb_file_ref_private_thunk
= {
217 const PPB_FileRef_1_0
* GetPPB_FileRef_1_0_Thunk() {
218 return &g_ppb_file_ref_thunk_1_0
;
221 const PPB_FileRef_1_1
* GetPPB_FileRef_1_1_Thunk() {
222 return &g_ppb_file_ref_thunk_1_1
;
225 const PPB_FileRef_1_2
* GetPPB_FileRef_1_2_Thunk() {
226 return &g_ppb_file_ref_thunk_1_2
;
229 const PPB_FileRefPrivate_0_1
* GetPPB_FileRefPrivate_0_1_Thunk() {
230 return &g_ppb_file_ref_private_thunk
;