Chromium Code Reviews| Index: content/browser/file_descriptor_info_impl.cc |
| diff --git a/content/browser/file_descriptor_info_impl.cc b/content/browser/file_descriptor_info_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e05ec43efa148788c602333c771a6d02bbf6e8ae |
| --- /dev/null |
| +++ b/content/browser/file_descriptor_info_impl.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2012 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 "content/browser/file_descriptor_info_impl.h" |
| + |
| +namespace content { |
| + |
| +// static |
| +scoped_ptr<FileDescriptorInfo> FileDescriptorInfoImpl::Create() { |
| + return scoped_ptr<FileDescriptorInfo>(new FileDescriptorInfoImpl()); |
| +} |
| + |
| +FileDescriptorInfoImpl::FileDescriptorInfoImpl() { |
| +} |
| + |
| +FileDescriptorInfoImpl::~FileDescriptorInfoImpl() { |
| +} |
| + |
| +void FileDescriptorInfoImpl::Share(int id, base::PlatformFile fd) { |
| + AddToMapping(id, fd); |
| +} |
| + |
| +void FileDescriptorInfoImpl::Transfer(int id, base::ScopedFD fd) { |
| + AddToMapping(id, fd.get()); |
| + owned_descriptors_.push_back(new base::ScopedFD(fd.Pass())); |
| +} |
| + |
| +void FileDescriptorInfoImpl::TransferWithoutMapping(base::ScopedFD fd) { |
| + owned_descriptors_.push_back(new base::ScopedFD(fd.Pass())); |
| +} |
| + |
| +base::PlatformFile FileDescriptorInfoImpl::GetFDAt(size_t i) const { |
| + return mapping_[i].first; |
| +} |
| + |
| +int FileDescriptorInfoImpl::GetIDAt(size_t i) const { |
| + return mapping_[i].second; |
| +} |
| + |
| +size_t FileDescriptorInfoImpl::GetMappingSize() const { |
| + return mapping_.size(); |
| +} |
| + |
| +void FileDescriptorInfoImpl::AddToMapping(int id, base::PlatformFile fd) { |
| + DCHECK(mapping_.end() == |
|
mdempsky
2014/09/24 21:16:44
I still suspect that we should be checking for dup
Hajime Morrita
2014/09/24 23:08:56
Done.
|
| + std::find(mapping_.begin(), mapping_.end(), std::make_pair(fd, id))); |
| + mapping_.push_back(std::make_pair(fd, id)); |
| +} |
| + |
| +const base::FileHandleMappingVector& FileDescriptorInfoImpl::GetMapping() |
| + const { |
| + return mapping_; |
| +} |
| + |
| +base::FileHandleMappingVector |
| +FileDescriptorInfoImpl::GetMappingWithIDAdjustment(int delta) const { |
| + base::FileHandleMappingVector result = mapping_; |
| + // Adding delta to each ID. |
| + for (unsigned i = 0; i < mapping_.size(); ++i) |
| + result[i].second += delta; |
| + return result; |
| +} |
| + |
| +} // namespace content |