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 da621598e24dd6ed24ef138b0790f8aa006214c8..bbef4fb0fae7d481356422c2cdc43eeeb62b1036 100644 |
--- a/ppapi/proxy/ppb_file_ref_proxy.cc |
+++ b/ppapi/proxy/ppb_file_ref_proxy.cc |
@@ -16,6 +16,7 @@ |
#include "ppapi/proxy/plugin_dispatcher.h" |
#include "ppapi/proxy/ppapi_messages.h" |
#include "ppapi/proxy/serialized_var.h" |
+#include "ppapi/shared_impl/array_writer.h" |
#include "ppapi/shared_impl/ppb_file_ref_shared.h" |
#include "ppapi/shared_impl/scoped_pp_resource.h" |
#include "ppapi/shared_impl/tracked_callback.h" |
@@ -29,6 +30,17 @@ using ppapi::thunk::ResourceCreationAPI; |
namespace ppapi { |
namespace proxy { |
+namespace { |
+ |
+void ReleaseEntries(const std::vector<PP_DirectoryEntry>& entries) { |
+ ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); |
+ for (std::vector<PP_DirectoryEntry>::const_iterator it = entries.begin(); |
+ it != entries.end(); ++it) |
+ tracker->ReleaseResource(it->file_ref); |
+} |
+ |
+} // namespace |
+ |
class FileRef : public PPB_FileRef_Shared { |
public: |
explicit FileRef(const PPB_FileRef_CreateInfo& info); |
@@ -50,11 +62,21 @@ class FileRef : public PPB_FileRef_Shared { |
scoped_refptr<TrackedCallback> callback) OVERRIDE; |
virtual int32_t Query(PP_FileInfo* info, |
scoped_refptr<TrackedCallback> callback) OVERRIDE; |
+ virtual int32_t ReadEntries(const PP_ArrayOutput& output, |
+ scoped_refptr<TrackedCallback> callback) OVERRIDE; |
+ virtual int32_t ReadEntriesInHost( |
+ std::vector<ppapi::PPB_FileRef_CreateInfo>* files, |
+ std::vector<PP_FileType>* file_types, |
+ scoped_refptr<TrackedCallback> callback) OVERRIDE; |
virtual PP_Var GetAbsolutePath() OVERRIDE; |
// Executes the pending callback with the given ID. See pending_callbacks_. |
void ExecuteCallback(uint32_t callback_id, int32_t result); |
void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); |
+ int32_t SetReadEntriesOutput( |
+ uint32_t callback_id, |
+ const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
+ const std::vector<PP_FileType>& file_types); |
private: |
PluginDispatcher* GetDispatcher() const { |
@@ -82,6 +104,12 @@ class FileRef : public PPB_FileRef_Shared { |
typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; |
PendingFileInfoMap pending_file_infos_; |
+ // Used to keep PP_ArrayOutput instances that are written before callbacks |
+ // are invoked. The id of a pending array output will match that of the |
+ // corresponding callback. |
+ typedef std::map<uint32_t, PP_ArrayOutput> PendingReadEntriesOutputMap; |
+ PendingReadEntriesOutputMap pending_read_entries_outputs_; |
+ |
// Holds a reference on plugin side when running out of process, so that |
// FileSystem won't die before FileRef. See PPB_FileRef_Impl for |
// corresponding code for in-process mode. Note that this workaround will |
@@ -101,12 +129,14 @@ FileRef::~FileRef() { |
// The callbacks map should have been cleared by LastPluginRefWasDeleted. |
DCHECK(pending_callbacks_.empty()); |
DCHECK(pending_file_infos_.empty()); |
+ DCHECK(pending_read_entries_outputs_.empty()); |
} |
void FileRef::LastPluginRefWasDeleted() { |
// The callback tracker will abort our callbacks for us. |
pending_callbacks_.clear(); |
pending_file_infos_.clear(); |
+ pending_read_entries_outputs_.clear(); |
} |
PP_Resource FileRef::GetParent() { |
@@ -163,6 +193,24 @@ int32_t FileRef::Query(PP_FileInfo* info, |
return PP_OK_COMPLETIONPENDING; |
} |
+int32_t FileRef::ReadEntries(const PP_ArrayOutput& output, |
+ scoped_refptr<TrackedCallback> callback) { |
+ // Store the pending read entries output id. |
+ int id = SendCallback(callback); |
+ pending_read_entries_outputs_[id] = output; |
+ GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadEntries( |
+ API_ID_PPB_FILE_REF, host_resource(), id)); |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+int32_t FileRef::ReadEntriesInHost( |
+ std::vector<ppapi::PPB_FileRef_CreateInfo>* files, |
+ std::vector<PP_FileType>* file_types, |
+ scoped_refptr<TrackedCallback> callback) { |
+ NOTREACHED(); |
+ return PP_ERROR_FAILED; |
+} |
+ |
PP_Var FileRef::GetAbsolutePath() { |
ReceiveSerializedVarReturnValue result; |
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( |
@@ -194,6 +242,39 @@ void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { |
pending_file_infos_.erase(found); |
} |
+int32_t FileRef::SetReadEntriesOutput( |
+ uint32_t callback_id, |
+ const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
+ const std::vector<PP_FileType>& file_types) { |
+ PendingReadEntriesOutputMap::iterator found = |
+ pending_read_entries_outputs_.find(callback_id); |
+ if (found == pending_read_entries_outputs_.end()) |
+ return PP_OK; |
+ |
+ PP_ArrayOutput output = found->second; |
+ pending_read_entries_outputs_.erase(found); |
+ |
+ std::vector<PP_DirectoryEntry> entries; |
+ for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; |
+ i < infos.size(); ++i) { |
+ PP_DirectoryEntry entry; |
+ entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); |
+ entry.file_type = file_types[i]; |
+ entries.push_back(entry); |
+ } |
+ |
+ ArrayWriter writer(output); |
+ if (!writer.is_valid()) { |
+ ReleaseEntries(entries); |
+ entries.clear(); |
+ return PP_ERROR_BADARGUMENT; |
+ } |
+ |
+ writer.StoreVector(entries); |
+ entries.clear(); |
+ return PP_OK; |
+} |
+ |
uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { |
// In extreme cases the IDs may wrap around, so avoid duplicates. |
while (pending_callbacks_.count(next_callback_id_)) |
@@ -234,6 +315,7 @@ bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { |
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_ReadEntries, OnMsgReadEntries) |
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, |
OnMsgGetAbsolutePath) |
#endif // !defined(OS_NACL) |
@@ -242,6 +324,8 @@ bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { |
OnMsgCallbackComplete) |
IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, |
OnMsgQueryCallbackComplete) |
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_ReadEntriesCallbackComplete, |
+ OnMsgReadEntriesCallbackComplete) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -349,6 +433,23 @@ void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, |
if (enter.succeeded()) |
result.Return(dispatcher(), enter.object()->GetAbsolutePath()); |
} |
+ |
+void PPB_FileRef_Proxy::OnMsgReadEntries(const HostResource& file_ref, |
+ uint32_t callback_id) { |
+ std::vector<ppapi::PPB_FileRef_CreateInfo>* files = |
+ new std::vector<ppapi::PPB_FileRef_CreateInfo>(); |
+ std::vector<PP_FileType>* file_types = new std::vector<PP_FileType>(); |
+ HostCallbackParams* params = new HostCallbackParams(file_ref, callback_id); |
+ EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( |
+ file_ref, callback_factory_, |
+ &PPB_FileRef_Proxy::OnReadEntriesCallbackCompleteInHost, |
+ base::Owned(params), base::Owned(files), base::Owned(file_types)); |
+ if (enter.succeeded()) { |
+ enter.SetResult(enter.object()->ReadEntriesInHost(files, file_types, |
+ enter.callback())); |
+ } |
+} |
+ |
#endif // !defined(OS_NACL) |
void PPB_FileRef_Proxy::OnMsgCallbackComplete( |
@@ -374,6 +475,26 @@ void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( |
} |
} |
+void PPB_FileRef_Proxy::OnMsgReadEntriesCallbackComplete( |
+ const HostResource& host_resource, |
+ const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, |
+ const std::vector<PP_FileType>& file_types, |
+ uint32_t callback_id, |
+ int32_t result) { |
+ CHECK_EQ(infos.size(), file_types.size()); |
+ |
+ EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); |
+ if (enter.succeeded()) { |
+ 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.
|
+ static_cast<FileRef*>(enter.object())->SetReadEntriesOutput( |
+ callback_id, infos, file_types); |
+ if (set_result != PP_OK) |
+ result = set_result; |
+ static_cast<FileRef*>(enter.object())->ExecuteCallback( |
+ callback_id, result); |
+ } |
+} |
+ |
#if !defined(OS_NACL) |
void PPB_FileRef_Proxy::OnCallbackCompleteInHost( |
int32_t result, |
@@ -392,6 +513,18 @@ void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( |
Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( |
API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); |
} |
+ |
+void PPB_FileRef_Proxy::OnReadEntriesCallbackCompleteInHost( |
+ int32_t result, |
+ 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.
|
+ base::internal::OwnedWrapper< |
+ std::vector<ppapi::PPB_FileRef_CreateInfo> > files, |
+ 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
|
+ Send(new PpapiMsg_PPBFileRef_ReadEntriesCallbackComplete( |
+ API_ID_PPB_FILE_REF, params.get()->host_resource, |
+ *files.get(), *file_types.get(), params.get()->callback_id, result)); |
+} |
+ |
#endif // !defined(OS_NACL) |
} // namespace proxy |