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