Index: ppapi/proxy/directory_reader_resource.cc |
diff --git a/ppapi/proxy/directory_reader_resource.cc b/ppapi/proxy/directory_reader_resource.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7bdfa75ce28906d2de48f21cbe114de77df8cecb |
--- /dev/null |
+++ b/ppapi/proxy/directory_reader_resource.cc |
@@ -0,0 +1,104 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ppapi/proxy/directory_reader_resource.h" |
+ |
+#include "base/bind.h" |
+#include "ipc/ipc_message.h" |
+#include "ppapi/c/pp_errors.h" |
+#include "ppapi/proxy/dispatch_reply_message.h" |
+#include "ppapi/proxy/plugin_globals.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/proxy/ppb_file_ref_proxy.h" |
+#include "ppapi/shared_impl/ppapi_globals.h" |
+#include "ppapi/shared_impl/resource.h" |
+#include "ppapi/shared_impl/resource_tracker.h" |
+#include "ppapi/thunk/enter.h" |
+#include "ppapi/thunk/ppb_file_ref_api.h" |
+ |
+using ppapi::proxy::PPB_FileRef_Proxy; |
+ |
+namespace ppapi { |
+namespace proxy { |
+ |
+DirectoryReaderResource::DirectoryReaderResource( |
+ Connection connection, |
+ PP_Instance instance, |
+ PP_Resource directory_ref) |
+ : PluginResource(connection, instance), |
+ directory_ref_(directory_ref), |
+ has_more_(true) {} |
yzshen1
2013/01/24 21:55:43
please init |entry_|.
nhiroki
2013/01/25 12:27:17
Done.
|
+ |
+thunk::PPB_DirectoryReader_API* |
+DirectoryReaderResource::AsPPB_DirectoryReader_API() { |
+ return this; |
+} |
+ |
+int32_t DirectoryReaderResource::GetNextEntry( |
+ PP_DirectoryEntry_Dev* entry, |
+ scoped_refptr<TrackedCallback> callback) { |
+ if (TrackedCallback::IsPending(callback_)) |
+ return PP_ERROR_INPROGRESS; |
+ |
+ entry_ = entry; |
+ callback_ = callback; |
+ |
+ if (FillUpEntry()) |
+ return PP_OK; |
+ |
+ if (!sent_create_to_renderer()) |
+ SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create()); |
+ |
+ ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); |
+ PpapiHostMsg_DirectoryReader_GetNextEntry msg( |
+ tracker->GetResource(directory_ref_)->host_resource()); |
+ Call<PpapiPluginMsg_DirectoryReader_GetNextEntryReply>( |
+ RENDERER, msg, |
+ base::Bind(&DirectoryReaderResource::OnPluginMsgGetNextEntryReply, this)); |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+void DirectoryReaderResource::OnPluginMsgGetNextEntryReply( |
+ const ResourceMessageReplyParams& params, |
+ const std::vector<ppapi::PPB_FileRef_CreateInfo> infos, |
+ const std::vector<PP_FileType> file_types) { |
+ DCHECK_EQ(infos.size(), file_types.size()); |
yzshen1
2013/01/24 21:55:43
Please make it a CHECK. Something must be really w
nhiroki
2013/01/25 12:27:17
Done.
|
+ |
+ for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; |
+ i < infos.size(); ++i) { |
+ PP_DirectoryEntry_Dev entry; |
+ entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); |
yzshen1
2013/01/24 21:55:43
Where do you release the ref? If the ref is not re
nhiroki
2013/01/25 12:27:17
Added release routine into the dtor.
|
+ entry.file_type = file_types[i]; |
+ entries_.push(entry); |
+ } |
+ |
+ // Current implementation returns all entries at once. |
+ // TODO(nhiroki): DirectoryReader should return directory entries in multiple |
+ // chunks. |
+ has_more_ = false; |
+ |
+ FillUpEntry(); |
yzshen1
2013/01/24 21:55:43
[optional]
Please check that callback_ is still pe
nhiroki
2013/01/25 12:27:17
Done.
|
+ entry_ = NULL; |
+ |
+ callback_->Run(params.result()); |
+} |
+ |
+bool DirectoryReaderResource::FillUpEntry() { |
+ DCHECK(entry_); |
+ if (!entries_.empty()) { |
+ *entry_ = entries_.front(); |
+ entries_.pop(); |
+ return true; |
+ } |
+ |
+ if (!has_more_) { |
+ entry_->file_ref = 0; |
yzshen1
2013/01/24 21:55:43
Please also init the other field in |entry_|.
nhiroki
2013/01/25 12:27:17
Done.
|
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
+} // namespace proxy |
+} // namespace ppapi |