Chromium Code Reviews| Index: ppapi/proxy/ppb_file_ref_proxy.cc |
| diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc |
| index 49dac58d60ada7d43589bd10a201186336c6adf8..eb55f8f2ac6485caf8931666eae858fc84f95666 100644 |
| --- a/ppapi/proxy/ppb_file_ref_proxy.cc |
| +++ b/ppapi/proxy/ppb_file_ref_proxy.cc |
| @@ -47,10 +47,13 @@ class FileRef : public PPB_FileRef_Shared { |
| virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| virtual int32_t Rename(PP_Resource new_file_ref, |
| scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| + virtual int32_t Query(PP_FileInfo *info, |
|
yzshen1
2013/03/21 17:18:11
nit: '*' should be adjacent to PP_FileInfo
teravest
2013/03/21 19:48:57
Done.
|
| + scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| virtual PP_Var GetAbsolutePath() OVERRIDE; |
| // Executes the pending callback with the given ID. See pending_callbacks_. |
| void ExecuteCallback(int callback_id, int32_t result); |
| + void SetFileInfo(int callback_id, const PP_FileInfo &info); |
|
yzshen1
2013/03/21 17:18:11
nit: '&' should be adjacent to PP_FileInfo
teravest
2013/03/21 19:48:57
Done.
|
| private: |
| PluginDispatcher* GetDispatcher() const { |
| @@ -72,6 +75,12 @@ class FileRef : public PPB_FileRef_Shared { |
| scoped_refptr<TrackedCallback> > PendingCallbackMap; |
| PendingCallbackMap pending_callbacks_; |
| + // Used to keep pointers to PP_FileInfo instances that are written before |
| + // callbacks are invoked. The id of a pending file info will match that of |
| + // the corresponding callback. |
| + typedef std::map<unsigned int, PP_FileInfo*> PendingFileInfoMap; |
| + PendingFileInfoMap pending_file_infos_; |
|
yzshen1
2013/03/21 17:18:11
You should do cleanup like |pending_callbacks_| wh
teravest
2013/03/21 19:48:57
Done.
|
| + |
| DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); |
| }; |
| @@ -134,6 +143,16 @@ int32_t FileRef::Rename(PP_Resource new_file_ref, |
| return PP_OK_COMPLETIONPENDING; |
| } |
| +int32_t FileRef::Query(PP_FileInfo* info, |
| + scoped_refptr<TrackedCallback> callback) { |
| + // Store the pending file info id. |
| + int id = SendCallback(callback); |
| + pending_file_infos_[id] = info; |
| + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( |
| + API_ID_PPB_FILE_REF, host_resource(), id)); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| PP_Var FileRef::GetAbsolutePath() { |
| ReceiveSerializedVarReturnValue result; |
| GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( |
| @@ -156,6 +175,15 @@ void FileRef::ExecuteCallback(int callback_id, int32_t result) { |
| callback->Run(result); |
| } |
| +void FileRef::SetFileInfo(int callback_id, const PP_FileInfo &info) { |
|
yzshen1
2013/03/21 17:18:11
ditto.
teravest
2013/03/21 19:48:57
Done.
|
| + PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); |
| + if (found == pending_file_infos_.end()) |
| + return; |
| + PP_FileInfo* target_info = found->second; |
| + *target_info = info; |
| + pending_file_infos_.erase(found); |
| +} |
| + |
| int FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { |
| // In extreme cases the IDs may wrap around, so avoid duplicates. |
| while (pending_callbacks_.count(next_callback_id_)) |
| @@ -200,12 +228,15 @@ bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) |
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) |
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) |
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, |
| OnMsgGetAbsolutePath) |
| #endif // !defined(OS_NACL) |
| IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, |
| OnMsgCallbackComplete) |
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, |
| + OnMsgQueryCallbackComplete) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -294,6 +325,17 @@ void PPB_FileRef_Proxy::OnMsgRename(const HostResource& file_ref, |
| } |
| } |
| +void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref, |
| + int callback_id) { |
| + PP_FileInfo info; |
|
yzshen1
2013/03/21 17:18:11
|info| is on the stack, it seems we rely on the fa
teravest
2013/03/21 19:48:57
info is on the heap now.
|
| + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( |
| + file_ref, callback_factory_, |
| + &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, &info, |
| + callback_id); |
| + if (enter.succeeded()) |
| + enter.SetResult(enter.object()->Query(&info, enter.callback())); |
| +} |
| + |
| void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, |
| SerializedVarReturnValue result) { |
| EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); |
| @@ -312,6 +354,19 @@ void PPB_FileRef_Proxy::OnMsgCallbackComplete( |
| static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
| } |
| +void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( |
| + const HostResource& host_resource, |
| + PP_FileInfo info, |
| + int callback_id, |
| + int32_t result) { |
| + EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
| + if (enter.succeeded()) { |
| + // Set the FileInfo output parameter. |
| + static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info); |
| + static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
| + } |
| +} |
| + |
| #if !defined(OS_NACL) |
| void PPB_FileRef_Proxy::OnCallbackCompleteInHost( |
| int32_t result, |
| @@ -321,6 +376,22 @@ void PPB_FileRef_Proxy::OnCallbackCompleteInHost( |
| Send(new PpapiMsg_PPBFileRef_CallbackComplete( |
| API_ID_PPB_FILE_REF, host_resource, callback_id, result)); |
| } |
| + |
| +void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( |
| + int32_t result, |
| + const HostResource& host_resource, |
| + PP_FileInfo* info, |
| + int callback_id) { |
| + if (result == PP_OK) { |
| + Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( |
| + API_ID_PPB_FILE_REF, host_resource, *info, callback_id, result)); |
| + } else { |
| + PP_FileInfo tmp_info; |
| + memset(&tmp_info, 0, sizeof(tmp_info)); |
| + Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( |
| + API_ID_PPB_FILE_REF, host_resource, tmp_info, callback_id, result)); |
| + } |
| +} |
| #endif // !defined(OS_NACL) |
| } // namespace proxy |