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 "base/file_descriptor_posix.h" | 8 #include "base/files/file.h" |
9 #include "base/memory/scoped_vector.h" | |
10 #include "base/process/launch.h" | |
11 #include "content/common/content_export.h" | |
9 | 12 |
10 namespace content { | 13 namespace content { |
11 | 14 |
12 // This struct is used when passing files that should be mapped in a process | 15 // FileDescriptorInfo is a collection of file descriptors which is |
jam
2014/09/23 05:16:09
this doesn't conform to the content api http://www
| |
13 // that is been created and allows to associate that file with a specific ID. | 16 // needed to launch a process. You should to tell FileDescriptorInfo |
14 // It also provides a way to know if the actual file descriptor should be | 17 // which FD should be closed and which isn't so that it can take care |
15 // closed with the FileDescriptor.auto_close field. | 18 // of the lifetime of FDs. |
19 // | |
20 // See base/process/launcher.h for more details about launching a | |
21 // process. | |
22 class CONTENT_EXPORT FileDescriptorInfo { | |
23 public: | |
24 FileDescriptorInfo(); | |
25 ~FileDescriptorInfo(); | |
16 | 26 |
17 struct FileDescriptorInfo { | 27 // Add and FD associated with an ID, without delegating the ownerhip |
18 FileDescriptorInfo(int id, const base::FileDescriptor& file_descriptor) | 28 // of ID. |
19 : id(id), | 29 void Share(int id, base::PlatformFile fd); |
20 fd(file_descriptor) { | 30 // Add an FD associated with an ID, passing the FD ownership to |
21 } | 31 // FileDescriptorInfo. |
32 void Transfer(int id, base::ScopedFD fd); | |
33 // Just delegating a lifetime of an FD. This is needed as some FDs | |
34 // are transferred to another process without key mapping. | |
35 void TransferWithoutMapping(base::ScopedFD fd); | |
36 // A vecotr-backed map from registered ID-FD pair. | |
37 const base::FileHandleMappingVector& GetMapping() const; | |
38 // A GetMapping() variant what adjusts the ID value by |delta|. | |
39 // Some environments need this trick. | |
40 base::FileHandleMappingVector GetMappingWithIDAdjustment(int delta) const; | |
22 | 41 |
23 int id; | 42 // API for iterating registerd ID-FD pair. |
24 base::FileDescriptor fd; | 43 base::PlatformFile GetFDAt(size_t i) const; |
44 int GetIDAt(size_t i) const; | |
45 size_t GetMappingSize() const { return mapping_.size(); } | |
46 | |
47 private: | |
48 void AddToMapping(int id, base::PlatformFile fd); | |
49 | |
50 base::FileHandleMappingVector mapping_; | |
51 ScopedVector<base::ScopedFD> owned_descriptors_; | |
25 }; | 52 }; |
26 | 53 |
27 } | 54 } |
28 | 55 |
29 #endif // CONTENT_PUBLIC_BROWSER_FILE_DESCRIPTOR_INFO_H_ | 56 #endif // CONTENT_PUBLIC_BROWSER_FILE_DESCRIPTOR_INFO_H_ |
OLD | NEW |