Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ppapi / thunk / ppb_file_ref_thunk.cc
blob4e61cd666d895100514d2a24aca0dd8e57f7ec93
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"
17 namespace ppapi {
18 namespace thunk {
20 namespace {
22 typedef EnterResource<PPB_FileRef_API> EnterFileRef;
24 PP_Resource Create(PP_Resource file_system, const char* path) {
25 ppapi::ProxyAutoLock lock;
26 Resource* object =
27 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_system);
28 if (!object)
29 return 0;
30 EnterResourceCreationNoLock enter(object->pp_instance());
31 if (enter.failed())
32 return 0;
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);
43 if (enter.failed())
44 return PP_FILESYSTEMTYPE_INVALID;
45 return enter.object()->GetFileSystemType();
48 PP_Var GetName(PP_Resource file_ref) {
49 EnterFileRef enter(file_ref, true);
50 if (enter.failed())
51 return PP_MakeUndefined();
52 return enter.object()->GetName();
55 PP_Var GetPath(PP_Resource file_ref) {
56 EnterFileRef enter(file_ref, true);
57 if (enter.failed())
58 return PP_MakeUndefined();
59 return enter.object()->GetPath();
62 PP_Resource GetParent(PP_Resource file_ref) {
63 EnterFileRef enter(file_ref, true);
64 if (enter.failed())
65 return 0;
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);
73 if (enter.failed())
74 return enter.retval();
75 return enter.SetResult(enter.object()->MakeDirectory(make_ancestors,
76 enter.callback()));
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);
84 if (enter.failed())
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);
93 if (enter.failed())
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);
102 if (enter.failed())
103 return enter.retval();
104 return enter.SetResult(enter.object()->Rename(new_file_ref,
105 enter.callback()));
108 int32_t Query(PP_Resource file_ref,
109 PP_FileInfo* info,
110 PP_CompletionCallback callback) {
111 EnterFileRef enter(file_ref, callback, true);
112 if (enter.failed())
113 return enter.retval();
114 return enter.SetResult(enter.object()->Query(info,
115 enter.callback()));
118 PP_Var GetAbsolutePath(PP_Resource file_ref) {
119 EnterFileRef enter(file_ref, true);
120 if (enter.failed())
121 return PP_MakeUndefined();
122 return enter.object()->GetAbsolutePath();
125 const PPB_FileRef_1_0 g_ppb_file_ref_thunk_1_0 = {
126 &Create,
127 &IsFileRef,
128 &GetFileSystemType,
129 &GetName,
130 &GetPath,
131 &GetParent,
132 &MakeDirectory,
133 &Touch,
134 &Delete,
135 &Rename
138 const PPB_FileRef_1_1 g_ppb_file_ref_thunk_1_1 = {
139 &Create,
140 &IsFileRef,
141 &GetFileSystemType,
142 &GetName,
143 &GetPath,
144 &GetParent,
145 &MakeDirectory,
146 &Touch,
147 &Delete,
148 &Rename,
149 &Query
152 const PPB_FileRefPrivate g_ppb_file_ref_private_thunk = {
153 &GetAbsolutePath
156 } // namespace
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;
170 } // namespace thunk
171 } // namespace ppapi