Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: sandbox/mac/xpc_message_server.h

Issue 404893002: Add an XPC implementation of sandbox::MessageServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/mac/xpc.cc ('k') | sandbox/mac/xpc_message_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/mac/xpc_message_server.h
diff --git a/sandbox/mac/xpc_message_server.h b/sandbox/mac/xpc_message_server.h
new file mode 100644
index 0000000000000000000000000000000000000000..99edb26abfd0ec2c6d93610e0ab205b09080fe6f
--- /dev/null
+++ b/sandbox/mac/xpc_message_server.h
@@ -0,0 +1,62 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SANDBOX_MAC_XPC_MESSAGE_SERVER_H_
+#define SANDBOX_MAC_XPC_MESSAGE_SERVER_H_
+
+#include "base/mac/scoped_mach_port.h"
+#include "base/memory/scoped_ptr.h"
+#include "sandbox/mac/message_server.h"
+#include "sandbox/mac/xpc.h"
+#include "sandbox/sandbox_export.h"
+
+namespace sandbox {
+
+class DispatchSourceMach;
+
+// An implementation of MessageServer that uses XPC pipes to read and write XPC
+// messages from a Mach port.
+class SANDBOX_EXPORT XPCMessageServer : public MessageServer {
+ public:
+ // Creates a new XPC message server that will send messages to |demuxer|
+ // for handling. If the |server_receive_right| is non-NULL, this class will
+ // take ownership of the port and it will be used to receive messages.
+ // Otherwise the server will create a new receive right on which to listen.
+ XPCMessageServer(MessageDemuxer* demuxer,
+ mach_port_t server_receive_right);
+ virtual ~XPCMessageServer();
+
+ // MessageServer:
+ virtual bool Initialize() OVERRIDE;
+ virtual pid_t GetMessageSenderPID(IPCMessage request) OVERRIDE;
+ virtual IPCMessage CreateReply(IPCMessage request) OVERRIDE;
+ virtual bool SendReply(IPCMessage reply) OVERRIDE;
+ virtual void ForwardMessage(IPCMessage request,
+ mach_port_t destination) OVERRIDE;
+ // Creates an error reply message with a field "error" set to |error_code|.
+ virtual void RejectMessage(IPCMessage request, int error_code) OVERRIDE;
+ virtual mach_port_t GetServerPort() const OVERRIDE;
+
+ private:
+ // Reads a message from the XPC pipe.
+ void ReceiveMessage();
+
+ // The demuxer delegate. Weak.
+ MessageDemuxer* demuxer_;
+
+ // The Mach port on which the server is receiving requests.
+ base::mac::ScopedMachReceiveRight server_port_;
+
+ // MACH_RECV dispatch source that handles the |server_port_|.
+ scoped_ptr<DispatchSourceMach> dispatch_source_;
+
+ // The reply message, if one has been created.
+ xpc_object_t reply_message_;
+
+ DISALLOW_COPY_AND_ASSIGN(XPCMessageServer);
+};
+
+} // namespace sandbox
+
+#endif // SANDBOX_MAC_XPC_MESSAGE_SERVER_H_
« no previous file with comments | « sandbox/mac/xpc.cc ('k') | sandbox/mac/xpc_message_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698