OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 BASE_FILE_DESCRIPTOR_STORE_H_ | |
6 #define BASE_FILE_DESCRIPTOR_STORE_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <vector> | |
11 | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
include <string>
Jay Civelli
2017/02/09 22:08:26
Done.
| |
12 #include "base/files/memory_mapped_file.h" | |
13 #include "base/memory/singleton.h" | |
14 | |
15 namespace base { | |
16 | |
17 // The file descriptor store is used to associate file descriptors with keys | |
18 // that must be unique. | |
19 // It is used to share file descriptors from a process to its child. | |
20 class BASE_EXPORT FileDescriptorStore { | |
21 public: | |
22 struct Descriptor { | |
23 Descriptor(const std::string& key, int fd); | |
24 Descriptor(const std::string& key, | |
25 int fd, | |
26 base::MemoryMappedFile::Region region); | |
27 | |
28 // Globally unique key. | |
29 std::string key; | |
30 // Actual FD. | |
31 int fd; | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
nit: Use ScopedFD? You will have to define a move
Jay Civelli
2017/02/09 22:08:27
Great idea, now using a ScopedFD.
| |
32 // Optional region, defaults to kWholeFile. | |
33 base::MemoryMappedFile::Region region; | |
34 }; | |
35 typedef std::vector<Descriptor> Mapping; | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
Why not a map<std::string, Descriptor> and remove
Jay Civelli
2017/02/09 22:08:27
Done.
I copied this file over from GlobalDescripto
| |
36 | |
37 // Returns the singleton instance of FileDescriptorStore. | |
38 static FileDescriptorStore* GetInstance(); | |
39 | |
40 // Gets a descriptor given a key. It is a fatal error if the key is not known. | |
41 int Get(const std::string& key) const; | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
Get = TakeFD, and make it return a ScopedFD?
Jay Civelli
2017/02/09 22:08:27
Done.
| |
42 | |
43 // Gets a descriptor given a key. Returns -1 on error. | |
44 int MaybeGet(const std::string& key) const; | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
MaybeTakeFD?
Jay Civelli
2017/02/09 22:08:27
Done.
| |
45 | |
46 // Gets a region given a key. It is a fatal error if the key is not known. | |
47 base::MemoryMappedFile::Region GetRegion(const std::string& key) const; | |
48 | |
49 // Sets the descriptor for the given |key|. This sets the region associated | |
50 // with |key| to kWholeFile. | |
51 void Set(const std::string& key, int fd); | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:28
ScopedFD
Jay Civelli
2017/02/09 22:08:26
Done.
| |
52 | |
53 // Sets the descriptor and |region| for the given |key|. | |
54 void Set(const std::string& key, | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:28
ScopedFD
Jay Civelli
2017/02/09 22:08:26
Done.
| |
55 int fd, | |
56 base::MemoryMappedFile::Region region); | |
57 | |
58 void Reset(const Mapping& mapping); | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
If making the above changes, this should just beco
Jay Civelli
2017/02/09 22:08:26
This is actually not used, a left over from me tak
| |
59 | |
60 private: | |
61 friend struct DefaultSingletonTraits<FileDescriptorStore>; | |
62 FileDescriptorStore(); | |
63 ~FileDescriptorStore(); | |
64 | |
65 Mapping descriptors_; | |
66 }; | |
Ken Rockot(use gerrit already)
2017/02/09 17:17:27
DISALLOW_COPY_AND_ASSIGN
Jay Civelli
2017/02/09 22:08:26
Done.
| |
67 | |
68 } // namespace base | |
69 | |
70 #endif // BASE_FILE_DESCRIPTOR_STORE_H_ | |
OLD | NEW |