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

Side by Side Diff: remoting/host/ipc_desktop_environment_factory.cc

Issue 11778049: Making DesktopEnvironment a factory class used by ClientSession to create audio/video capturers and… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 11 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
« no previous file with comments | « remoting/host/ipc_desktop_environment_factory.h ('k') | remoting/host/ipc_event_executor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ipc_desktop_environment_factory.h"
6
7 #include <utility>
8
9 #include "ipc/ipc_channel_proxy.h"
10 #include "base/platform_file.h"
11 #include "remoting/capturer/video_frame_capturer.h"
12 #include "remoting/host/audio_capturer.h"
13 #include "remoting/host/chromoting_host.h"
14 #include "remoting/host/chromoting_host_context.h"
15 #include "remoting/host/chromoting_messages.h"
16 #include "remoting/host/desktop_session_connector.h"
17 #include "remoting/host/desktop_session_proxy.h"
18 #include "remoting/host/event_executor.h"
19 #include "remoting/host/ipc_desktop_environment.h"
20
21 namespace remoting {
22
23 IpcDesktopEnvironmentFactory::IpcDesktopEnvironmentFactory(
24 IPC::ChannelProxy* daemon_channel,
25 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner,
26 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
27 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
29 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner)
30 : DesktopEnvironmentFactory(input_task_runner, ui_task_runner),
31 daemon_channel_(daemon_channel),
32 audio_capture_task_runner_(audio_capture_task_runner),
33 network_task_runner_(network_task_runner),
34 video_capture_task_runner_(video_capture_task_runner),
35 next_id_(0) {
36 }
37
38 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() {
39 }
40
41 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create() {
42 DCHECK(network_task_runner_->BelongsToCurrentThread());
43
44 scoped_refptr<DesktopSessionProxy> desktop_session_proxy(
45 new DesktopSessionProxy(audio_capture_task_runner_,
46 network_task_runner_,
47 video_capture_task_runner_));
48
49 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment(
50 input_task_runner_, network_task_runner_, ui_task_runner_,
51 this, desktop_session_proxy));
52 }
53
54 void IpcDesktopEnvironmentFactory::ConnectTerminal(
55 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) {
56 DCHECK(network_task_runner_->BelongsToCurrentThread());
57
58 int id = next_id_++;
59 bool inserted = active_connections_.insert(
60 std::make_pair(id, desktop_session_proxy)).second;
61 CHECK(inserted);
62
63 VLOG(1) << "Network: registered desktop environment " << id;
64 daemon_channel_->Send(new ChromotingNetworkHostMsg_ConnectTerminal(id));
65 }
66
67 void IpcDesktopEnvironmentFactory::DisconnectTerminal(
68 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) {
69 DCHECK(network_task_runner_->BelongsToCurrentThread());
70
71 ActiveConnectionsList::iterator i;
72 for (i = active_connections_.begin(); i != active_connections_.end(); ++i) {
73 if (i->second.get() == desktop_session_proxy.get())
74 break;
75 }
76
77 if (i != active_connections_.end()) {
78 int id = i->first;
79 active_connections_.erase(i);
80
81 VLOG(1) << "Network: unregistered desktop environment " << id;
82 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id));
83 }
84 }
85
86 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached(
87 int terminal_id,
88 IPC::PlatformFileForTransit desktop_process,
89 IPC::PlatformFileForTransit desktop_pipe) {
90 if (!network_task_runner_->BelongsToCurrentThread()) {
91 network_task_runner_->PostTask(FROM_HERE, base::Bind(
92 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached,
93 base::Unretained(this), terminal_id, desktop_process, desktop_pipe));
94 return;
95 }
96
97 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id);
98 if (i != active_connections_.end()) {
99 i->second->DetachFromDesktop();
100 i->second->AttachToDesktop(desktop_process, desktop_pipe);
101 } else {
102 #if defined(OS_POSIX)
103 DCHECK(desktop_process.auto_close);
104 DCHECK(desktop_pipe.auto_close);
105
106 base::ClosePlatformFile(desktop_process.fd);
107 base::ClosePlatformFile(desktop_pipe.fd);
108 #elif defined(OS_WIN)
109 base::ClosePlatformFile(desktop_process);
110 #endif // defined(OS_WIN)
111 }
112 }
113
114 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) {
115 if (!network_task_runner_->BelongsToCurrentThread()) {
116 network_task_runner_->PostTask(FROM_HERE, base::Bind(
117 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected,
118 base::Unretained(this), terminal_id));
119 return;
120 }
121
122 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id);
123 if (i != active_connections_.end()) {
124 scoped_refptr<DesktopSessionProxy> desktop_session_proxy = i->second;
125 active_connections_.erase(i);
126
127 // Disconnect the client session.
128 desktop_session_proxy->DisconnectSession();
129 }
130 }
131
132 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/ipc_desktop_environment_factory.h ('k') | remoting/host/ipc_event_executor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698