Roll src/third_party/skia ff271c2:b679ca8
[chromium-blink-merge.git] / sandbox / mac / message_server.h
blob1cd40b0a3dc9e433fda4feacfeda9ba51c1b8a16
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
3 // found in the LICENSE file.
5 #ifndef SANDBOX_MAC_MESSAGE_SERVER_H_
6 #define SANDBOX_MAC_MESSAGE_SERVER_H_
8 #include <mach/mach.h>
9 #include <unistd.h>
11 #include "sandbox/mac/xpc.h"
13 namespace sandbox {
15 // A message received by a MessageServer. Each concrete implementation of
16 // that interface will handle the fields of this union appropriately.
17 // Consumers should treat this as an opaque handle.
18 union IPCMessage {
19 mach_msg_header_t* mach;
20 xpc_object_t xpc;
23 // A delegate interface for MessageServer that handles processing of
24 // incoming intercepted IPC messages.
25 class MessageDemuxer {
26 public:
27 // Handle a |request| message. The message is owned by the server. Use the
28 // server's methods to create and send a reply message.
29 virtual void DemuxMessage(IPCMessage request) = 0;
31 protected:
32 virtual ~MessageDemuxer() {}
35 // An interaface for an IPC server that implements Mach messaging semantics.
36 // The concrete implementation may be powered by raw Mach messages, XPC, or
37 // some other technology. This interface is the abstraction on top of those
38 // that enables message interception.
39 class MessageServer {
40 public:
41 virtual ~MessageServer() {}
43 // Initializes the class and starts running the message server. If this
44 // returns false, no other methods may be called on this class.
45 virtual bool Initialize() = 0;
47 // Given a received request message, returns the PID of the sending process.
48 virtual pid_t GetMessageSenderPID(IPCMessage request) = 0;
50 // Creates a reply message from a request message. The result is owned by
51 // the server.
52 virtual IPCMessage CreateReply(IPCMessage request) = 0;
54 // Sends a reply message. Returns true if the message was sent successfully.
55 virtual bool SendReply(IPCMessage reply) = 0;
57 // Forwards the original |request| to the |destination| for handling.
58 virtual void ForwardMessage(IPCMessage request, mach_port_t destination) = 0;
60 // Replies to the received |request| message by creating a reply and setting
61 // the specified |error_code| in a field that is interpreted by the
62 // underlying IPC system.
63 virtual void RejectMessage(IPCMessage request, int error_code) = 0;
65 // Returns the Mach port on which the MessageServer is listening.
66 virtual mach_port_t GetServerPort() const = 0;
69 } // namespace sandbox
71 #endif // SANDBOX_MAC_MESSAGE_SERVER_H_