Chromium Code Reviews| 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 DirectoryReaderResource::DirectoryReaderResource( | |
| 25 Connection connection, | |
| 26 PP_Instance instance, | |
| 27 PP_Resource directory_ref) | |
| 28 : PluginResource(connection, instance), | |
| 29 output_(NULL), | |
| 30 has_more_(true) { | |
| 31 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); | |
| 32 directory_resource_ = tracker->GetResource(directory_ref); | |
| 33 tracker->AddRefResource(directory_ref); | |
|
yzshen1
2013/02/01 23:57:47
You don't have to add a PP_Resource ref, now that
nhiroki
2013/02/02 05:14:58
Done.
| |
| 34 } | |
| 35 | |
| 36 DirectoryReaderResource::~DirectoryReaderResource() { | |
| 37 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); | |
| 38 // Release resources which have not been fetched by the plugin. | |
| 39 while (!entries_.empty()) { | |
| 40 tracker->ReleaseResource(entries_.front().file_resource->pp_resource()); | |
| 41 entries_.pop(); | |
| 42 } | |
| 43 tracker->ReleaseResource(directory_resource_->pp_resource()); | |
| 44 } | |
| 45 | |
| 46 thunk::PPB_DirectoryReader_API* | |
| 47 DirectoryReaderResource::AsPPB_DirectoryReader_API() { | |
| 48 return this; | |
| 49 } | |
| 50 | |
| 51 int32_t DirectoryReaderResource::GetNextEntry( | |
| 52 PP_DirectoryEntry_Dev* entry, | |
| 53 scoped_refptr<TrackedCallback> callback) { | |
| 54 if (TrackedCallback::IsPending(callback_)) | |
| 55 return PP_ERROR_INPROGRESS; | |
| 56 | |
| 57 output_ = entry; | |
| 58 callback_ = callback; | |
| 59 | |
| 60 if (FillUpEntry()) | |
| 61 return PP_OK; | |
| 62 | |
| 63 if (!sent_create_to_renderer()) | |
| 64 SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create()); | |
| 65 | |
| 66 PpapiHostMsg_DirectoryReader_GetEntries msg( | |
| 67 directory_resource_->host_resource()); | |
| 68 Call<PpapiPluginMsg_DirectoryReader_GetEntriesReply>( | |
| 69 RENDERER, msg, | |
| 70 base::Bind(&DirectoryReaderResource::OnPluginMsgGetEntriesReply, this)); | |
| 71 return PP_OK_COMPLETIONPENDING; | |
| 72 } | |
| 73 | |
| 74 void DirectoryReaderResource::OnPluginMsgGetEntriesReply( | |
| 75 const ResourceMessageReplyParams& params, | |
| 76 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, | |
| 77 const std::vector<PP_FileType>& file_types) { | |
| 78 CHECK_EQ(infos.size(), file_types.size()); | |
| 79 | |
| 80 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); | |
| 81 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; | |
| 82 i < infos.size(); ++i) { | |
| 83 DirectoryEntry entry; | |
| 84 entry.file_resource = | |
|
yzshen1
2013/02/01 23:57:47
It seems better to use ScopedPPResource here, beca
nhiroki
2013/02/02 05:14:58
Done.
| |
| 85 tracker->GetResource(PPB_FileRef_Proxy::DeserializeFileRef(infos[i])); | |
| 86 entry.file_type = file_types[i]; | |
| 87 entries_.push(entry); | |
| 88 } | |
| 89 has_more_ = false; | |
| 90 | |
| 91 if (!TrackedCallback::IsPending(callback_)) | |
| 92 return; | |
| 93 | |
| 94 FillUpEntry(); | |
| 95 callback_->Run(params.result()); | |
| 96 } | |
| 97 | |
| 98 bool DirectoryReaderResource::FillUpEntry() { | |
| 99 DCHECK(output_); | |
| 100 | |
| 101 if (!entries_.empty()) { | |
| 102 DirectoryEntry entry = entries_.front(); | |
| 103 entries_.pop(); | |
| 104 output_->file_ref = entry.file_resource->pp_resource(); | |
| 105 output_->file_type = entry.file_type; | |
| 106 output_ = NULL; | |
| 107 return true; | |
| 108 } | |
| 109 | |
| 110 if (!has_more_) { | |
| 111 output_->file_ref = 0; | |
| 112 output_->file_type = PP_FILETYPE_OTHER; | |
| 113 output_ = NULL; | |
| 114 return true; | |
| 115 } | |
| 116 | |
| 117 return false; | |
| 118 } | |
| 119 | |
| 120 } // namespace proxy | |
| 121 } // namespace ppapi | |
| OLD | NEW |