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