1 // Copyright (c) 2010 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.
5 #include "ppapi/cpp/directory_entry.h"
9 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module.h"
14 DirectoryEntry::DirectoryEntry() {
15 memset(&data_
, 0, sizeof(data_
));
18 DirectoryEntry::DirectoryEntry(
19 PassRef
, const PP_DirectoryEntry
& data
) {
20 data_
.file_ref
= data
.file_ref
;
21 data_
.file_type
= data
.file_type
;
24 DirectoryEntry::DirectoryEntry(const DirectoryEntry
& other
) {
25 data_
.file_ref
= other
.data_
.file_ref
;
26 data_
.file_type
= other
.data_
.file_type
;
28 Module::Get()->core()->AddRefResource(data_
.file_ref
);
31 DirectoryEntry::~DirectoryEntry() {
33 Module::Get()->core()->ReleaseResource(data_
.file_ref
);
36 DirectoryEntry
& DirectoryEntry::operator=(
37 const DirectoryEntry
& other
) {
39 Module::Get()->core()->ReleaseResource(data_
.file_ref
);
42 Module::Get()->core()->AddRefResource(data_
.file_ref
);
48 DirectoryEntryArrayOutputAdapterWithStorage::
49 DirectoryEntryArrayOutputAdapterWithStorage() {
50 set_output(&temp_storage_
);
53 DirectoryEntryArrayOutputAdapterWithStorage::
54 ~DirectoryEntryArrayOutputAdapterWithStorage() {
55 if (!temp_storage_
.empty()) {
56 // An easy way to release the resource references held by |temp_storage_|.
57 // A destructor for PP_DirectoryEntry will release them.
62 std::vector
<DirectoryEntry
>&
63 DirectoryEntryArrayOutputAdapterWithStorage::output() {
64 PP_DCHECK(output_storage_
.empty());
65 typedef std::vector
<PP_DirectoryEntry
> Entries
;
66 for (Entries::iterator it
= temp_storage_
.begin();
67 it
!= temp_storage_
.end();
69 output_storage_
.push_back(DirectoryEntry(PASS_REF
, *it
));
71 temp_storage_
.clear();
72 return output_storage_
;
75 } // namespace internal