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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "remoting/host/desktop_session_agent.h"
6
7 #include <fcntl.h>
8 #include <sys/socket.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 #include "base/eintr_wrapper.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/stringprintf.h"
15 #include "ipc/ipc_channel.h"
16 #include "ipc/ipc_channel_proxy.h"
17
18 namespace remoting {
19
20 // Provides screen/audio capturing and input injection services for
21 // the network process.
22 class DesktopSessionAgentPosix : public DesktopSessionAgent {
23 public:
24 DesktopSessionAgentPosix(
25 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
26 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
27 virtual ~DesktopSessionAgentPosix();
28
29 protected:
30 virtual bool DoCreateNetworkChannel(
31 IPC::PlatformFileForTransit* client_out,
32 scoped_ptr<IPC::ChannelProxy>* server_out) OVERRIDE;
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgentPosix);
36 };
37
38 DesktopSessionAgentPosix::DesktopSessionAgentPosix(
39 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
40 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
41 : DesktopSessionAgent(caller_task_runner, io_task_runner) {
42 }
43
44 DesktopSessionAgentPosix::~DesktopSessionAgentPosix() {
45 }
46
47 bool DesktopSessionAgentPosix::DoCreateNetworkChannel(
48 IPC::PlatformFileForTransit* client_out,
49 scoped_ptr<IPC::ChannelProxy>* server_out) {
50 // Create a socket pair.
51 int pipe_fds[2];
52 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds) != 0) {
53 PLOG(ERROR) << "socketpair()";
54 return false;
55 }
56
57 // Set both ends to be non-blocking.
58 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.
59 fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK) == -1) {
60 PLOG(ERROR) << "fcntl(O_NONBLOCK)";
61 if (HANDLE_EINTR(close(pipe_fds[0])) < 0)
62 PLOG(ERROR) << "close()";
63 if (HANDLE_EINTR(close(pipe_fds[1])) < 0)
64 PLOG(ERROR) << "close()";
65 return false;
66 }
67
68 // Generate a unique name for the channel.
69 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID();
70 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.
71 channel_name.c_str());
72
73 // Wrap the pipe into an IPC channel.
74 base::FileDescriptor fd(pipe_fds[0], false);
75 IPC::ChannelHandle handle(socket_name, fd);
76 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.
77 IPC::ChannelHandle(socket_name, fd),
78 IPC::Channel::MODE_SERVER,
79 this,
80 io_task_runner()));
81
82 *client_out = base::FileDescriptor(pipe_fds[1], false);
83 *server_out = server.Pass();
84 return true;
85 }
86
87 // static
88 scoped_ptr<DesktopSessionAgent> DesktopSessionAgent::Create(
89 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
90 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
91 return scoped_ptr<DesktopSessionAgent>(new DesktopSessionAgentPosix(
92 caller_task_runner, io_task_runner));
93 }
94
95 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698