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 ReadEntries(const PP_ArrayOutput& output, | |
66 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
67 virtual int32_t ReadEntriesInHost( | |
68 std::vector<ppapi::PPB_FileRef_CreateInfo>* files, | |
69 std::vector<PP_FileType>* file_types, | |
70 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
53 virtual PP_Var GetAbsolutePath() OVERRIDE; | 71 virtual PP_Var GetAbsolutePath() OVERRIDE; |
54 | 72 |
55 // Executes the pending callback with the given ID. See pending_callbacks_. | 73 // Executes the pending callback with the given ID. See pending_callbacks_. |
56 void ExecuteCallback(uint32_t callback_id, int32_t result); | 74 void ExecuteCallback(uint32_t callback_id, int32_t result); |
57 void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); | 75 void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); |
76 int32_t SetReadEntriesOutput( | |
77 uint32_t callback_id, | |
78 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, | |
79 const std::vector<PP_FileType>& file_types); | |
58 | 80 |
59 private: | 81 private: |
60 PluginDispatcher* GetDispatcher() const { | 82 PluginDispatcher* GetDispatcher() const { |
61 return PluginDispatcher::GetForResource(this); | 83 return PluginDispatcher::GetForResource(this); |
62 } | 84 } |
63 | 85 |
64 // Adds a callback to the list and returns its ID. | 86 // Adds a callback to the list and returns its ID. |
65 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); | 87 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); |
66 | 88 |
67 // This class can have any number of out-standing requests with completion | 89 // This class can have any number of out-standing requests with completion |
68 // callbacks, in contrast to most resources which have one possible pending | 90 // callbacks, in contrast to most resources which have one possible pending |
69 // callback pending (like a Flush callback). | 91 // callback pending (like a Flush callback). |
70 // | 92 // |
71 // To keep track of them, assign integer IDs to the callbacks, which is how | 93 // 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 | 94 // 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. | 95 // back here. Use unsigned so that overflow is well-defined. |
74 uint32_t next_callback_id_; | 96 uint32_t next_callback_id_; |
75 typedef std::map<uint32_t, | 97 typedef std::map<uint32_t, |
76 scoped_refptr<TrackedCallback> > PendingCallbackMap; | 98 scoped_refptr<TrackedCallback> > PendingCallbackMap; |
77 PendingCallbackMap pending_callbacks_; | 99 PendingCallbackMap pending_callbacks_; |
78 | 100 |
79 // Used to keep pointers to PP_FileInfo instances that are written before | 101 // 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 | 102 // callbacks are invoked. The id of a pending file info will match that of |
81 // the corresponding callback. | 103 // the corresponding callback. |
82 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; | 104 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; |
83 PendingFileInfoMap pending_file_infos_; | 105 PendingFileInfoMap pending_file_infos_; |
84 | 106 |
107 // Used to keep PP_ArrayOutput instances that are written before callbacks | |
108 // are invoked. The id of a pending array output will match that of the | |
109 // corresponding callback. | |
110 typedef std::map<uint32_t, PP_ArrayOutput> PendingReadEntriesOutputMap; | |
111 PendingReadEntriesOutputMap pending_read_entries_outputs_; | |
112 | |
85 // Holds a reference on plugin side when running out of process, so that | 113 // 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 | 114 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for |
87 // corresponding code for in-process mode. Note that this workaround will | 115 // corresponding code for in-process mode. Note that this workaround will |
88 // be no longer needed after FileRef refactoring. | 116 // be no longer needed after FileRef refactoring. |
89 ScopedPPResource file_system_; | 117 ScopedPPResource file_system_; |
90 | 118 |
91 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); | 119 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); |
92 }; | 120 }; |
93 | 121 |
94 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) | 122 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) |
95 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), | 123 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), |
96 next_callback_id_(0u), | 124 next_callback_id_(0u), |
97 file_system_(info.file_system_plugin_resource) { | 125 file_system_(info.file_system_plugin_resource) { |
98 } | 126 } |
99 | 127 |
100 FileRef::~FileRef() { | 128 FileRef::~FileRef() { |
101 // The callbacks map should have been cleared by LastPluginRefWasDeleted. | 129 // The callbacks map should have been cleared by LastPluginRefWasDeleted. |
102 DCHECK(pending_callbacks_.empty()); | 130 DCHECK(pending_callbacks_.empty()); |
103 DCHECK(pending_file_infos_.empty()); | 131 DCHECK(pending_file_infos_.empty()); |
132 DCHECK(pending_read_entries_outputs_.empty()); | |
104 } | 133 } |
105 | 134 |
106 void FileRef::LastPluginRefWasDeleted() { | 135 void FileRef::LastPluginRefWasDeleted() { |
107 // The callback tracker will abort our callbacks for us. | 136 // The callback tracker will abort our callbacks for us. |
108 pending_callbacks_.clear(); | 137 pending_callbacks_.clear(); |
109 pending_file_infos_.clear(); | 138 pending_file_infos_.clear(); |
139 pending_read_entries_outputs_.clear(); | |
110 } | 140 } |
111 | 141 |
112 PP_Resource FileRef::GetParent() { | 142 PP_Resource FileRef::GetParent() { |
113 PPB_FileRef_CreateInfo create_info; | 143 PPB_FileRef_CreateInfo create_info; |
114 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( | 144 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( |
115 API_ID_PPB_FILE_REF, host_resource(), &create_info)); | 145 API_ID_PPB_FILE_REF, host_resource(), &create_info)); |
116 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); | 146 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); |
117 } | 147 } |
118 | 148 |
119 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, | 149 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, | 186 int32_t FileRef::Query(PP_FileInfo* info, |
157 scoped_refptr<TrackedCallback> callback) { | 187 scoped_refptr<TrackedCallback> callback) { |
158 // Store the pending file info id. | 188 // Store the pending file info id. |
159 int id = SendCallback(callback); | 189 int id = SendCallback(callback); |
160 pending_file_infos_[id] = info; | 190 pending_file_infos_[id] = info; |
161 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( | 191 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( |
162 API_ID_PPB_FILE_REF, host_resource(), id)); | 192 API_ID_PPB_FILE_REF, host_resource(), id)); |
163 return PP_OK_COMPLETIONPENDING; | 193 return PP_OK_COMPLETIONPENDING; |
164 } | 194 } |
165 | 195 |
196 int32_t FileRef::ReadEntries(const PP_ArrayOutput& output, | |
197 scoped_refptr<TrackedCallback> callback) { | |
198 // Store the pending read entries output id. | |
199 int id = SendCallback(callback); | |
200 pending_read_entries_outputs_[id] = output; | |
201 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadEntries( | |
202 API_ID_PPB_FILE_REF, host_resource(), id)); | |
203 return PP_OK_COMPLETIONPENDING; | |
204 } | |
205 | |
206 int32_t FileRef::ReadEntriesInHost( | |
207 std::vector<ppapi::PPB_FileRef_CreateInfo>* files, | |
208 std::vector<PP_FileType>* file_types, | |
209 scoped_refptr<TrackedCallback> callback) { | |
210 NOTREACHED(); | |
211 return PP_ERROR_FAILED; | |
212 } | |
213 | |
166 PP_Var FileRef::GetAbsolutePath() { | 214 PP_Var FileRef::GetAbsolutePath() { |
167 ReceiveSerializedVarReturnValue result; | 215 ReceiveSerializedVarReturnValue result; |
168 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( | 216 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( |
169 API_ID_PPB_FILE_REF, host_resource(), &result)); | 217 API_ID_PPB_FILE_REF, host_resource(), &result)); |
170 return result.Return(GetDispatcher()); | 218 return result.Return(GetDispatcher()); |
171 } | 219 } |
172 | 220 |
173 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { | 221 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { |
174 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); | 222 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); |
175 if (found == pending_callbacks_.end()) { | 223 if (found == pending_callbacks_.end()) { |
(...skipping 11 matching lines...) Expand all Loading... | |
187 | 235 |
188 void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { | 236 void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { |
189 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); | 237 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); |
190 if (found == pending_file_infos_.end()) | 238 if (found == pending_file_infos_.end()) |
191 return; | 239 return; |
192 PP_FileInfo* target_info = found->second; | 240 PP_FileInfo* target_info = found->second; |
193 *target_info = info; | 241 *target_info = info; |
194 pending_file_infos_.erase(found); | 242 pending_file_infos_.erase(found); |
195 } | 243 } |
196 | 244 |
245 int32_t FileRef::SetReadEntriesOutput( | |
246 uint32_t callback_id, | |
247 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, | |
248 const std::vector<PP_FileType>& file_types) { | |
249 PendingReadEntriesOutputMap::iterator found = | |
250 pending_read_entries_outputs_.find(callback_id); | |
251 if (found == pending_read_entries_outputs_.end()) | |
252 return PP_OK; | |
253 | |
254 PP_ArrayOutput output = found->second; | |
255 pending_read_entries_outputs_.erase(found); | |
256 | |
257 std::vector<PP_DirectoryEntry> entries; | |
258 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; | |
259 i < infos.size(); ++i) { | |
260 PP_DirectoryEntry entry; | |
261 entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); | |
262 entry.file_type = file_types[i]; | |
263 entries.push_back(entry); | |
264 } | |
265 | |
266 ArrayWriter writer(output); | |
267 if (!writer.is_valid()) { | |
268 ReleaseEntries(entries); | |
269 entries.clear(); | |
270 return PP_ERROR_BADARGUMENT; | |
271 } | |
272 | |
273 writer.StoreVector(entries); | |
274 entries.clear(); | |
275 return PP_OK; | |
276 } | |
277 | |
197 uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { | 278 uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { |
198 // In extreme cases the IDs may wrap around, so avoid duplicates. | 279 // In extreme cases the IDs may wrap around, so avoid duplicates. |
199 while (pending_callbacks_.count(next_callback_id_)) | 280 while (pending_callbacks_.count(next_callback_id_)) |
200 ++next_callback_id_; | 281 ++next_callback_id_; |
201 | 282 |
202 pending_callbacks_[next_callback_id_] = callback; | 283 pending_callbacks_[next_callback_id_] = callback; |
203 return next_callback_id_++; | 284 return next_callback_id_++; |
204 } | 285 } |
205 | 286 |
206 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) | 287 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) |
(...skipping 20 matching lines...) Expand all Loading... | |
227 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) | 308 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) |
228 #if !defined(OS_NACL) | 309 #if !defined(OS_NACL) |
229 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) | 310 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) |
230 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) | 311 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) |
231 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, | 312 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, |
232 OnMsgMakeDirectory) | 313 OnMsgMakeDirectory) |
233 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) | 314 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) |
234 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) | 315 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) |
235 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) | 316 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) |
236 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) | 317 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) |
318 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_ReadEntries, OnMsgReadEntries) | |
237 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, | 319 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, |
238 OnMsgGetAbsolutePath) | 320 OnMsgGetAbsolutePath) |
239 #endif // !defined(OS_NACL) | 321 #endif // !defined(OS_NACL) |
240 | 322 |
241 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, | 323 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, |
242 OnMsgCallbackComplete) | 324 OnMsgCallbackComplete) |
243 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, | 325 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, |
244 OnMsgQueryCallbackComplete) | 326 OnMsgQueryCallbackComplete) |
327 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_ReadEntriesCallbackComplete, | |
328 OnMsgReadEntriesCallbackComplete) | |
245 IPC_MESSAGE_UNHANDLED(handled = false) | 329 IPC_MESSAGE_UNHANDLED(handled = false) |
246 IPC_END_MESSAGE_MAP() | 330 IPC_END_MESSAGE_MAP() |
247 return handled; | 331 return handled; |
248 } | 332 } |
249 | 333 |
250 // static | 334 // static |
251 void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, | 335 void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, |
252 PPB_FileRef_CreateInfo* result) { | 336 PPB_FileRef_CreateInfo* result) { |
253 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); | 337 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); |
254 if (enter.succeeded()) | 338 if (enter.succeeded()) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 if (enter.succeeded()) | 426 if (enter.succeeded()) |
343 enter.SetResult(enter.object()->Query(info, enter.callback())); | 427 enter.SetResult(enter.object()->Query(info, enter.callback())); |
344 } | 428 } |
345 | 429 |
346 void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, | 430 void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, |
347 SerializedVarReturnValue result) { | 431 SerializedVarReturnValue result) { |
348 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); | 432 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); |
349 if (enter.succeeded()) | 433 if (enter.succeeded()) |
350 result.Return(dispatcher(), enter.object()->GetAbsolutePath()); | 434 result.Return(dispatcher(), enter.object()->GetAbsolutePath()); |
351 } | 435 } |
436 | |
437 void PPB_FileRef_Proxy::OnMsgReadEntries(const HostResource& file_ref, | |
438 uint32_t callback_id) { | |
439 std::vector<ppapi::PPB_FileRef_CreateInfo>* files = | |
440 new std::vector<ppapi::PPB_FileRef_CreateInfo>(); | |
441 std::vector<PP_FileType>* file_types = new std::vector<PP_FileType>(); | |
442 HostCallbackParams* params = new HostCallbackParams(file_ref, callback_id); | |
443 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( | |
444 file_ref, callback_factory_, | |
445 &PPB_FileRef_Proxy::OnReadEntriesCallbackCompleteInHost, | |
446 base::Owned(params), base::Owned(files), base::Owned(file_types)); | |
447 if (enter.succeeded()) { | |
448 enter.SetResult(enter.object()->ReadEntriesInHost(files, file_types, | |
449 enter.callback())); | |
450 } | |
451 } | |
452 | |
352 #endif // !defined(OS_NACL) | 453 #endif // !defined(OS_NACL) |
353 | 454 |
354 void PPB_FileRef_Proxy::OnMsgCallbackComplete( | 455 void PPB_FileRef_Proxy::OnMsgCallbackComplete( |
355 const HostResource& host_resource, | 456 const HostResource& host_resource, |
356 uint32_t callback_id, | 457 uint32_t callback_id, |
357 int32_t result) { | 458 int32_t result) { |
358 // Forward the callback info to the plugin resource. | 459 // Forward the callback info to the plugin resource. |
359 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); | 460 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
360 if (enter.succeeded()) | 461 if (enter.succeeded()) |
361 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); | 462 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
362 } | 463 } |
363 | 464 |
364 void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( | 465 void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( |
365 const HostResource& host_resource, | 466 const HostResource& host_resource, |
366 const PP_FileInfo& info, | 467 const PP_FileInfo& info, |
367 uint32_t callback_id, | 468 uint32_t callback_id, |
368 int32_t result) { | 469 int32_t result) { |
369 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); | 470 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
370 if (enter.succeeded()) { | 471 if (enter.succeeded()) { |
371 // Set the FileInfo output parameter. | 472 // Set the FileInfo output parameter. |
372 static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info); | 473 static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info); |
373 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); | 474 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
374 } | 475 } |
375 } | 476 } |
376 | 477 |
478 void PPB_FileRef_Proxy::OnMsgReadEntriesCallbackComplete( | |
479 const HostResource& host_resource, | |
480 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, | |
481 const std::vector<PP_FileType>& file_types, | |
482 uint32_t callback_id, | |
483 int32_t result) { | |
484 CHECK_EQ(infos.size(), file_types.size()); | |
485 | |
486 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); | |
487 if (enter.succeeded()) { | |
488 int32_t set_result = | |
teravest
2013/05/02 17:32:10
Why bother setting the read entries if the result
hamaji
2013/05/02 18:49:40
Done.
| |
489 static_cast<FileRef*>(enter.object())->SetReadEntriesOutput( | |
490 callback_id, infos, file_types); | |
491 if (set_result != PP_OK) | |
492 result = set_result; | |
493 static_cast<FileRef*>(enter.object())->ExecuteCallback( | |
494 callback_id, result); | |
495 } | |
496 } | |
497 | |
377 #if !defined(OS_NACL) | 498 #if !defined(OS_NACL) |
378 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( | 499 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( |
379 int32_t result, | 500 int32_t result, |
380 const HostResource& host_resource, | 501 const HostResource& host_resource, |
381 uint32_t callback_id) { | 502 uint32_t callback_id) { |
382 // Execute OnMsgCallbackComplete in the plugin process. | 503 // Execute OnMsgCallbackComplete in the plugin process. |
383 Send(new PpapiMsg_PPBFileRef_CallbackComplete( | 504 Send(new PpapiMsg_PPBFileRef_CallbackComplete( |
384 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); | 505 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); |
385 } | 506 } |
386 | 507 |
387 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( | 508 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( |
388 int32_t result, | 509 int32_t result, |
389 const HostResource& host_resource, | 510 const HostResource& host_resource, |
390 base::internal::OwnedWrapper<PP_FileInfo> info, | 511 base::internal::OwnedWrapper<PP_FileInfo> info, |
391 uint32_t callback_id) { | 512 uint32_t callback_id) { |
392 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( | 513 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( |
393 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); | 514 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); |
394 } | 515 } |
516 | |
517 void PPB_FileRef_Proxy::OnReadEntriesCallbackCompleteInHost( | |
518 int32_t result, | |
519 base::internal::OwnedWrapper<HostCallbackParams> params, | |
dmichael (off chromium)
2013/05/02 19:43:54
Can you just pass this one by value? It doesn't se
hamaji
2013/05/02 20:14:49
Done.
| |
520 base::internal::OwnedWrapper< | |
521 std::vector<ppapi::PPB_FileRef_CreateInfo> > files, | |
522 base::internal::OwnedWrapper<std::vector<PP_FileType> > file_types) { | |
dmichael (off chromium)
2013/05/02 19:43:54
^^^ For these, you might consider linked_ptr<> or
hamaji
2013/05/02 20:14:49
Done. I used linked_ptr because auto_ptr is not al
| |
523 Send(new PpapiMsg_PPBFileRef_ReadEntriesCallbackComplete( | |
524 API_ID_PPB_FILE_REF, params.get()->host_resource, | |
525 *files.get(), *file_types.get(), params.get()->callback_id, result)); | |
526 } | |
527 | |
395 #endif // !defined(OS_NACL) | 528 #endif // !defined(OS_NACL) |
396 | 529 |
397 } // namespace proxy | 530 } // namespace proxy |
398 } // namespace ppapi | 531 } // namespace ppapi |
OLD | NEW |