OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_file_ref_proxy.h" | 5 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/c/ppb_file_ref.h" | 8 #include "ppapi/c/ppb_file_ref.h" |
9 #include "ppapi/c/private/ppb_proxy_private.h" | 9 #include "ppapi/c/private/ppb_proxy_private.h" |
10 #include "ppapi/proxy/enter_proxy.h" | 10 #include "ppapi/proxy/enter_proxy.h" |
11 #include "ppapi/proxy/host_dispatcher.h" | 11 #include "ppapi/proxy/host_dispatcher.h" |
12 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/serialized_var.h" | 14 #include "ppapi/proxy/serialized_var.h" |
15 #include "ppapi/shared_impl/file_ref_impl.h" | 15 #include "ppapi/shared_impl/file_ref_impl.h" |
16 #include "ppapi/thunk/resource_creation_api.h" | 16 #include "ppapi/thunk/resource_creation_api.h" |
17 #include "ppapi/thunk/thunk.h" | 17 #include "ppapi/thunk/thunk.h" |
18 | 18 |
19 using ppapi::thunk::EnterFunctionNoLock; | 19 using ppapi::thunk::EnterFunctionNoLock; |
20 using ppapi::thunk::EnterResourceNoLock; | 20 using ppapi::thunk::EnterResourceNoLock; |
21 using ppapi::thunk::PPB_FileRef_API; | 21 using ppapi::thunk::PPB_FileRef_API; |
22 using ppapi::thunk::ResourceCreationAPI; | 22 using ppapi::thunk::ResourceCreationAPI; |
23 | 23 |
24 namespace ppapi { | 24 namespace ppapi { |
25 namespace proxy { | 25 namespace proxy { |
26 | 26 |
27 namespace { | |
28 | |
29 InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher, | |
30 const void* target_interface) { | |
31 return new PPB_FileRef_Proxy(dispatcher, target_interface); | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 class FileRef : public FileRefImpl { | 27 class FileRef : public FileRefImpl { |
37 public: | 28 public: |
38 explicit FileRef(const PPB_FileRef_CreateInfo& info); | 29 explicit FileRef(const PPB_FileRef_CreateInfo& info); |
39 virtual ~FileRef(); | 30 virtual ~FileRef(); |
40 | 31 |
41 // PPB_FileRef_API implementation (not provided by FileRefImpl). | 32 // PPB_FileRef_API implementation (not provided by FileRefImpl). |
42 virtual PP_Resource GetParent() OVERRIDE; | 33 virtual PP_Resource GetParent() OVERRIDE; |
43 virtual int32_t MakeDirectory(PP_Bool make_ancestors, | 34 virtual int32_t MakeDirectory(PP_Bool make_ancestors, |
44 PP_CompletionCallback callback) OVERRIDE; | 35 PP_CompletionCallback callback) OVERRIDE; |
45 virtual int32_t Touch(PP_Time last_access_time, | 36 virtual int32_t Touch(PP_Time last_access_time, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 new_file_ref_object->host_resource().instance() != pp_instance()) | 95 new_file_ref_object->host_resource().instance() != pp_instance()) |
105 return PP_ERROR_BADRESOURCE; | 96 return PP_ERROR_BADRESOURCE; |
106 | 97 |
107 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( | 98 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( |
108 INTERFACE_ID_PPB_FILE_REF, host_resource(), | 99 INTERFACE_ID_PPB_FILE_REF, host_resource(), |
109 new_file_ref_object->host_resource(), | 100 new_file_ref_object->host_resource(), |
110 GetDispatcher()->callback_tracker().SendCallback(callback))); | 101 GetDispatcher()->callback_tracker().SendCallback(callback))); |
111 return PP_OK_COMPLETIONPENDING; | 102 return PP_OK_COMPLETIONPENDING; |
112 } | 103 } |
113 | 104 |
114 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher, | 105 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) |
115 const void* target_interface) | 106 : InterfaceProxy(dispatcher) { |
116 : InterfaceProxy(dispatcher, target_interface) { | |
117 } | 107 } |
118 | 108 |
119 PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { | 109 PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { |
120 } | 110 } |
121 | 111 |
122 const InterfaceProxy::Info* PPB_FileRef_Proxy::GetInfo() { | |
123 static const Info info = { | |
124 thunk::GetPPB_FileRef_Thunk(), | |
125 PPB_FILEREF_INTERFACE, | |
126 INTERFACE_ID_PPB_FILE_REF, | |
127 false, | |
128 &CreateFileRefProxy, | |
129 }; | |
130 return &info; | |
131 } | |
132 | |
133 // static | 112 // static |
134 PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, | 113 PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, |
135 const char* path) { | 114 const char* path) { |
136 Resource* file_system_object = | 115 Resource* file_system_object = |
137 PluginResourceTracker::GetInstance()->GetResource(file_system); | 116 PluginResourceTracker::GetInstance()->GetResource(file_system); |
138 if (!file_system_object) | 117 if (!file_system_object) |
139 return 0; | 118 return 0; |
140 | 119 |
141 PPB_FileRef_CreateInfo create_info; | 120 PPB_FileRef_CreateInfo create_info; |
142 PluginDispatcher::GetForResource(file_system_object)->Send( | 121 PluginDispatcher::GetForResource(file_system_object)->Send( |
(...skipping 29 matching lines...) Expand all Loading... |
172 PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( | 151 PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( |
173 const PPB_FileRef_CreateInfo& serialized) { | 152 const PPB_FileRef_CreateInfo& serialized) { |
174 if (serialized.resource.is_null()) | 153 if (serialized.resource.is_null()) |
175 return 0; // Resource invalid. | 154 return 0; // Resource invalid. |
176 return (new FileRef(serialized))->GetReference(); | 155 return (new FileRef(serialized))->GetReference(); |
177 } | 156 } |
178 | 157 |
179 void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, | 158 void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, |
180 const std::string& path, | 159 const std::string& path, |
181 PPB_FileRef_CreateInfo* result) { | 160 PPB_FileRef_CreateInfo* result) { |
182 EnterFunctionNoLock<ResourceCreationAPI> enter(file_system.instance(), true); | 161 thunk::EnterResourceCreation enter(file_system.instance()); |
183 if (enter.failed()) | 162 if (enter.failed()) |
184 return; | 163 return; |
185 PP_Resource resource = enter.functions()->CreateFileRef( | 164 PP_Resource resource = enter.functions()->CreateFileRef( |
186 file_system.host_resource(), path.c_str()); | 165 file_system.host_resource(), path.c_str()); |
187 if (!resource) | 166 if (!resource) |
188 return; // CreateInfo default constructor initializes to 0. | 167 return; // CreateInfo default constructor initializes to 0. |
189 SerializeFileRef(resource, result); | 168 SerializeFileRef(resource, result); |
190 } | 169 } |
191 | 170 |
192 void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, | 171 void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return; | 219 return; |
241 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); | 220 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
242 int32_t result = enter.object()->Rename(new_file_ref.host_resource(), | 221 int32_t result = enter.object()->Rename(new_file_ref.host_resource(), |
243 callback); | 222 callback); |
244 if (result != PP_OK_COMPLETIONPENDING) | 223 if (result != PP_OK_COMPLETIONPENDING) |
245 PP_RunCompletionCallback(&callback, result); | 224 PP_RunCompletionCallback(&callback, result); |
246 } | 225 } |
247 | 226 |
248 } // namespace proxy | 227 } // namespace proxy |
249 } // namespace ppapi | 228 } // namespace ppapi |
OLD | NEW |