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..d18f08805f7fdeb3f0ee625caae1fb23c344e0b9 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, |
+ 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); |
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_; |
+ |
DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); |
}; |
@@ -83,11 +92,13 @@ FileRef::FileRef(const PPB_FileRef_CreateInfo& info) |
FileRef::~FileRef() { |
// The callbacks map should have been cleared by LastPluginRefWasDeleted. |
DCHECK(pending_callbacks_.empty()); |
+ DCHECK(pending_file_infos_.empty()); |
} |
void FileRef::LastPluginRefWasDeleted() { |
// The callback tracker will abort our callbacks for us. |
pending_callbacks_.clear(); |
+ pending_file_infos_.clear(); |
} |
PP_Resource FileRef::GetParent() { |
@@ -134,6 +145,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 +177,15 @@ void FileRef::ExecuteCallback(int callback_id, int32_t result) { |
callback->Run(result); |
} |
+void FileRef::SetFileInfo(int callback_id, const PP_FileInfo& info) { |
+ 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 +230,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 +327,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 = new PP_FileInfo(); |
+ EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( |
+ file_ref, callback_factory_, |
+ &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, |
+ base::Owned(info), callback_id); |
yzshen1
2013/03/21 22:02:05
I thought you will need to change your OnQueryCall
|
+ 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 +356,19 @@ void PPB_FileRef_Proxy::OnMsgCallbackComplete( |
static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); |
} |
+void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( |
+ const HostResource& host_resource, |
+ const 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 +378,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 |