| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 IPC_ATTACHMENT_BROKER_PRIVILEGED_MAC_H_ | 5 #ifndef IPC_ATTACHMENT_BROKER_PRIVILEGED_MAC_H_ |
| 6 #define IPC_ATTACHMENT_BROKER_PRIVILEGED_MAC_H_ | 6 #define IPC_ATTACHMENT_BROKER_PRIVILEGED_MAC_H_ |
| 7 | 7 |
| 8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 : public AttachmentBrokerPrivileged, | 57 : public AttachmentBrokerPrivileged, |
| 58 public base::PortProvider::Observer { | 58 public base::PortProvider::Observer { |
| 59 public: | 59 public: |
| 60 explicit AttachmentBrokerPrivilegedMac(base::PortProvider* port_provider); | 60 explicit AttachmentBrokerPrivilegedMac(base::PortProvider* port_provider); |
| 61 ~AttachmentBrokerPrivilegedMac() override; | 61 ~AttachmentBrokerPrivilegedMac() override; |
| 62 | 62 |
| 63 // IPC::AttachmentBroker overrides. | 63 // IPC::AttachmentBroker overrides. |
| 64 bool SendAttachmentToProcess( | 64 bool SendAttachmentToProcess( |
| 65 const scoped_refptr<IPC::BrokerableAttachment>& attachment, | 65 const scoped_refptr<IPC::BrokerableAttachment>& attachment, |
| 66 base::ProcessId destination_process) override; | 66 base::ProcessId destination_process) override; |
| 67 void DeregisterCommunicationChannel(Endpoint* endpoint) override; |
| 67 | 68 |
| 68 // IPC::Listener overrides. | 69 // IPC::Listener overrides. |
| 69 bool OnMessageReceived(const Message& message) override; | 70 bool OnMessageReceived(const Message& message) override; |
| 70 | 71 |
| 71 // base::PortProvider::Observer override. | 72 // base::PortProvider::Observer override. |
| 72 void OnReceivedTaskPort(base::ProcessHandle process) override; | 73 void OnReceivedTaskPort(base::ProcessHandle process) override; |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerPrivilegedMacMultiProcessTest, | 76 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerPrivilegedMacMultiProcessTest, |
| 76 InsertRight); | 77 InsertRight); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // |port_to_insert| must be a send right in the current task's name space. | 144 // |port_to_insert| must be a send right in the current task's name space. |
| 144 // Creates an intermediate Mach port in |pid| and sends |port_to_insert| as a | 145 // Creates an intermediate Mach port in |pid| and sends |port_to_insert| as a |
| 145 // mach_msg to the intermediate Mach port. | 146 // mach_msg to the intermediate Mach port. |
| 146 // Returns the intermediate port on success, and MACH_PORT_NULL on failure. | 147 // Returns the intermediate port on success, and MACH_PORT_NULL on failure. |
| 147 // This method takes ownership of |port_to_insert|. On success, ownership is | 148 // This method takes ownership of |port_to_insert|. On success, ownership is |
| 148 // passed to the intermediate Mach port. | 149 // passed to the intermediate Mach port. |
| 149 mach_port_name_t CreateIntermediateMachPort( | 150 mach_port_name_t CreateIntermediateMachPort( |
| 150 mach_port_t task_port, | 151 mach_port_t task_port, |
| 151 base::mac::ScopedMachSendRight port_to_insert); | 152 base::mac::ScopedMachSendRight port_to_insert); |
| 152 | 153 |
| 153 // Acquire a send right to a named right in |pid|. | |
| 154 // Returns MACH_PORT_NULL on error. | |
| 155 base::mac::ScopedMachSendRight AcquireSendRight(base::ProcessId pid, | |
| 156 mach_port_name_t named_right); | |
| 157 | |
| 158 // Extracts a copy of the send right to |named_right| from |task_port|. | 154 // Extracts a copy of the send right to |named_right| from |task_port|. |
| 159 // Returns MACH_PORT_NULL on error. | 155 // Returns MACH_PORT_NULL on error. |
| 160 base::mac::ScopedMachSendRight ExtractNamedRight( | 156 base::mac::ScopedMachSendRight ExtractNamedRight( |
| 161 mach_port_t task_port, | 157 mach_port_t task_port, |
| 162 mach_port_name_t named_right); | 158 mach_port_name_t named_right); |
| 163 | 159 |
| 164 // Copies an existing |wire_format|, but substitutes in a different mach port. | 160 // Copies an existing |wire_format|, but substitutes in a different mach port. |
| 165 MachPortWireFormat CopyWireFormat(const MachPortWireFormat& wire_format, | 161 MachPortWireFormat CopyWireFormat(const MachPortWireFormat& wire_format, |
| 166 uint32_t mach_port); | 162 uint32_t mach_port); |
| 167 | 163 |
| 168 // |wire_format.destination_process| must be this process. | 164 // |wire_format.destination_process| must be this process. |
| 169 // |wire_format.mach_port| must be the final Mach port. | 165 // |wire_format.mach_port| must be the final Mach port. |
| 170 // Consumes a reference to |wire_format.mach_port|, as ownership is implicitly | 166 // Consumes a reference to |wire_format.mach_port|, as ownership is implicitly |
| 171 // passed to the consumer of the Chrome IPC message. | 167 // passed to the consumer of the Chrome IPC message. |
| 172 // Makes an attachment, queues it, and notifies the observers. | 168 // Makes an attachment, queues it, and notifies the observers. |
| 173 void RoutePrecursorToSelf(AttachmentPrecursor* precursor); | 169 void RoutePrecursorToSelf(AttachmentPrecursor* precursor); |
| 174 | 170 |
| 175 // |wire_format.destination_process| must be another process. | 171 // |wire_format.destination_process| must be another process. |
| 176 // |wire_format.mach_port| must be the intermediate Mach port. | 172 // |wire_format.mach_port| must be the intermediate Mach port. |
| 177 // Ownership of |wire_format.mach_port| is implicitly passed to the process | 173 // Ownership of |wire_format.mach_port| is implicitly passed to the process |
| 178 // that receives the Chrome IPC message. | 174 // that receives the Chrome IPC message. |
| 179 void RouteWireFormatToAnother(const MachPortWireFormat& wire_format); | 175 // Returns |false| on irrecoverable error. |
| 176 bool RouteWireFormatToAnother(const MachPortWireFormat& wire_format); |
| 180 | 177 |
| 181 // Atempts to broker all precursors whose destination is |pid|. Has no effect | 178 // Atempts to broker all precursors whose destination is |pid|. Has no effect |
| 182 // if |port_provider_| does not have the task port for |pid|. | 179 // if |port_provider_| does not have the task port for |pid|. |
| 183 void SendPrecursorsForProcess(base::ProcessId pid); | 180 void SendPrecursorsForProcess(base::ProcessId pid); |
| 184 | 181 |
| 185 // Brokers a single precursor into the task represented by |task_port|. | 182 // Brokers a single precursor into the task represented by |task_port|. |
| 186 void SendPrecursor(AttachmentPrecursor* precursor, mach_port_t task_port); | 183 // Returns |false| on irrecoverable error. |
| 184 bool SendPrecursor(AttachmentPrecursor* precursor, mach_port_t task_port); |
| 187 | 185 |
| 188 // Add a precursor to |precursors_|. Takes ownership of |port|. | 186 // Add a precursor to |precursors_|. Takes ownership of |port|. |
| 189 void AddPrecursor(base::ProcessId pid, | 187 void AddPrecursor(base::ProcessId pid, |
| 190 base::mac::ScopedMachSendRight port, | 188 base::mac::ScopedMachSendRight port, |
| 191 const BrokerableAttachment::AttachmentId& id); | 189 const BrokerableAttachment::AttachmentId& id); |
| 192 | 190 |
| 193 // Atempts to process all extractors whose source is |pid|. Has no effect | 191 // Atempts to process all extractors whose source is |pid|. Has no effect |
| 194 // if |port_provider_| does not have the task port for |pid|. | 192 // if |port_provider_| does not have the task port for |pid|. |
| 195 void ProcessExtractorsForProcess(base::ProcessId pid); | 193 void ProcessExtractorsForProcess(base::ProcessId pid); |
| 196 | 194 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 216 // processed. | 214 // processed. |
| 217 std::map<base::ProcessId, ScopedVector<AttachmentExtractor>*> extractors_; | 215 std::map<base::ProcessId, ScopedVector<AttachmentExtractor>*> extractors_; |
| 218 base::Lock extractors_lock_; | 216 base::Lock extractors_lock_; |
| 219 | 217 |
| 220 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivilegedMac); | 218 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivilegedMac); |
| 221 }; | 219 }; |
| 222 | 220 |
| 223 } // namespace IPC | 221 } // namespace IPC |
| 224 | 222 |
| 225 #endif // IPC_ATTACHMENT_BROKER_PRIVILEGED_MAC_H_ | 223 #endif // IPC_ATTACHMENT_BROKER_PRIVILEGED_MAC_H_ |
| OLD | NEW |