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/resource_creation_api.h"
22 typedef EnterResource
<PPB_FileRef_API
> EnterFileRef
;
24 PP_Resource
Create(PP_Resource file_system
, const char* path
) {
25 ppapi::ProxyAutoLock lock
;
27 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_system
);
30 EnterResourceCreationNoLock
enter(object
->pp_instance());
33 return enter
.functions()->CreateFileRef(file_system
, path
);
36 PP_Bool
IsFileRef(PP_Resource resource
) {
37 EnterFileRef
enter(resource
, false);
38 return PP_FromBool(enter
.succeeded());
41 PP_FileSystemType
GetFileSystemType(PP_Resource file_ref
) {
42 EnterFileRef
enter(file_ref
, true);
44 return PP_FILESYSTEMTYPE_INVALID
;
45 return enter
.object()->GetFileSystemType();
48 PP_Var
GetName(PP_Resource file_ref
) {
49 EnterFileRef
enter(file_ref
, true);
51 return PP_MakeUndefined();
52 return enter
.object()->GetName();
55 PP_Var
GetPath(PP_Resource file_ref
) {
56 EnterFileRef
enter(file_ref
, true);
58 return PP_MakeUndefined();
59 return enter
.object()->GetPath();
62 PP_Resource
GetParent(PP_Resource file_ref
) {
63 EnterFileRef
enter(file_ref
, true);
66 return enter
.object()->GetParent();
69 int32_t MakeDirectory(PP_Resource directory_ref
,
70 PP_Bool make_ancestors
,
71 PP_CompletionCallback callback
) {
72 EnterFileRef
enter(directory_ref
, callback
, true);
74 return enter
.retval();
75 return enter
.SetResult(enter
.object()->MakeDirectory(make_ancestors
,
79 int32_t Touch(PP_Resource file_ref
,
80 PP_Time last_access_time
,
81 PP_Time last_modified_time
,
82 PP_CompletionCallback callback
) {
83 EnterFileRef
enter(file_ref
, callback
, true);
85 return enter
.retval();
86 return enter
.SetResult(enter
.object()->Touch(
87 last_access_time
, last_modified_time
, enter
.callback()));
90 int32_t Delete(PP_Resource file_ref
,
91 PP_CompletionCallback callback
) {
92 EnterFileRef
enter(file_ref
, callback
, true);
94 return enter
.retval();
95 return enter
.SetResult(enter
.object()->Delete(enter
.callback()));
98 int32_t Rename(PP_Resource file_ref
,
99 PP_Resource new_file_ref
,
100 PP_CompletionCallback callback
) {
101 EnterFileRef
enter(file_ref
, callback
, true);
103 return enter
.retval();
104 return enter
.SetResult(enter
.object()->Rename(new_file_ref
,
108 int32_t Query(PP_Resource file_ref
,
110 PP_CompletionCallback callback
) {
111 EnterFileRef
enter(file_ref
, callback
, true);
113 return enter
.retval();
114 return enter
.SetResult(enter
.object()->Query(info
,
118 PP_Var
GetAbsolutePath(PP_Resource file_ref
) {
119 EnterFileRef
enter(file_ref
, true);
121 return PP_MakeUndefined();
122 return enter
.object()->GetAbsolutePath();
125 const PPB_FileRef_1_0 g_ppb_file_ref_thunk_1_0
= {
138 const PPB_FileRef_1_1 g_ppb_file_ref_thunk_1_1
= {
152 const PPB_FileRefPrivate g_ppb_file_ref_private_thunk
= {
158 const PPB_FileRef_1_0
* GetPPB_FileRef_1_0_Thunk() {
159 return &g_ppb_file_ref_thunk_1_0
;
162 const PPB_FileRef_1_1
* GetPPB_FileRef_1_1_Thunk() {
163 return &g_ppb_file_ref_thunk_1_1
;
166 const PPB_FileRefPrivate_0_1
* GetPPB_FileRefPrivate_0_1_Thunk() {
167 return &g_ppb_file_ref_private_thunk
;