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_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/ppb_file_ref.h" | 11 #include "ppapi/c/ppb_file_ref.h" |
12 #include "ppapi/c/private/ppb_file_ref_private.h" | 12 #include "ppapi/c/private/ppb_file_ref_private.h" |
13 #include "ppapi/c/private/ppb_proxy_private.h" | 13 #include "ppapi/c/private/ppb_proxy_private.h" |
14 #include "ppapi/proxy/enter_proxy.h" | 14 #include "ppapi/proxy/enter_proxy.h" |
15 #include "ppapi/proxy/host_dispatcher.h" | 15 #include "ppapi/proxy/host_dispatcher.h" |
16 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
17 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
18 #include "ppapi/proxy/serialized_var.h" | 18 #include "ppapi/proxy/serialized_var.h" |
| 19 #include "ppapi/shared_impl/array_writer.h" |
19 #include "ppapi/shared_impl/ppb_file_ref_shared.h" | 20 #include "ppapi/shared_impl/ppb_file_ref_shared.h" |
20 #include "ppapi/shared_impl/scoped_pp_resource.h" | 21 #include "ppapi/shared_impl/scoped_pp_resource.h" |
21 #include "ppapi/shared_impl/tracked_callback.h" | 22 #include "ppapi/shared_impl/tracked_callback.h" |
22 #include "ppapi/thunk/resource_creation_api.h" | 23 #include "ppapi/thunk/resource_creation_api.h" |
23 #include "ppapi/thunk/thunk.h" | 24 #include "ppapi/thunk/thunk.h" |
24 | 25 |
25 using ppapi::thunk::EnterResourceNoLock; | 26 using ppapi::thunk::EnterResourceNoLock; |
26 using ppapi::thunk::PPB_FileRef_API; | 27 using ppapi::thunk::PPB_FileRef_API; |
27 using ppapi::thunk::ResourceCreationAPI; | 28 using ppapi::thunk::ResourceCreationAPI; |
28 | 29 |
29 namespace ppapi { | 30 namespace ppapi { |
30 namespace proxy { | 31 namespace proxy { |
31 | 32 |
| 33 namespace { |
| 34 |
| 35 void ReleaseEntries(const std::vector<PP_DirectoryEntry>& entries) { |
| 36 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); |
| 37 for (std::vector<PP_DirectoryEntry>::const_iterator it = entries.begin(); |
| 38 it != entries.end(); ++it) |
| 39 tracker->ReleaseResource(it->file_ref); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
32 class FileRef : public PPB_FileRef_Shared { | 44 class FileRef : public PPB_FileRef_Shared { |
33 public: | 45 public: |
34 explicit FileRef(const PPB_FileRef_CreateInfo& info); | 46 explicit FileRef(const PPB_FileRef_CreateInfo& info); |
35 virtual ~FileRef(); | 47 virtual ~FileRef(); |
36 | 48 |
37 // Resource overrides. | 49 // Resource overrides. |
38 virtual void LastPluginRefWasDeleted() OVERRIDE; | 50 virtual void LastPluginRefWasDeleted() OVERRIDE; |
39 | 51 |
40 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). | 52 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). |
41 virtual PP_Resource GetParent() OVERRIDE; | 53 virtual PP_Resource GetParent() OVERRIDE; |
42 virtual int32_t MakeDirectory( | 54 virtual int32_t MakeDirectory( |
43 PP_Bool make_ancestors, | 55 PP_Bool make_ancestors, |
44 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 56 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
45 virtual int32_t Touch(PP_Time last_access_time, | 57 virtual int32_t Touch(PP_Time last_access_time, |
46 PP_Time last_modified_time, | 58 PP_Time last_modified_time, |
47 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 59 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
48 virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; | 60 virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
49 virtual int32_t Rename(PP_Resource new_file_ref, | 61 virtual int32_t Rename(PP_Resource new_file_ref, |
50 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 62 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
51 virtual int32_t Query(PP_FileInfo* info, | 63 virtual int32_t Query(PP_FileInfo* info, |
52 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 64 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 65 virtual int32_t ReadDirectoryEntries( |
| 66 const PP_ArrayOutput& output, |
| 67 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 68 virtual int32_t QueryInHost( |
| 69 linked_ptr<PP_FileInfo> info, |
| 70 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 71 virtual int32_t ReadDirectoryEntriesInHost( |
| 72 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
| 73 linked_ptr<std::vector<PP_FileType> > file_types, |
| 74 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
53 virtual PP_Var GetAbsolutePath() OVERRIDE; | 75 virtual PP_Var GetAbsolutePath() OVERRIDE; |
54 | 76 |
55 // Executes the pending callback with the given ID. See pending_callbacks_. | 77 // Executes the pending callback with the given ID. See pending_callbacks_. |
56 void ExecuteCallback(uint32_t callback_id, int32_t result); | 78 void ExecuteCallback(uint32_t callback_id, int32_t result); |
57 void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); | 79 int32_t SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); |
| 80 int32_t SetReadDirectoryEntriesOutput( |
| 81 uint32_t callback_id, |
| 82 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
| 83 const std::vector<PP_FileType>& file_types); |
58 | 84 |
59 private: | 85 private: |
60 PluginDispatcher* GetDispatcher() const { | 86 PluginDispatcher* GetDispatcher() const { |
61 return PluginDispatcher::GetForResource(this); | 87 return PluginDispatcher::GetForResource(this); |
62 } | 88 } |
63 | 89 |
64 // Adds a callback to the list and returns its ID. | 90 // Adds a callback to the list and returns its ID. |
65 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); | 91 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); |
66 | 92 |
67 // This class can have any number of out-standing requests with completion | 93 // This class can have any number of out-standing requests with completion |
68 // callbacks, in contrast to most resources which have one possible pending | 94 // callbacks, in contrast to most resources which have one possible pending |
69 // callback pending (like a Flush callback). | 95 // callback pending (like a Flush callback). |
70 // | 96 // |
71 // To keep track of them, assign integer IDs to the callbacks, which is how | 97 // 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 | 98 // 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. | 99 // back here. Use unsigned so that overflow is well-defined. |
74 uint32_t next_callback_id_; | 100 uint32_t next_callback_id_; |
75 typedef std::map<uint32_t, | 101 typedef std::map<uint32_t, |
76 scoped_refptr<TrackedCallback> > PendingCallbackMap; | 102 scoped_refptr<TrackedCallback> > PendingCallbackMap; |
77 PendingCallbackMap pending_callbacks_; | 103 PendingCallbackMap pending_callbacks_; |
78 | 104 |
79 // Used to keep pointers to PP_FileInfo instances that are written before | 105 // 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 | 106 // callbacks are invoked. The id of a pending file info will match that of |
81 // the corresponding callback. | 107 // the corresponding callback. |
82 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; | 108 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; |
83 PendingFileInfoMap pending_file_infos_; | 109 PendingFileInfoMap pending_file_infos_; |
84 | 110 |
| 111 // Used to keep PP_ArrayOutput instances that are written before callbacks |
| 112 // are invoked. The id of a pending array output will match that of the |
| 113 // corresponding callback. |
| 114 typedef std::map<uint32_t, PP_ArrayOutput> |
| 115 PendingReadDirectoryEntriesOutputMap; |
| 116 PendingReadDirectoryEntriesOutputMap pending_read_entries_outputs_; |
| 117 |
85 // Holds a reference on plugin side when running out of process, so that | 118 // 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 | 119 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for |
87 // corresponding code for in-process mode. Note that this workaround will | 120 // corresponding code for in-process mode. Note that this workaround will |
88 // be no longer needed after FileRef refactoring. | 121 // be no longer needed after FileRef refactoring. |
89 ScopedPPResource file_system_; | 122 ScopedPPResource file_system_; |
90 | 123 |
91 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); | 124 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); |
92 }; | 125 }; |
93 | 126 |
94 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) | 127 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) |
95 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), | 128 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), |
96 next_callback_id_(0u), | 129 next_callback_id_(0u), |
97 file_system_(info.file_system_plugin_resource) { | 130 file_system_(info.file_system_plugin_resource) { |
98 } | 131 } |
99 | 132 |
100 FileRef::~FileRef() { | 133 FileRef::~FileRef() { |
101 // The callbacks map should have been cleared by LastPluginRefWasDeleted. | 134 // The callbacks map should have been cleared by LastPluginRefWasDeleted. |
102 DCHECK(pending_callbacks_.empty()); | 135 DCHECK(pending_callbacks_.empty()); |
103 DCHECK(pending_file_infos_.empty()); | 136 DCHECK(pending_file_infos_.empty()); |
| 137 DCHECK(pending_read_entries_outputs_.empty()); |
104 } | 138 } |
105 | 139 |
106 void FileRef::LastPluginRefWasDeleted() { | 140 void FileRef::LastPluginRefWasDeleted() { |
107 // The callback tracker will abort our callbacks for us. | 141 // The callback tracker will abort our callbacks for us. |
108 pending_callbacks_.clear(); | 142 pending_callbacks_.clear(); |
109 pending_file_infos_.clear(); | 143 pending_file_infos_.clear(); |
| 144 pending_read_entries_outputs_.clear(); |
110 } | 145 } |
111 | 146 |
112 PP_Resource FileRef::GetParent() { | 147 PP_Resource FileRef::GetParent() { |
113 PPB_FileRef_CreateInfo create_info; | 148 PPB_FileRef_CreateInfo create_info; |
114 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( | 149 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( |
115 API_ID_PPB_FILE_REF, host_resource(), &create_info)); | 150 API_ID_PPB_FILE_REF, host_resource(), &create_info)); |
116 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); | 151 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); |
117 } | 152 } |
118 | 153 |
119 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, | 154 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 int32_t FileRef::Query(PP_FileInfo* info, | 191 int32_t FileRef::Query(PP_FileInfo* info, |
157 scoped_refptr<TrackedCallback> callback) { | 192 scoped_refptr<TrackedCallback> callback) { |
158 // Store the pending file info id. | 193 // Store the pending file info id. |
159 int id = SendCallback(callback); | 194 int id = SendCallback(callback); |
160 pending_file_infos_[id] = info; | 195 pending_file_infos_[id] = info; |
161 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( | 196 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( |
162 API_ID_PPB_FILE_REF, host_resource(), id)); | 197 API_ID_PPB_FILE_REF, host_resource(), id)); |
163 return PP_OK_COMPLETIONPENDING; | 198 return PP_OK_COMPLETIONPENDING; |
164 } | 199 } |
165 | 200 |
| 201 int32_t FileRef::ReadDirectoryEntries( |
| 202 const PP_ArrayOutput& output, |
| 203 scoped_refptr<TrackedCallback> callback) { |
| 204 // Store the pending read entries output id. |
| 205 int id = SendCallback(callback); |
| 206 pending_read_entries_outputs_[id] = output; |
| 207 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadDirectoryEntries( |
| 208 API_ID_PPB_FILE_REF, host_resource(), id)); |
| 209 return PP_OK_COMPLETIONPENDING; |
| 210 } |
| 211 |
| 212 int32_t FileRef::QueryInHost( |
| 213 linked_ptr<PP_FileInfo> info, |
| 214 scoped_refptr<TrackedCallback> callback) { |
| 215 NOTREACHED(); |
| 216 return PP_ERROR_FAILED; |
| 217 } |
| 218 |
| 219 int32_t FileRef::ReadDirectoryEntriesInHost( |
| 220 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
| 221 linked_ptr<std::vector<PP_FileType> > file_types, |
| 222 scoped_refptr<TrackedCallback> callback) { |
| 223 NOTREACHED(); |
| 224 return PP_ERROR_FAILED; |
| 225 } |
| 226 |
166 PP_Var FileRef::GetAbsolutePath() { | 227 PP_Var FileRef::GetAbsolutePath() { |
167 ReceiveSerializedVarReturnValue result; | 228 ReceiveSerializedVarReturnValue result; |
168 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( | 229 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( |
169 API_ID_PPB_FILE_REF, host_resource(), &result)); | 230 API_ID_PPB_FILE_REF, host_resource(), &result)); |
170 return result.Return(GetDispatcher()); | 231 return result.Return(GetDispatcher()); |
171 } | 232 } |
172 | 233 |
173 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { | 234 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { |
174 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); | 235 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); |
175 if (found == pending_callbacks_.end()) { | 236 if (found == pending_callbacks_.end()) { |
176 // This will happen when the plugin deletes its resource with a pending | 237 // 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 | 238 // callback. The callback will be locally issued with an ABORTED call while |
178 // the operation may still be pending in the renderer. | 239 // the operation may still be pending in the renderer. |
179 return; | 240 return; |
180 } | 241 } |
181 | 242 |
182 // Executing the callback may mutate the callback list. | 243 // Executing the callback may mutate the callback list. |
183 scoped_refptr<TrackedCallback> callback = found->second; | 244 scoped_refptr<TrackedCallback> callback = found->second; |
184 pending_callbacks_.erase(found); | 245 pending_callbacks_.erase(found); |
185 callback->Run(result); | 246 callback->Run(result); |
186 } | 247 } |
187 | 248 |
188 void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { | 249 int32_t FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { |
189 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); | 250 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); |
190 if (found == pending_file_infos_.end()) | 251 if (found == pending_file_infos_.end()) |
191 return; | 252 return PP_ERROR_FAILED; |
192 PP_FileInfo* target_info = found->second; | 253 PP_FileInfo* target_info = found->second; |
193 *target_info = info; | 254 *target_info = info; |
194 pending_file_infos_.erase(found); | 255 pending_file_infos_.erase(found); |
| 256 return PP_OK; |
| 257 } |
| 258 |
| 259 int32_t FileRef::SetReadDirectoryEntriesOutput( |
| 260 uint32_t callback_id, |
| 261 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
| 262 const std::vector<PP_FileType>& file_types) { |
| 263 PendingReadDirectoryEntriesOutputMap::iterator found = |
| 264 pending_read_entries_outputs_.find(callback_id); |
| 265 if (found == pending_read_entries_outputs_.end()) |
| 266 return PP_ERROR_FAILED; |
| 267 |
| 268 PP_ArrayOutput output = found->second; |
| 269 pending_read_entries_outputs_.erase(found); |
| 270 |
| 271 std::vector<PP_DirectoryEntry> entries; |
| 272 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; |
| 273 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 if (result == PP_OK) { |
372 static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info); | 488 result = static_cast<FileRef*>(enter.object())->SetFileInfo( |
| 489 callback_id, info); |
| 490 } |
373 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); | 491 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
374 } | 492 } |
375 } | 493 } |
376 | 494 |
| 495 void PPB_FileRef_Proxy::OnMsgReadDirectoryEntriesCallbackComplete( |
| 496 const HostResource& host_resource, |
| 497 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
| 498 const std::vector<PP_FileType>& file_types, |
| 499 uint32_t callback_id, |
| 500 int32_t result) { |
| 501 CHECK_EQ(infos.size(), file_types.size()); |
| 502 |
| 503 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
| 504 if (enter.succeeded()) { |
| 505 if (result == PP_OK) { |
| 506 result = |
| 507 static_cast<FileRef*>(enter.object())->SetReadDirectoryEntriesOutput( |
| 508 callback_id, infos, file_types); |
| 509 } |
| 510 static_cast<FileRef*>(enter.object())->ExecuteCallback( |
| 511 callback_id, result); |
| 512 } |
| 513 } |
| 514 |
377 #if !defined(OS_NACL) | 515 #if !defined(OS_NACL) |
378 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( | 516 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( |
379 int32_t result, | 517 int32_t result, |
380 const HostResource& host_resource, | 518 const HostResource& host_resource, |
381 uint32_t callback_id) { | 519 uint32_t callback_id) { |
382 // Execute OnMsgCallbackComplete in the plugin process. | 520 // Execute OnMsgCallbackComplete in the plugin process. |
383 Send(new PpapiMsg_PPBFileRef_CallbackComplete( | 521 Send(new PpapiMsg_PPBFileRef_CallbackComplete( |
384 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); | 522 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); |
385 } | 523 } |
386 | 524 |
387 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( | 525 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( |
388 int32_t result, | 526 int32_t result, |
389 const HostResource& host_resource, | 527 const HostResource& host_resource, |
390 base::internal::OwnedWrapper<PP_FileInfo> info, | 528 linked_ptr<PP_FileInfo> info, |
391 uint32_t callback_id) { | 529 uint32_t callback_id) { |
392 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( | 530 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( |
393 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); | 531 API_ID_PPB_FILE_REF, host_resource, *info, callback_id, result)); |
394 } | 532 } |
| 533 |
| 534 void PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost( |
| 535 int32_t result, |
| 536 HostCallbackParams params, |
| 537 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
| 538 linked_ptr<std::vector<PP_FileType> > file_types) { |
| 539 Send(new PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete( |
| 540 API_ID_PPB_FILE_REF, params.host_resource, |
| 541 *files, *file_types, params.callback_id, result)); |
| 542 } |
| 543 |
395 #endif // !defined(OS_NACL) | 544 #endif // !defined(OS_NACL) |
396 | 545 |
397 } // namespace proxy | 546 } // namespace proxy |
398 } // namespace ppapi | 547 } // namespace ppapi |
OLD | NEW |