OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "ppapi/c/pp_directory_entry.h" |
10 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/ppb_file_ref.h" | 12 #include "ppapi/c/ppb_file_ref.h" |
12 #include "ppapi/c/private/ppb_file_ref_private.h" | 13 #include "ppapi/c/private/ppb_file_ref_private.h" |
13 #include "ppapi/c/private/ppb_proxy_private.h" | 14 #include "ppapi/c/private/ppb_proxy_private.h" |
14 #include "ppapi/proxy/enter_proxy.h" | 15 #include "ppapi/proxy/enter_proxy.h" |
15 #include "ppapi/proxy/host_dispatcher.h" | 16 #include "ppapi/proxy/host_dispatcher.h" |
16 #include "ppapi/proxy/plugin_dispatcher.h" | 17 #include "ppapi/proxy/plugin_dispatcher.h" |
17 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
18 #include "ppapi/proxy/serialized_var.h" | 19 #include "ppapi/proxy/serialized_var.h" |
| 20 #include "ppapi/shared_impl/array_writer.h" |
19 #include "ppapi/shared_impl/ppb_file_ref_shared.h" | 21 #include "ppapi/shared_impl/ppb_file_ref_shared.h" |
20 #include "ppapi/shared_impl/scoped_pp_resource.h" | 22 #include "ppapi/shared_impl/scoped_pp_resource.h" |
21 #include "ppapi/shared_impl/tracked_callback.h" | 23 #include "ppapi/shared_impl/tracked_callback.h" |
22 #include "ppapi/thunk/resource_creation_api.h" | 24 #include "ppapi/thunk/resource_creation_api.h" |
23 #include "ppapi/thunk/thunk.h" | 25 #include "ppapi/thunk/thunk.h" |
24 | 26 |
25 using ppapi::thunk::EnterResourceNoLock; | 27 using ppapi::thunk::EnterResourceNoLock; |
26 using ppapi::thunk::PPB_FileRef_API; | 28 using ppapi::thunk::PPB_FileRef_API; |
27 using ppapi::thunk::ResourceCreationAPI; | 29 using ppapi::thunk::ResourceCreationAPI; |
28 | 30 |
29 namespace ppapi { | 31 namespace ppapi { |
30 namespace proxy { | 32 namespace proxy { |
31 | 33 |
| 34 namespace { |
| 35 |
| 36 void ReleaseEntries(const std::vector<PP_DirectoryEntry>& entries) { |
| 37 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); |
| 38 for (std::vector<PP_DirectoryEntry>::const_iterator it = entries.begin(); |
| 39 it != entries.end(); ++it) |
| 40 tracker->ReleaseResource(it->file_ref); |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
32 class FileRef : public PPB_FileRef_Shared { | 45 class FileRef : public PPB_FileRef_Shared { |
33 public: | 46 public: |
34 explicit FileRef(const PPB_FileRef_CreateInfo& info); | 47 explicit FileRef(const PPB_FileRef_CreateInfo& info); |
35 virtual ~FileRef(); | 48 virtual ~FileRef(); |
36 | 49 |
37 // Resource overrides. | 50 // Resource overrides. |
38 virtual void LastPluginRefWasDeleted() OVERRIDE; | 51 virtual void LastPluginRefWasDeleted() OVERRIDE; |
39 | 52 |
40 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). | 53 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). |
41 virtual PP_Resource GetParent() OVERRIDE; | 54 virtual PP_Resource GetParent() OVERRIDE; |
42 virtual int32_t MakeDirectory( | 55 virtual int32_t MakeDirectory( |
43 PP_Bool make_ancestors, | 56 PP_Bool make_ancestors, |
44 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 57 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
45 virtual int32_t Touch(PP_Time last_access_time, | 58 virtual int32_t Touch(PP_Time last_access_time, |
46 PP_Time last_modified_time, | 59 PP_Time last_modified_time, |
47 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 60 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
48 virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; | 61 virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
49 virtual int32_t Rename(PP_Resource new_file_ref, | 62 virtual int32_t Rename(PP_Resource new_file_ref, |
50 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 63 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
51 virtual int32_t Query(PP_FileInfo* info, | 64 virtual int32_t Query(PP_FileInfo* info, |
52 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 65 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 66 virtual int32_t ReadDirectoryEntries( |
| 67 const PP_ArrayOutput& output, |
| 68 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 69 virtual int32_t QueryInHost( |
| 70 linked_ptr<PP_FileInfo> info, |
| 71 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 72 virtual int32_t ReadDirectoryEntriesInHost( |
| 73 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
| 74 linked_ptr<std::vector<PP_FileType> > file_types, |
| 75 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
53 virtual PP_Var GetAbsolutePath() OVERRIDE; | 76 virtual PP_Var GetAbsolutePath() OVERRIDE; |
54 | 77 |
55 // Executes the pending callback with the given ID. See pending_callbacks_. | 78 // Executes the pending callback with the given ID. See pending_callbacks_. |
56 void ExecuteCallback(uint32_t callback_id, int32_t result); | 79 void ExecuteCallback(uint32_t callback_id, int32_t result); |
57 void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); | 80 int32_t SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); |
| 81 int32_t SetReadDirectoryEntriesOutput( |
| 82 uint32_t callback_id, |
| 83 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
| 84 const std::vector<PP_FileType>& file_types); |
58 | 85 |
59 private: | 86 private: |
60 PluginDispatcher* GetDispatcher() const { | 87 PluginDispatcher* GetDispatcher() const { |
61 return PluginDispatcher::GetForResource(this); | 88 return PluginDispatcher::GetForResource(this); |
62 } | 89 } |
63 | 90 |
64 // Adds a callback to the list and returns its ID. | 91 // Adds a callback to the list and returns its ID. |
65 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); | 92 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); |
66 | 93 |
67 // This class can have any number of out-standing requests with completion | 94 // This class can have any number of out-standing requests with completion |
68 // callbacks, in contrast to most resources which have one possible pending | 95 // callbacks, in contrast to most resources which have one possible pending |
69 // callback pending (like a Flush callback). | 96 // callback pending (like a Flush callback). |
70 // | 97 // |
71 // To keep track of them, assign integer IDs to the callbacks, which is how | 98 // To keep track of them, assign integer IDs to the callbacks, which is how |
72 // the callback will be identified when it's passed to the host and then | 99 // the callback will be identified when it's passed to the host and then |
73 // back here. Use unsigned so that overflow is well-defined. | 100 // back here. Use unsigned so that overflow is well-defined. |
74 uint32_t next_callback_id_; | 101 uint32_t next_callback_id_; |
75 typedef std::map<uint32_t, | 102 typedef std::map<uint32_t, |
76 scoped_refptr<TrackedCallback> > PendingCallbackMap; | 103 scoped_refptr<TrackedCallback> > PendingCallbackMap; |
77 PendingCallbackMap pending_callbacks_; | 104 PendingCallbackMap pending_callbacks_; |
78 | 105 |
79 // Used to keep pointers to PP_FileInfo instances that are written before | 106 // Used to keep pointers to PP_FileInfo instances that are written before |
80 // callbacks are invoked. The id of a pending file info will match that of | 107 // callbacks are invoked. The id of a pending file info will match that of |
81 // the corresponding callback. | 108 // the corresponding callback. |
82 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; | 109 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; |
83 PendingFileInfoMap pending_file_infos_; | 110 PendingFileInfoMap pending_file_infos_; |
84 | 111 |
| 112 // Used to keep PP_ArrayOutput instances that are written before callbacks |
| 113 // are invoked. The id of a pending array output will match that of the |
| 114 // corresponding callback. |
| 115 typedef std::map<uint32_t, PP_ArrayOutput> |
| 116 PendingReadDirectoryEntriesOutputMap; |
| 117 PendingReadDirectoryEntriesOutputMap pending_read_entries_outputs_; |
| 118 |
85 // Holds a reference on plugin side when running out of process, so that | 119 // Holds a reference on plugin side when running out of process, so that |
86 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for | 120 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for |
87 // corresponding code for in-process mode. Note that this workaround will | 121 // corresponding code for in-process mode. Note that this workaround will |
88 // be no longer needed after FileRef refactoring. | 122 // be no longer needed after FileRef refactoring. |
89 ScopedPPResource file_system_; | 123 ScopedPPResource file_system_; |
90 | 124 |
91 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); | 125 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); |
92 }; | 126 }; |
93 | 127 |
94 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) | 128 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) |
95 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), | 129 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), |
96 next_callback_id_(0u), | 130 next_callback_id_(0u), |
97 file_system_(info.file_system_plugin_resource) { | 131 file_system_(info.file_system_plugin_resource) { |
98 } | 132 } |
99 | 133 |
100 FileRef::~FileRef() { | 134 FileRef::~FileRef() { |
101 // The callbacks map should have been cleared by LastPluginRefWasDeleted. | 135 // The callbacks map should have been cleared by LastPluginRefWasDeleted. |
102 DCHECK(pending_callbacks_.empty()); | 136 DCHECK(pending_callbacks_.empty()); |
103 DCHECK(pending_file_infos_.empty()); | 137 DCHECK(pending_file_infos_.empty()); |
| 138 DCHECK(pending_read_entries_outputs_.empty()); |
104 } | 139 } |
105 | 140 |
106 void FileRef::LastPluginRefWasDeleted() { | 141 void FileRef::LastPluginRefWasDeleted() { |
107 // The callback tracker will abort our callbacks for us. | 142 // The callback tracker will abort our callbacks for us. |
108 pending_callbacks_.clear(); | 143 pending_callbacks_.clear(); |
109 pending_file_infos_.clear(); | 144 pending_file_infos_.clear(); |
| 145 pending_read_entries_outputs_.clear(); |
110 } | 146 } |
111 | 147 |
112 PP_Resource FileRef::GetParent() { | 148 PP_Resource FileRef::GetParent() { |
113 PPB_FileRef_CreateInfo create_info; | 149 PPB_FileRef_CreateInfo create_info; |
114 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( | 150 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( |
115 API_ID_PPB_FILE_REF, host_resource(), &create_info)); | 151 API_ID_PPB_FILE_REF, host_resource(), &create_info)); |
116 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); | 152 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); |
117 } | 153 } |
118 | 154 |
119 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, | 155 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, |
(...skipping 29 matching lines...) Expand all Loading... |
149 | 185 |
150 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( | 186 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( |
151 API_ID_PPB_FILE_REF, host_resource(), | 187 API_ID_PPB_FILE_REF, host_resource(), |
152 new_file_ref_object->host_resource(), SendCallback(callback))); | 188 new_file_ref_object->host_resource(), SendCallback(callback))); |
153 return PP_OK_COMPLETIONPENDING; | 189 return PP_OK_COMPLETIONPENDING; |
154 } | 190 } |
155 | 191 |
156 int32_t FileRef::Query(PP_FileInfo* info, | 192 int32_t FileRef::Query(PP_FileInfo* info, |
157 scoped_refptr<TrackedCallback> callback) { | 193 scoped_refptr<TrackedCallback> callback) { |
158 // Store the pending file info id. | 194 // Store the pending file info id. |
159 int id = SendCallback(callback); | 195 uint32_t id = SendCallback(callback); |
160 pending_file_infos_[id] = info; | 196 pending_file_infos_[id] = info; |
161 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( | 197 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( |
162 API_ID_PPB_FILE_REF, host_resource(), id)); | 198 API_ID_PPB_FILE_REF, host_resource(), id)); |
163 return PP_OK_COMPLETIONPENDING; | 199 return PP_OK_COMPLETIONPENDING; |
164 } | 200 } |
165 | 201 |
| 202 int32_t FileRef::ReadDirectoryEntries( |
| 203 const PP_ArrayOutput& output, |
| 204 scoped_refptr<TrackedCallback> callback) { |
| 205 // Store the pending read entries output id. |
| 206 uint32_t id = SendCallback(callback); |
| 207 pending_read_entries_outputs_[id] = output; |
| 208 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadDirectoryEntries( |
| 209 API_ID_PPB_FILE_REF, host_resource(), id)); |
| 210 return PP_OK_COMPLETIONPENDING; |
| 211 } |
| 212 |
| 213 int32_t FileRef::QueryInHost( |
| 214 linked_ptr<PP_FileInfo> info, |
| 215 scoped_refptr<TrackedCallback> callback) { |
| 216 NOTREACHED(); |
| 217 return PP_ERROR_FAILED; |
| 218 } |
| 219 |
| 220 int32_t FileRef::ReadDirectoryEntriesInHost( |
| 221 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
| 222 linked_ptr<std::vector<PP_FileType> > file_types, |
| 223 scoped_refptr<TrackedCallback> callback) { |
| 224 NOTREACHED(); |
| 225 return PP_ERROR_FAILED; |
| 226 } |
| 227 |
166 PP_Var FileRef::GetAbsolutePath() { | 228 PP_Var FileRef::GetAbsolutePath() { |
167 ReceiveSerializedVarReturnValue result; | 229 ReceiveSerializedVarReturnValue result; |
168 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( | 230 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( |
169 API_ID_PPB_FILE_REF, host_resource(), &result)); | 231 API_ID_PPB_FILE_REF, host_resource(), &result)); |
170 return result.Return(GetDispatcher()); | 232 return result.Return(GetDispatcher()); |
171 } | 233 } |
172 | 234 |
173 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { | 235 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { |
174 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); | 236 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); |
175 if (found == pending_callbacks_.end()) { | 237 if (found == pending_callbacks_.end()) { |
176 // This will happen when the plugin deletes its resource with a pending | 238 // This will happen when the plugin deletes its resource with a pending |
177 // callback. The callback will be locally issued with an ABORTED call while | 239 // callback. The callback will be locally issued with an ABORTED call while |
178 // the operation may still be pending in the renderer. | 240 // the operation may still be pending in the renderer. |
179 return; | 241 return; |
180 } | 242 } |
181 | 243 |
182 // Executing the callback may mutate the callback list. | 244 // Executing the callback may mutate the callback list. |
183 scoped_refptr<TrackedCallback> callback = found->second; | 245 scoped_refptr<TrackedCallback> callback = found->second; |
184 pending_callbacks_.erase(found); | 246 pending_callbacks_.erase(found); |
185 callback->Run(result); | 247 callback->Run(result); |
186 } | 248 } |
187 | 249 |
188 void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { | 250 int32_t FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { |
189 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); | 251 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); |
190 if (found == pending_file_infos_.end()) | 252 if (found == pending_file_infos_.end()) |
191 return; | 253 return PP_ERROR_FAILED; |
192 PP_FileInfo* target_info = found->second; | 254 PP_FileInfo* target_info = found->second; |
193 *target_info = info; | 255 *target_info = info; |
194 pending_file_infos_.erase(found); | 256 pending_file_infos_.erase(found); |
| 257 return PP_OK; |
| 258 } |
| 259 |
| 260 int32_t FileRef::SetReadDirectoryEntriesOutput( |
| 261 uint32_t callback_id, |
| 262 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
| 263 const std::vector<PP_FileType>& file_types) { |
| 264 PendingReadDirectoryEntriesOutputMap::iterator found = |
| 265 pending_read_entries_outputs_.find(callback_id); |
| 266 if (found == pending_read_entries_outputs_.end()) |
| 267 return PP_ERROR_FAILED; |
| 268 |
| 269 PP_ArrayOutput output = found->second; |
| 270 pending_read_entries_outputs_.erase(found); |
| 271 |
| 272 std::vector<PP_DirectoryEntry> entries; |
| 273 for (size_t i = 0; i < infos.size(); ++i) { |
| 274 PP_DirectoryEntry entry; |
| 275 entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); |
| 276 entry.file_type = file_types[i]; |
| 277 entries.push_back(entry); |
| 278 } |
| 279 |
| 280 ArrayWriter writer(output); |
| 281 if (!writer.is_valid()) { |
| 282 ReleaseEntries(entries); |
| 283 return PP_ERROR_BADARGUMENT; |
| 284 } |
| 285 |
| 286 writer.StoreVector(entries); |
| 287 return PP_OK; |
195 } | 288 } |
196 | 289 |
197 uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { | 290 uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { |
198 // In extreme cases the IDs may wrap around, so avoid duplicates. | 291 // In extreme cases the IDs may wrap around, so avoid duplicates. |
199 while (pending_callbacks_.count(next_callback_id_)) | 292 while (pending_callbacks_.count(next_callback_id_)) |
200 ++next_callback_id_; | 293 ++next_callback_id_; |
201 | 294 |
202 pending_callbacks_[next_callback_id_] = callback; | 295 pending_callbacks_[next_callback_id_] = callback; |
203 return next_callback_id_++; | 296 return next_callback_id_++; |
204 } | 297 } |
(...skipping 22 matching lines...) Expand all Loading... |
227 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) | 320 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) |
228 #if !defined(OS_NACL) | 321 #if !defined(OS_NACL) |
229 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) | 322 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) |
230 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) | 323 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) |
231 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, | 324 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, |
232 OnMsgMakeDirectory) | 325 OnMsgMakeDirectory) |
233 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) | 326 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) |
234 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) | 327 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) |
235 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) | 328 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) |
236 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) | 329 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) |
| 330 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_ReadDirectoryEntries, |
| 331 OnMsgReadDirectoryEntries) |
237 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, | 332 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, |
238 OnMsgGetAbsolutePath) | 333 OnMsgGetAbsolutePath) |
239 #endif // !defined(OS_NACL) | 334 #endif // !defined(OS_NACL) |
240 | 335 |
241 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, | 336 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, |
242 OnMsgCallbackComplete) | 337 OnMsgCallbackComplete) |
243 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, | 338 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, |
244 OnMsgQueryCallbackComplete) | 339 OnMsgQueryCallbackComplete) |
| 340 IPC_MESSAGE_HANDLER( |
| 341 PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete, |
| 342 OnMsgReadDirectoryEntriesCallbackComplete) |
245 IPC_MESSAGE_UNHANDLED(handled = false) | 343 IPC_MESSAGE_UNHANDLED(handled = false) |
246 IPC_END_MESSAGE_MAP() | 344 IPC_END_MESSAGE_MAP() |
247 return handled; | 345 return handled; |
248 } | 346 } |
249 | 347 |
250 // static | 348 // static |
251 void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, | 349 void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, |
252 PPB_FileRef_CreateInfo* result) { | 350 PPB_FileRef_CreateInfo* result) { |
253 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); | 351 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); |
254 if (enter.succeeded()) | 352 if (enter.succeeded()) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 file_ref, callback_factory_, | 425 file_ref, callback_factory_, |
328 &PPB_FileRef_Proxy::OnCallbackCompleteInHost, file_ref, callback_id); | 426 &PPB_FileRef_Proxy::OnCallbackCompleteInHost, file_ref, callback_id); |
329 if (enter.succeeded()) { | 427 if (enter.succeeded()) { |
330 enter.SetResult(enter.object()->Rename(new_file_ref.host_resource(), | 428 enter.SetResult(enter.object()->Rename(new_file_ref.host_resource(), |
331 enter.callback())); | 429 enter.callback())); |
332 } | 430 } |
333 } | 431 } |
334 | 432 |
335 void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref, | 433 void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref, |
336 uint32_t callback_id) { | 434 uint32_t callback_id) { |
337 PP_FileInfo* info = new PP_FileInfo(); | 435 linked_ptr<PP_FileInfo> info(new PP_FileInfo()); |
338 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( | 436 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( |
339 file_ref, callback_factory_, | 437 file_ref, callback_factory_, |
340 &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, | 438 &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, |
341 base::Owned(info), callback_id); | 439 info, callback_id); |
342 if (enter.succeeded()) | 440 if (enter.succeeded()) |
343 enter.SetResult(enter.object()->Query(info, enter.callback())); | 441 enter.SetResult(enter.object()->QueryInHost(info, enter.callback())); |
344 } | 442 } |
345 | 443 |
346 void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, | 444 void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, |
347 SerializedVarReturnValue result) { | 445 SerializedVarReturnValue result) { |
348 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); | 446 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); |
349 if (enter.succeeded()) | 447 if (enter.succeeded()) |
350 result.Return(dispatcher(), enter.object()->GetAbsolutePath()); | 448 result.Return(dispatcher(), enter.object()->GetAbsolutePath()); |
351 } | 449 } |
| 450 |
| 451 void PPB_FileRef_Proxy::OnMsgReadDirectoryEntries(const HostResource& file_ref, |
| 452 uint32_t callback_id) { |
| 453 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files( |
| 454 new std::vector<ppapi::PPB_FileRef_CreateInfo>()); |
| 455 linked_ptr<std::vector<PP_FileType> > file_types( |
| 456 new std::vector<PP_FileType>()); |
| 457 HostCallbackParams params(file_ref, callback_id); |
| 458 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( |
| 459 file_ref, callback_factory_, |
| 460 &PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost, |
| 461 params, files, file_types); |
| 462 if (enter.succeeded()) { |
| 463 enter.SetResult(enter.object()->ReadDirectoryEntriesInHost( |
| 464 files, file_types, enter.callback())); |
| 465 } |
| 466 } |
| 467 |
352 #endif // !defined(OS_NACL) | 468 #endif // !defined(OS_NACL) |
353 | 469 |
354 void PPB_FileRef_Proxy::OnMsgCallbackComplete( | 470 void PPB_FileRef_Proxy::OnMsgCallbackComplete( |
355 const HostResource& host_resource, | 471 const HostResource& host_resource, |
356 uint32_t callback_id, | 472 uint32_t callback_id, |
357 int32_t result) { | 473 int32_t result) { |
358 // Forward the callback info to the plugin resource. | 474 // Forward the callback info to the plugin resource. |
359 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); | 475 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
360 if (enter.succeeded()) | 476 if (enter.succeeded()) |
361 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); | 477 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
362 } | 478 } |
363 | 479 |
364 void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( | 480 void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( |
365 const HostResource& host_resource, | 481 const HostResource& host_resource, |
366 const PP_FileInfo& info, | 482 const PP_FileInfo& info, |
367 uint32_t callback_id, | 483 uint32_t callback_id, |
368 int32_t result) { | 484 int32_t result) { |
369 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); | 485 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
370 if (enter.succeeded()) { | 486 if (!enter.succeeded()) |
371 // Set the FileInfo output parameter. | 487 return; |
372 static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info); | 488 |
373 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); | 489 if (result == PP_OK) { |
| 490 result = static_cast<FileRef*>(enter.object())->SetFileInfo( |
| 491 callback_id, info); |
374 } | 492 } |
| 493 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
| 494 } |
| 495 |
| 496 void PPB_FileRef_Proxy::OnMsgReadDirectoryEntriesCallbackComplete( |
| 497 const HostResource& host_resource, |
| 498 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
| 499 const std::vector<PP_FileType>& file_types, |
| 500 uint32_t callback_id, |
| 501 int32_t result) { |
| 502 CHECK_EQ(infos.size(), file_types.size()); |
| 503 |
| 504 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
| 505 if (!enter.succeeded()) |
| 506 return; |
| 507 |
| 508 if (result == PP_OK) { |
| 509 result = |
| 510 static_cast<FileRef*>(enter.object())->SetReadDirectoryEntriesOutput( |
| 511 callback_id, infos, file_types); |
| 512 } |
| 513 static_cast<FileRef*>(enter.object())->ExecuteCallback( |
| 514 callback_id, result); |
375 } | 515 } |
376 | 516 |
377 #if !defined(OS_NACL) | 517 #if !defined(OS_NACL) |
378 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( | 518 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( |
379 int32_t result, | 519 int32_t result, |
380 const HostResource& host_resource, | 520 const HostResource& host_resource, |
381 uint32_t callback_id) { | 521 uint32_t callback_id) { |
382 // Execute OnMsgCallbackComplete in the plugin process. | 522 // Execute OnMsgCallbackComplete in the plugin process. |
383 Send(new PpapiMsg_PPBFileRef_CallbackComplete( | 523 Send(new PpapiMsg_PPBFileRef_CallbackComplete( |
384 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); | 524 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); |
385 } | 525 } |
386 | 526 |
387 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( | 527 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( |
388 int32_t result, | 528 int32_t result, |
389 const HostResource& host_resource, | 529 const HostResource& host_resource, |
390 base::internal::OwnedWrapper<PP_FileInfo> info, | 530 linked_ptr<PP_FileInfo> info, |
391 uint32_t callback_id) { | 531 uint32_t callback_id) { |
392 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( | 532 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( |
393 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); | 533 API_ID_PPB_FILE_REF, host_resource, *info, callback_id, result)); |
394 } | 534 } |
| 535 |
| 536 void PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost( |
| 537 int32_t result, |
| 538 HostCallbackParams params, |
| 539 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
| 540 linked_ptr<std::vector<PP_FileType> > file_types) { |
| 541 Send(new PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete( |
| 542 API_ID_PPB_FILE_REF, params.host_resource, |
| 543 *files, *file_types, params.callback_id, result)); |
| 544 } |
| 545 |
395 #endif // !defined(OS_NACL) | 546 #endif // !defined(OS_NACL) |
396 | 547 |
397 } // namespace proxy | 548 } // namespace proxy |
398 } // namespace ppapi | 549 } // namespace ppapi |
OLD | NEW |