OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 BASE_MAC_MACH_PORT_BROKER_H_ | 5 #ifndef BASE_MAC_MACH_PORT_BROKER_H_ |
6 #define BASE_MAC_MACH_PORT_BROKER_H_ | 6 #define BASE_MAC_MACH_PORT_BROKER_H_ |
7 | 7 |
8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "base/base_export.h" | 14 #include "base/base_export.h" |
14 #include "base/mac/dispatch_source_mach.h" | 15 #include "base/mac/dispatch_source_mach.h" |
15 #include "base/mac/scoped_mach_port.h" | 16 #include "base/mac/scoped_mach_port.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/process/port_provider_mac.h" | 18 #include "base/process/port_provider_mac.h" |
19 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 // On OS X, the task port of a process is required to collect metrics about the | 24 // On OS X, the task port of a process is required to collect metrics about the |
25 // process, and to insert Mach ports into the process. Running |task_for_pid()| | 25 // process, and to insert Mach ports into the process. Running |task_for_pid()| |
26 // is only allowed for privileged code. However, a process has port rights to | 26 // is only allowed for privileged code. However, a process has port rights to |
27 // all its subprocesses, so let the child processes send their Mach port to the | 27 // all its subprocesses, so let the child processes send their Mach port to the |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // this method (and release the lock afterwards). | 84 // this method (and release the lock afterwards). |
85 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); | 85 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); |
86 | 86 |
87 // Name used to identify a particular port broker. | 87 // Name used to identify a particular port broker. |
88 const std::string name_; | 88 const std::string name_; |
89 | 89 |
90 // The Mach port on which the server listens. | 90 // The Mach port on which the server listens. |
91 base::mac::ScopedMachReceiveRight server_port_; | 91 base::mac::ScopedMachReceiveRight server_port_; |
92 | 92 |
93 // The dispatch source and queue on which Mach messages will be received. | 93 // The dispatch source and queue on which Mach messages will be received. |
94 scoped_ptr<base::DispatchSourceMach> dispatch_source_; | 94 std::unique_ptr<base::DispatchSourceMach> dispatch_source_; |
95 | 95 |
96 // Stores mach info for every process in the broker. | 96 // Stores mach info for every process in the broker. |
97 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; | 97 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; |
98 MachMap mach_map_; | 98 MachMap mach_map_; |
99 | 99 |
100 // Mutex that guards |mach_map_|. | 100 // Mutex that guards |mach_map_|. |
101 mutable base::Lock lock_; | 101 mutable base::Lock lock_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(MachPortBroker); | 103 DISALLOW_COPY_AND_ASSIGN(MachPortBroker); |
104 }; | 104 }; |
105 | 105 |
106 } // namespace base | 106 } // namespace base |
107 | 107 |
108 #endif // BASE_MAC_MACH_PORT_BROKER_H_ | 108 #endif // BASE_MAC_MACH_PORT_BROKER_H_ |
OLD | NEW |