summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/directory_entry.cc
diff options
context:
space:
mode:
authorhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-03 21:51:46 +0000
committerhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-03 21:51:46 +0000
commit2dea98eb8c10879742d8e49988a416b5a7c30cdb (patch)
tree78755572dafee446a60d08de8828d4902251fd78 /ppapi/cpp/directory_entry.cc
parent222c700ea36f0d0de88c9f075363387c51ee117b (diff)
downloadchromium_src-2dea98eb8c10879742d8e49988a416b5a7c30cdb.zip
chromium_src-2dea98eb8c10879742d8e49988a416b5a7c30cdb.tar.gz
chromium_src-2dea98eb8c10879742d8e49988a416b5a7c30cdb.tar.bz2
Move DirectoryReader::ReadEntries to FileRef::ReadDirectoryEntries
This also means this API becomes a stable API. While DirectoryReader was using the new pepper proxy API, FileRef is using the old one. As updating FileRef would take some time, the implementation of ReadEntries is converted from the new design to the old one for now. BUG=234513 TEST=browser_tests R=avi@chromium.org, binji@chromium.org, dmichael@chromium.org, palmer@chromium.org, raymes@chromium.org, teravest@chromium.org Review URL: https://codereview.chromium.org/14784002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp/directory_entry.cc')
-rw-r--r--ppapi/cpp/directory_entry.cc76
1 files changed, 76 insertions, 0 deletions
diff --git a/ppapi/cpp/directory_entry.cc b/ppapi/cpp/directory_entry.cc
new file mode 100644
index 0000000..c8e2b9d
--- /dev/null
+++ b/ppapi/cpp/directory_entry.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2010 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/cpp/directory_entry.h"
+
+#include <string.h>
+
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/module.h"
+
+namespace pp {
+
+DirectoryEntry::DirectoryEntry() {
+ memset(&data_, 0, sizeof(data_));
+}
+
+DirectoryEntry::DirectoryEntry(
+ PassRef, const PP_DirectoryEntry& data) {
+ data_.file_ref = data.file_ref;
+ data_.file_type = data.file_type;
+}
+
+DirectoryEntry::DirectoryEntry(const DirectoryEntry& other) {
+ data_.file_ref = other.data_.file_ref;
+ data_.file_type = other.data_.file_type;
+ if (data_.file_ref)
+ Module::Get()->core()->AddRefResource(data_.file_ref);
+}
+
+DirectoryEntry::~DirectoryEntry() {
+ if (data_.file_ref)
+ Module::Get()->core()->ReleaseResource(data_.file_ref);
+}
+
+DirectoryEntry& DirectoryEntry::operator=(
+ const DirectoryEntry& other) {
+ if (data_.file_ref)
+ Module::Get()->core()->ReleaseResource(data_.file_ref);
+ data_ = other.data_;
+ if (data_.file_ref)
+ Module::Get()->core()->AddRefResource(data_.file_ref);
+ return *this;
+}
+
+namespace internal {
+
+DirectoryEntryArrayOutputAdapterWithStorage::
+ DirectoryEntryArrayOutputAdapterWithStorage() {
+ set_output(&temp_storage_);
+}
+
+DirectoryEntryArrayOutputAdapterWithStorage::
+ ~DirectoryEntryArrayOutputAdapterWithStorage() {
+ if (!temp_storage_.empty()) {
+ // An easy way to release the resource references held by |temp_storage_|.
+ // A destructor for PP_DirectoryEntry will release them.
+ output();
+ }
+}
+
+std::vector<DirectoryEntry>&
+ DirectoryEntryArrayOutputAdapterWithStorage::output() {
+ PP_DCHECK(output_storage_.empty());
+ typedef std::vector<PP_DirectoryEntry> Entries;
+ for (Entries::iterator it = temp_storage_.begin();
+ it != temp_storage_.end();
+ ++it) {
+ output_storage_.push_back(DirectoryEntry(PASS_REF, *it));
+ }
+ temp_storage_.clear();
+ return output_storage_;
+}
+
+} // namespace internal
+} // namespace pp