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