OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/ipc_desktop_environment_factory.h" | 5 #include "remoting/host/ipc_desktop_environment_factory.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
| 10 #include "base/platform_file.h" |
10 #include "remoting/host/audio_capturer.h" | 11 #include "remoting/host/audio_capturer.h" |
11 #include "remoting/host/chromoting_host.h" | 12 #include "remoting/host/chromoting_host.h" |
12 #include "remoting/host/chromoting_host_context.h" | 13 #include "remoting/host/chromoting_host_context.h" |
13 #include "remoting/host/chromoting_messages.h" | 14 #include "remoting/host/chromoting_messages.h" |
14 #include "remoting/host/desktop_session_connector.h" | 15 #include "remoting/host/desktop_session_connector.h" |
15 #include "remoting/host/event_executor.h" | 16 #include "remoting/host/event_executor.h" |
16 #include "remoting/host/ipc_desktop_environment.h" | 17 #include "remoting/host/ipc_desktop_environment.h" |
17 #include "remoting/host/video_frame_capturer.h" | 18 #include "remoting/host/video_frame_capturer.h" |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
(...skipping 10 matching lines...) Expand all Loading... |
30 } | 31 } |
31 | 32 |
32 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() { | 33 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() { |
33 } | 34 } |
34 | 35 |
35 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create( | 36 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create( |
36 ClientSession* client) { | 37 ClientSession* client) { |
37 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 38 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
38 | 39 |
39 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment( | 40 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment( |
40 input_task_runner_, ui_task_runner_, this, client)); | 41 input_task_runner_, network_task_runner_, ui_task_runner_, this, client)); |
41 } | 42 } |
42 | 43 |
43 void IpcDesktopEnvironmentFactory::ConnectTerminal( | 44 void IpcDesktopEnvironmentFactory::ConnectTerminal( |
44 IpcDesktopEnvironment* desktop_environment) { | 45 IpcDesktopEnvironment* desktop_environment) { |
45 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 46 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
46 | 47 |
47 int id = next_id_++; | 48 int id = next_id_++; |
48 bool inserted = active_connections_.insert( | 49 bool inserted = active_connections_.insert( |
49 std::make_pair(id, desktop_environment)).second; | 50 std::make_pair(id, desktop_environment)).second; |
50 CHECK(inserted); | 51 CHECK(inserted); |
(...skipping 14 matching lines...) Expand all Loading... |
65 | 66 |
66 if (i != active_connections_.end()) { | 67 if (i != active_connections_.end()) { |
67 int id = i->first; | 68 int id = i->first; |
68 active_connections_.erase(i); | 69 active_connections_.erase(i); |
69 | 70 |
70 VLOG(1) << "Network: unregistered desktop environment " << id; | 71 VLOG(1) << "Network: unregistered desktop environment " << id; |
71 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id)); | 72 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id)); |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
| 76 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached( |
| 77 int terminal_id, |
| 78 IPC::PlatformFileForTransit desktop_process, |
| 79 IPC::PlatformFileForTransit desktop_pipe) { |
| 80 if (!network_task_runner_->BelongsToCurrentThread()) { |
| 81 network_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 82 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached, |
| 83 base::Unretained(this), terminal_id, desktop_process, desktop_pipe)); |
| 84 return; |
| 85 } |
| 86 |
| 87 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); |
| 88 if (i != active_connections_.end()) { |
| 89 i->second->OnDesktopSessionAgentAttached(desktop_process, desktop_pipe); |
| 90 } else { |
| 91 #if defined(OS_POSIX) |
| 92 DCHECK(desktop_process.auto_close); |
| 93 DCHECK(desktop_pipe.auto_close); |
| 94 |
| 95 base::ClosePlatformFile(desktop_process.fd); |
| 96 base::ClosePlatformFile(desktop_pipe.fd); |
| 97 #elif defined(OS_WIN) |
| 98 base::ClosePlatformFile(desktop_process); |
| 99 #endif // defined(OS_WIN) |
| 100 } |
| 101 } |
| 102 |
75 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { | 103 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { |
76 if (!network_task_runner_->BelongsToCurrentThread()) { | 104 if (!network_task_runner_->BelongsToCurrentThread()) { |
77 network_task_runner_->PostTask(FROM_HERE, base::Bind( | 105 network_task_runner_->PostTask(FROM_HERE, base::Bind( |
78 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, | 106 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, |
79 base::Unretained(this), terminal_id)); | 107 base::Unretained(this), terminal_id)); |
80 return; | 108 return; |
81 } | 109 } |
82 | 110 |
83 ActiveConnectionsList::iterator i = | 111 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); |
84 active_connections_.find(terminal_id); | |
85 if (i != active_connections_.end()) { | 112 if (i != active_connections_.end()) { |
86 IpcDesktopEnvironment* desktop_environment = i->second; | 113 IpcDesktopEnvironment* desktop_environment = i->second; |
87 active_connections_.erase(i); | 114 active_connections_.erase(i); |
88 | 115 |
89 // Disconnect the client for the given desktop environment. | 116 // Disconnect the client for the given desktop environment. |
90 desktop_environment->DisconnectClient(); | 117 desktop_environment->DisconnectClient(); |
91 } | 118 } |
92 } | 119 } |
93 | 120 |
94 } // namespace remoting | 121 } // namespace remoting |
OLD | NEW |