Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "content/browser/file_descriptor_info_impl.h" | |
| 6 | |
| 7 namespace content { | |
| 8 | |
| 9 // static | |
| 10 scoped_ptr<FileDescriptorInfo> FileDescriptorInfoImpl::Create() { | |
| 11 return scoped_ptr<FileDescriptorInfo>(new FileDescriptorInfoImpl()); | |
| 12 } | |
| 13 | |
| 14 FileDescriptorInfoImpl::FileDescriptorInfoImpl() { | |
| 15 } | |
| 16 | |
| 17 FileDescriptorInfoImpl::~FileDescriptorInfoImpl() { | |
| 18 } | |
| 19 | |
| 20 void FileDescriptorInfoImpl::Share(int id, base::PlatformFile fd) { | |
| 21 AddToMapping(id, fd); | |
| 22 } | |
| 23 | |
| 24 void FileDescriptorInfoImpl::Transfer(int id, base::ScopedFD fd) { | |
| 25 AddToMapping(id, fd.get()); | |
| 26 owned_descriptors_.push_back(new base::ScopedFD(fd.Pass())); | |
| 27 } | |
| 28 | |
| 29 void FileDescriptorInfoImpl::TransferWithoutMapping(base::ScopedFD fd) { | |
| 30 owned_descriptors_.push_back(new base::ScopedFD(fd.Pass())); | |
| 31 } | |
| 32 | |
| 33 base::PlatformFile FileDescriptorInfoImpl::GetFDAt(size_t i) const { | |
| 34 return mapping_[i].first; | |
| 35 } | |
| 36 | |
| 37 int FileDescriptorInfoImpl::GetIDAt(size_t i) const { | |
| 38 return mapping_[i].second; | |
| 39 } | |
| 40 | |
| 41 size_t FileDescriptorInfoImpl::GetMappingSize() const { | |
| 42 return mapping_.size(); | |
| 43 } | |
| 44 | |
| 45 void FileDescriptorInfoImpl::AddToMapping(int id, base::PlatformFile fd) { | |
| 46 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.
| |
| 47 std::find(mapping_.begin(), mapping_.end(), std::make_pair(fd, id))); | |
| 48 mapping_.push_back(std::make_pair(fd, id)); | |
| 49 } | |
| 50 | |
| 51 const base::FileHandleMappingVector& FileDescriptorInfoImpl::GetMapping() | |
| 52 const { | |
| 53 return mapping_; | |
| 54 } | |
| 55 | |
| 56 base::FileHandleMappingVector | |
| 57 FileDescriptorInfoImpl::GetMappingWithIDAdjustment(int delta) const { | |
| 58 base::FileHandleMappingVector result = mapping_; | |
| 59 // Adding delta to each ID. | |
| 60 for (unsigned i = 0; i < mapping_.size(); ++i) | |
| 61 result[i].second += delta; | |
| 62 return result; | |
| 63 } | |
| 64 | |
| 65 } // namespace content | |
| OLD | NEW |