1 // Copyright (c) 2012 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 "content/browser/file_descriptor_info_impl.h"
10 scoped_ptr
<FileDescriptorInfo
> FileDescriptorInfoImpl::Create() {
11 return scoped_ptr
<FileDescriptorInfo
>(new FileDescriptorInfoImpl());
14 FileDescriptorInfoImpl::FileDescriptorInfoImpl() {
17 FileDescriptorInfoImpl::~FileDescriptorInfoImpl() {
20 void FileDescriptorInfoImpl::Share(int id
, base::PlatformFile fd
) {
24 void FileDescriptorInfoImpl::Transfer(int id
, base::ScopedFD fd
) {
25 AddToMapping(id
, fd
.get());
26 owned_descriptors_
.push_back(new base::ScopedFD(fd
.Pass()));
29 base::PlatformFile
FileDescriptorInfoImpl::GetFDAt(size_t i
) const {
30 return mapping_
[i
].first
;
33 int FileDescriptorInfoImpl::GetIDAt(size_t i
) const {
34 return mapping_
[i
].second
;
37 size_t FileDescriptorInfoImpl::GetMappingSize() const {
38 return mapping_
.size();
41 bool FileDescriptorInfoImpl::HasID(int id
) const {
42 for (unsigned i
= 0; i
< mapping_
.size(); ++i
) {
43 if (mapping_
[i
].second
== id
)
50 void FileDescriptorInfoImpl::AddToMapping(int id
, base::PlatformFile fd
) {
52 mapping_
.push_back(std::make_pair(fd
, id
));
55 const base::FileHandleMappingVector
& FileDescriptorInfoImpl::GetMapping()
60 base::FileHandleMappingVector
61 FileDescriptorInfoImpl::GetMappingWithIDAdjustment(int delta
) const {
62 base::FileHandleMappingVector result
= mapping_
;
63 // Adding delta to each ID.
64 for (unsigned i
= 0; i
< mapping_
.size(); ++i
)
65 result
[i
].second
+= delta
;
69 } // namespace content