OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ | 5 #ifndef SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ |
6 #define SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ | 6 #define SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ |
7 | 7 |
8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
9 | 9 |
10 #include "base/mac/scoped_mach_port.h" | 10 #include "base/mac/scoped_mach_port.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 class MachMessageServer : public MessageServer { | 23 class MachMessageServer : public MessageServer { |
24 public: | 24 public: |
25 // Creates a new Mach message server that will send messages to |demuxer| | 25 // Creates a new Mach message server that will send messages to |demuxer| |
26 // for handling. If the |server_receive_right| is non-NULL, this class will | 26 // for handling. If the |server_receive_right| is non-NULL, this class will |
27 // take ownership of the port and it will be used to receive messages. | 27 // take ownership of the port and it will be used to receive messages. |
28 // Otherwise the server will create a new receive right. | 28 // Otherwise the server will create a new receive right. |
29 // The maximum size of messages is specified by |buffer_size|. | 29 // The maximum size of messages is specified by |buffer_size|. |
30 MachMessageServer(MessageDemuxer* demuxer, | 30 MachMessageServer(MessageDemuxer* demuxer, |
31 mach_port_t server_receive_right, | 31 mach_port_t server_receive_right, |
32 mach_msg_size_t buffer_size); | 32 mach_msg_size_t buffer_size); |
33 virtual ~MachMessageServer(); | 33 ~MachMessageServer() override; |
34 | 34 |
35 // MessageServer: | 35 // MessageServer: |
36 virtual bool Initialize() override; | 36 bool Initialize() override; |
37 virtual pid_t GetMessageSenderPID(IPCMessage request) override; | 37 pid_t GetMessageSenderPID(IPCMessage request) override; |
38 virtual IPCMessage CreateReply(IPCMessage request) override; | 38 IPCMessage CreateReply(IPCMessage request) override; |
39 virtual bool SendReply(IPCMessage reply) override; | 39 bool SendReply(IPCMessage reply) override; |
40 virtual void ForwardMessage(IPCMessage request, | 40 void ForwardMessage(IPCMessage request, mach_port_t destination) override; |
41 mach_port_t destination) override; | |
42 // Replies to the message with the specified |error_code| as a MIG | 41 // Replies to the message with the specified |error_code| as a MIG |
43 // error_reply RetCode. | 42 // error_reply RetCode. |
44 virtual void RejectMessage(IPCMessage request, int error_code) override; | 43 void RejectMessage(IPCMessage request, int error_code) override; |
45 virtual mach_port_t GetServerPort() const override; | 44 mach_port_t GetServerPort() const override; |
46 | 45 |
47 private: | 46 private: |
48 // Event handler for the |server_source_| that reads a message from the queue | 47 // Event handler for the |server_source_| that reads a message from the queue |
49 // and processes it. | 48 // and processes it. |
50 void ReceiveMessage(); | 49 void ReceiveMessage(); |
51 | 50 |
52 // The demuxer delegate. Weak. | 51 // The demuxer delegate. Weak. |
53 MessageDemuxer* demuxer_; | 52 MessageDemuxer* demuxer_; |
54 | 53 |
55 // The Mach port on which the server is receiving requests. | 54 // The Mach port on which the server is receiving requests. |
56 base::mac::ScopedMachReceiveRight server_port_; | 55 base::mac::ScopedMachReceiveRight server_port_; |
57 | 56 |
58 // The size of the two message buffers below. | 57 // The size of the two message buffers below. |
59 const mach_msg_size_t buffer_size_; | 58 const mach_msg_size_t buffer_size_; |
60 | 59 |
61 // Request and reply buffers used in ReceiveMessage. | 60 // Request and reply buffers used in ReceiveMessage. |
62 base::mac::ScopedMachVM request_buffer_; | 61 base::mac::ScopedMachVM request_buffer_; |
63 base::mac::ScopedMachVM reply_buffer_; | 62 base::mac::ScopedMachVM reply_buffer_; |
64 | 63 |
65 // MACH_RECV dispatch source that handles the |server_port_|. | 64 // MACH_RECV dispatch source that handles the |server_port_|. |
66 scoped_ptr<DispatchSourceMach> dispatch_source_; | 65 scoped_ptr<DispatchSourceMach> dispatch_source_; |
67 | 66 |
68 // Whether or not ForwardMessage() was called during ReceiveMessage(). | 67 // Whether or not ForwardMessage() was called during ReceiveMessage(). |
69 bool did_forward_message_; | 68 bool did_forward_message_; |
70 }; | 69 }; |
71 | 70 |
72 } // namespace sandbox | 71 } // namespace sandbox |
73 | 72 |
74 #endif // SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ | 73 #endif // SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ |
OLD | NEW |