| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/file_descriptor_info_impl.h" | 5 #include "content/browser/file_descriptor_info_impl.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace content { |
| 8 | 8 |
| 9 // static | 9 // static |
| 10 scoped_ptr<FileDescriptorInfo> FileDescriptorInfoImpl::Create() { | 10 scoped_ptr<FileDescriptorInfo> FileDescriptorInfoImpl::Create() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 bool FileDescriptorInfoImpl::HasID(int id) const { | 41 bool FileDescriptorInfoImpl::HasID(int id) const { |
| 42 for (unsigned i = 0; i < mapping_.size(); ++i) { | 42 for (unsigned i = 0; i < mapping_.size(); ++i) { |
| 43 if (mapping_[i].second == id) | 43 if (mapping_[i].second == id) |
| 44 return true; | 44 return true; |
| 45 } | 45 } |
| 46 | 46 |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool FileDescriptorInfoImpl::OwnsFD(base::PlatformFile file) const { |
| 51 return owned_descriptors_.end() != |
| 52 std::find_if( |
| 53 owned_descriptors_.begin(), owned_descriptors_.end(), |
| 54 [file](const base::ScopedFD* fd) { return fd->get() == file; }); |
| 55 } |
| 56 |
| 57 base::ScopedFD FileDescriptorInfoImpl::ReleaseFD(base::PlatformFile file) { |
| 58 DCHECK(OwnsFD(file)); |
| 59 |
| 60 base::ScopedFD fd; |
| 61 auto found = std::find_if( |
| 62 owned_descriptors_.begin(), owned_descriptors_.end(), |
| 63 [file](const base::ScopedFD* fd) { return fd->get() == file; }); |
| 64 |
| 65 (*found)->swap(fd); |
| 66 owned_descriptors_.erase(found); |
| 67 |
| 68 return fd.Pass(); |
| 69 } |
| 70 |
| 50 void FileDescriptorInfoImpl::AddToMapping(int id, base::PlatformFile fd) { | 71 void FileDescriptorInfoImpl::AddToMapping(int id, base::PlatformFile fd) { |
| 51 DCHECK(!HasID(id)); | 72 DCHECK(!HasID(id)); |
| 52 mapping_.push_back(std::make_pair(fd, id)); | 73 mapping_.push_back(std::make_pair(fd, id)); |
| 53 } | 74 } |
| 54 | 75 |
| 55 const base::FileHandleMappingVector& FileDescriptorInfoImpl::GetMapping() | 76 const base::FileHandleMappingVector& FileDescriptorInfoImpl::GetMapping() |
| 56 const { | 77 const { |
| 57 return mapping_; | 78 return mapping_; |
| 58 } | 79 } |
| 59 | 80 |
| 60 base::FileHandleMappingVector | 81 base::FileHandleMappingVector |
| 61 FileDescriptorInfoImpl::GetMappingWithIDAdjustment(int delta) const { | 82 FileDescriptorInfoImpl::GetMappingWithIDAdjustment(int delta) const { |
| 62 base::FileHandleMappingVector result = mapping_; | 83 base::FileHandleMappingVector result = mapping_; |
| 63 // Adding delta to each ID. | 84 // Adding delta to each ID. |
| 64 for (unsigned i = 0; i < mapping_.size(); ++i) | 85 for (unsigned i = 0; i < mapping_.size(); ++i) |
| 65 result[i].second += delta; | 86 result[i].second += delta; |
| 66 return result; | 87 return result; |
| 67 } | 88 } |
| 68 | 89 |
| 69 } // namespace content | 90 } // namespace content |
| OLD | NEW |