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

Unified Diff: remoting/host/desktop_session_agent_posix.cc

Issue 11231060: [Chromoting] The desktop process now creates a pre-connected pipe and passes (with some help of the… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixup Created 8 years, 2 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
Index: remoting/host/desktop_session_agent_posix.cc
diff --git a/remoting/host/desktop_session_agent_posix.cc b/remoting/host/desktop_session_agent_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9fb9b8baab1b194cceab4469453eb6b1acdfa8ab
--- /dev/null
+++ b/remoting/host/desktop_session_agent_posix.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2012 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.
+
+#include "remoting/host/desktop_session_agent.h"
+
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "base/eintr_wrapper.h"
+#include "base/single_thread_task_runner.h"
+#include "base/stringprintf.h"
+#include "ipc/ipc_channel.h"
+#include "ipc/ipc_channel_proxy.h"
+
+namespace remoting {
+
+// Provides screen/audio capturing and input injection services for
+// the network process.
+class DesktopSessionAgentPosix : public DesktopSessionAgent {
+ public:
+ DesktopSessionAgentPosix(
+ scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
+ virtual ~DesktopSessionAgentPosix();
+
+ protected:
+ virtual bool DoCreateNetworkChannel(
+ IPC::PlatformFileForTransit* client_out,
+ scoped_ptr<IPC::ChannelProxy>* server_out) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgentPosix);
+};
+
+DesktopSessionAgentPosix::DesktopSessionAgentPosix(
+ scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+ : DesktopSessionAgent(caller_task_runner, io_task_runner) {
+}
+
+DesktopSessionAgentPosix::~DesktopSessionAgentPosix() {
+}
+
+bool DesktopSessionAgentPosix::DoCreateNetworkChannel(
+ IPC::PlatformFileForTransit* client_out,
+ scoped_ptr<IPC::ChannelProxy>* server_out) {
+ // Create a socket pair.
+ int pipe_fds[2];
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds) != 0) {
+ PLOG(ERROR) << "socketpair()";
+ return false;
+ }
+
+ // Set both ends to be non-blocking.
+ if (fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) == -1 ||
Sergey Ulanov 2012/10/24 20:12:01 Looks like this duplicates code from SocketPair()
alexeypa (please no reviews) 2012/10/24 21:41:51 I'll follow up with a separate CL.
+ fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK) == -1) {
+ PLOG(ERROR) << "fcntl(O_NONBLOCK)";
+ if (HANDLE_EINTR(close(pipe_fds[0])) < 0)
+ PLOG(ERROR) << "close()";
+ if (HANDLE_EINTR(close(pipe_fds[1])) < 0)
+ PLOG(ERROR) << "close()";
+ return false;
+ }
+
+ // Generate a unique name for the channel.
+ std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID();
+ std::string socket_name = base::StringPrintf("/var/tmp/DesktopSessionAgent%s",
Sergey Ulanov 2012/10/24 20:12:01 Not sure why we need this. We pass IPC::ChannelPro
alexeypa (please no reviews) 2012/10/24 21:41:51 Done.
+ channel_name.c_str());
+
+ // Wrap the pipe into an IPC channel.
+ base::FileDescriptor fd(pipe_fds[0], false);
+ IPC::ChannelHandle handle(socket_name, fd);
+ scoped_ptr<IPC::ChannelProxy> server(new IPC::ChannelProxy(
Sergey Ulanov 2012/10/24 20:12:01 nit: server_out->reset()?
alexeypa (please no reviews) 2012/10/24 21:41:51 Done.
+ IPC::ChannelHandle(socket_name, fd),
+ IPC::Channel::MODE_SERVER,
+ this,
+ io_task_runner()));
+
+ *client_out = base::FileDescriptor(pipe_fds[1], false);
+ *server_out = server.Pass();
+ return true;
+}
+
+// static
+scoped_ptr<DesktopSessionAgent> DesktopSessionAgent::Create(
+ scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
+ return scoped_ptr<DesktopSessionAgent>(new DesktopSessionAgentPosix(
+ caller_task_runner, io_task_runner));
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698