| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/proxy/directory_reader_resource.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "ipc/ipc_message.h" | |
| 9 #include "ppapi/c/pp_errors.h" | |
| 10 #include "ppapi/proxy/dispatch_reply_message.h" | |
| 11 #include "ppapi/proxy/ppapi_messages.h" | |
| 12 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
| 13 #include "ppapi/shared_impl/ppapi_globals.h" | |
| 14 #include "ppapi/shared_impl/resource_tracker.h" | |
| 15 #include "ppapi/shared_impl/tracked_callback.h" | |
| 16 #include "ppapi/thunk/enter.h" | |
| 17 #include "ppapi/thunk/ppb_file_ref_api.h" | |
| 18 | |
| 19 using ppapi::proxy::PPB_FileRef_Proxy; | |
| 20 | |
| 21 namespace ppapi { | |
| 22 namespace proxy { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 void ReleaseEntries(const std::vector<PP_DirectoryEntry_Dev>& entries) { | |
| 27 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); | |
| 28 for (std::vector<PP_DirectoryEntry_Dev>::const_iterator it = entries.begin(); | |
| 29 it != entries.end(); ++it) | |
| 30 tracker->ReleaseResource(it->file_ref); | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 DirectoryReaderResource::DirectoryReaderResource( | |
| 36 Connection connection, | |
| 37 PP_Instance instance, | |
| 38 PP_Resource directory_ref) | |
| 39 : PluginResource(connection, instance) { | |
| 40 directory_resource_ = | |
| 41 PpapiGlobals::Get()->GetResourceTracker()->GetResource(directory_ref); | |
| 42 } | |
| 43 | |
| 44 DirectoryReaderResource::~DirectoryReaderResource() { | |
| 45 } | |
| 46 | |
| 47 thunk::PPB_DirectoryReader_API* | |
| 48 DirectoryReaderResource::AsPPB_DirectoryReader_API() { | |
| 49 return this; | |
| 50 } | |
| 51 | |
| 52 int32_t DirectoryReaderResource::ReadEntries( | |
| 53 const PP_ArrayOutput& output, | |
| 54 scoped_refptr<TrackedCallback> callback) { | |
| 55 if (TrackedCallback::IsPending(callback_)) | |
| 56 return PP_ERROR_INPROGRESS; | |
| 57 | |
| 58 callback_ = callback; | |
| 59 | |
| 60 if (!sent_create_to_renderer()) | |
| 61 SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create()); | |
| 62 | |
| 63 PpapiHostMsg_DirectoryReader_GetEntries msg( | |
| 64 directory_resource_->host_resource()); | |
| 65 Call<PpapiPluginMsg_DirectoryReader_GetEntriesReply>( | |
| 66 RENDERER, msg, | |
| 67 base::Bind(&DirectoryReaderResource::OnPluginMsgGetEntriesReply, | |
| 68 this, output)); | |
| 69 return PP_OK_COMPLETIONPENDING; | |
| 70 } | |
| 71 | |
| 72 void DirectoryReaderResource::OnPluginMsgGetEntriesReply( | |
| 73 const PP_ArrayOutput& output, | |
| 74 const ResourceMessageReplyParams& params, | |
| 75 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, | |
| 76 const std::vector<PP_FileType>& file_types) { | |
| 77 CHECK_EQ(infos.size(), file_types.size()); | |
| 78 | |
| 79 std::vector<PP_DirectoryEntry_Dev> entries; | |
| 80 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; | |
| 81 i < infos.size(); ++i) { | |
| 82 PP_DirectoryEntry_Dev entry; | |
| 83 entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); | |
| 84 entry.file_type = file_types[i]; | |
| 85 entries.push_back(entry); | |
| 86 } | |
| 87 | |
| 88 if (!TrackedCallback::IsPending(callback_)) { | |
| 89 ReleaseEntries(entries); | |
| 90 entries.clear(); | |
| 91 return; | |
| 92 } | |
| 93 | |
| 94 ArrayWriter writer(output); | |
| 95 if (!writer.is_valid()) { | |
| 96 ReleaseEntries(entries); | |
| 97 entries.clear(); | |
| 98 callback_->Run(PP_ERROR_FAILED); | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 writer.StoreVector(entries); | |
| 103 entries.clear(); | |
| 104 callback_->Run(params.result()); | |
| 105 } | |
| 106 | |
| 107 } // namespace proxy | |
| 108 } // namespace ppapi | |
| OLD | NEW |