Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Unified Diff: ppapi/proxy/directory_reader_resource.cc

Issue 11958033: Implement Pepper proxy for PPB_DirectoryReader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test failure Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7fff3030051fe03468353cd410b7488821217e41
--- /dev/null
+++ b/ppapi/proxy/directory_reader_resource.cc
@@ -0,0 +1,113 @@
+// 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/ppapi_messages.h"
+#include "ppapi/proxy/ppb_file_ref_proxy.h"
+#include "ppapi/shared_impl/ppapi_globals.h"
+#include "ppapi/shared_impl/resource_tracker.h"
+#include "ppapi/shared_impl/tracked_callback.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),
+ output_(NULL),
+ has_more_(true) {
+ directory_resource_ =
+ PpapiGlobals::Get()->GetResourceTracker()->GetResource(directory_ref);
+}
+
+DirectoryReaderResource::~DirectoryReaderResource() {
+}
+
+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;
+
+ output_ = entry;
+ callback_ = callback;
+
+ if (FillUpEntry())
+ return PP_OK;
+
+ if (!sent_create_to_renderer())
+ SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create());
+
+ PpapiHostMsg_DirectoryReader_GetEntries msg(
+ directory_resource_->host_resource());
+ Call<PpapiPluginMsg_DirectoryReader_GetEntriesReply>(
+ RENDERER, msg,
+ base::Bind(&DirectoryReaderResource::OnPluginMsgGetEntriesReply, this));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void DirectoryReaderResource::OnPluginMsgGetEntriesReply(
+ const ResourceMessageReplyParams& params,
+ const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos,
+ const std::vector<PP_FileType>& file_types) {
+ CHECK_EQ(infos.size(), file_types.size());
+
+ ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
+ for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0;
+ i < infos.size(); ++i) {
+ DirectoryEntry entry;
+ entry.file_resource =
+ tracker->GetResource(PPB_FileRef_Proxy::DeserializeFileRef(infos[i]));
+ entry.file_type = file_types[i];
+ entries_.push(entry);
+ }
+ has_more_ = false;
+
+ if (!TrackedCallback::IsPending(callback_))
+ return;
+
+ FillUpEntry();
+ callback_->Run(params.result());
+}
+
+bool DirectoryReaderResource::FillUpEntry() {
+ DCHECK(output_);
+
+ if (!entries_.empty()) {
+ DirectoryEntry entry = entries_.front();
+ entries_.pop();
+ output_->file_ref = entry.file_resource->pp_resource();
+ output_->file_type = entry.file_type;
+ output_ = NULL;
+ return true;
+ }
+
+ if (!has_more_) {
+ output_->file_ref = 0;
+ output_->file_type = PP_FILETYPE_OTHER;
+ output_ = NULL;
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace proxy
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698