| 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 #ifndef CONTENT_PUBLIC_BROWSER_FILE_DESCRIPTOR_INFO_H_ | |
| 6 #define CONTENT_PUBLIC_BROWSER_FILE_DESCRIPTOR_INFO_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "base/files/file.h" | |
| 13 #include "base/files/memory_mapped_file.h" | |
| 14 #include "base/process/launch.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 // FileDescriptorInfo is a collection of file descriptors which is needed to | |
| 19 // launch a process. You should tell FileDescriptorInfo which FDs should be | |
| 20 // closed and which shouldn't so that it can take care of the lifetime of FDs. | |
| 21 // | |
| 22 // See base/process/launcher.h for more details about launching a process. | |
| 23 class FileDescriptorInfo { | |
| 24 public: | |
| 25 virtual ~FileDescriptorInfo() {} | |
| 26 | |
| 27 // Adds an FD associated with an ID, without delegating the ownerhip of ID. | |
| 28 virtual void Share(int id, base::PlatformFile fd) = 0; | |
| 29 | |
| 30 // Similar to Share but also provides a region in that file that should be | |
| 31 // read in the launched process (accessible with GetRegionAt()). | |
| 32 virtual void ShareWithRegion( | |
| 33 int id, | |
| 34 base::PlatformFile fd, | |
| 35 const base::MemoryMappedFile::Region& region) = 0; | |
| 36 | |
| 37 // Adds an FD associated with an ID, passing the FD ownership to | |
| 38 // FileDescriptorInfo. | |
| 39 virtual void Transfer(int id, base::ScopedFD fd) = 0; | |
| 40 | |
| 41 // A vector backed map of registered ID-FD pairs. | |
| 42 virtual const base::FileHandleMappingVector& GetMapping() const = 0; | |
| 43 | |
| 44 // A GetMapping() variant that adjusts the ID value by |delta|. | |
| 45 // Some environments need this trick. | |
| 46 virtual std::unique_ptr<base::FileHandleMappingVector> | |
| 47 GetMappingWithIDAdjustment(int delta) const = 0; | |
| 48 | |
| 49 // API for iterating over the registered ID-FD pairs. | |
| 50 virtual base::PlatformFile GetFDAt(size_t i) const = 0; | |
| 51 virtual int GetIDAt(size_t i) const = 0; | |
| 52 virtual const base::MemoryMappedFile::Region& GetRegionAt(size_t i) const = 0; | |
| 53 virtual size_t GetMappingSize() const = 0; | |
| 54 | |
| 55 // Returns true if |this| has ownership of |file|. | |
| 56 virtual bool OwnsFD(base::PlatformFile file) const = 0; | |
| 57 // Assuming |OwnsFD(file)|, releases the ownership. | |
| 58 virtual base::ScopedFD ReleaseFD(base::PlatformFile file) = 0; | |
| 59 }; | |
| 60 | |
| 61 } | |
| 62 | |
| 63 #endif // CONTENT_PUBLIC_BROWSER_FILE_DESCRIPTOR_INFO_H_ | |
| OLD | NEW |