| OLD | NEW |
| (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 "remoting/host/audio_capturer.h" |
| 11 #include "remoting/host/chromoting_host.h" |
| 12 #include "remoting/host/chromoting_host_context.h" |
| 13 #include "remoting/host/chromoting_messages.h" |
| 14 #include "remoting/host/desktop_session_connector.h" |
| 15 #include "remoting/host/event_executor.h" |
| 16 #include "remoting/host/ipc_desktop_environment.h" |
| 17 #include "remoting/host/video_frame_capturer.h" |
| 18 |
| 19 namespace remoting { |
| 20 |
| 21 IpcDesktopEnvironmentFactory::IpcDesktopEnvironmentFactory( |
| 22 IPC::ChannelProxy* daemon_channel, |
| 23 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 24 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 25 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
| 26 : DesktopEnvironmentFactory(input_task_runner, ui_task_runner), |
| 27 daemon_channel_(daemon_channel), |
| 28 network_task_runner_(network_task_runner), |
| 29 next_id_(0) { |
| 30 } |
| 31 |
| 32 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() { |
| 33 } |
| 34 |
| 35 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create( |
| 36 ClientSession* client) { |
| 37 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 38 |
| 39 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment( |
| 40 input_task_runner_, ui_task_runner_, this, client)); |
| 41 } |
| 42 |
| 43 void IpcDesktopEnvironmentFactory::ConnectTerminal( |
| 44 IpcDesktopEnvironment* desktop_environment) { |
| 45 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 46 |
| 47 int id = next_id_++; |
| 48 bool inserted = active_connections_.insert( |
| 49 std::make_pair(id, desktop_environment)).second; |
| 50 CHECK(inserted); |
| 51 |
| 52 VLOG(1) << "Network: registered desktop environment " << id; |
| 53 daemon_channel_->Send(new ChromotingNetworkHostMsg_ConnectTerminal(id)); |
| 54 } |
| 55 |
| 56 void IpcDesktopEnvironmentFactory::DisconnectTerminal( |
| 57 IpcDesktopEnvironment* desktop_environment) { |
| 58 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 59 |
| 60 ActiveConnectionsList::iterator i; |
| 61 for (i = active_connections_.begin(); i != active_connections_.end(); ++i) { |
| 62 if (i->second == desktop_environment) |
| 63 break; |
| 64 } |
| 65 |
| 66 if (i != active_connections_.end()) { |
| 67 int id = i->first; |
| 68 active_connections_.erase(i); |
| 69 |
| 70 VLOG(1) << "Network: unregistered desktop environment " << id; |
| 71 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id)); |
| 72 } |
| 73 } |
| 74 |
| 75 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { |
| 76 if (!network_task_runner_->BelongsToCurrentThread()) { |
| 77 network_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 78 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, |
| 79 base::Unretained(this), terminal_id)); |
| 80 return; |
| 81 } |
| 82 |
| 83 ActiveConnectionsList::iterator i = |
| 84 active_connections_.find(terminal_id); |
| 85 if (i != active_connections_.end()) { |
| 86 IpcDesktopEnvironment* desktop_environment = i->second; |
| 87 active_connections_.erase(i); |
| 88 |
| 89 // Disconnect the client for the given desktop environment. |
| 90 desktop_environment->DisconnectClient(); |
| 91 } |
| 92 } |
| 93 |
| 94 } // namespace remoting |
| OLD | NEW |