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.h" | 5 #include "remoting/host/ipc_desktop_environment.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/platform_file.h" | |
11 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
12 #include "ipc/ipc_channel_proxy.h" | |
13 #include "ipc/ipc_message_macros.h" | |
14 #include "remoting/capturer/capture_data.h" | |
15 #include "remoting/capturer/video_frame_capturer.h" | 11 #include "remoting/capturer/video_frame_capturer.h" |
16 #include "remoting/host/audio_capturer.h" | 12 #include "remoting/host/audio_capturer.h" |
17 #include "remoting/host/chromoting_messages.h" | |
18 #include "remoting/host/client_session.h" | |
19 #include "remoting/host/desktop_session_connector.h" | 13 #include "remoting/host/desktop_session_connector.h" |
20 #include "remoting/host/desktop_session_proxy.h" | 14 #include "remoting/host/desktop_session_proxy.h" |
21 #include "remoting/host/event_executor.h" | 15 #include "remoting/host/event_executor.h" |
22 #include "remoting/host/ipc_audio_capturer.h" | |
23 #include "remoting/host/ipc_event_executor.h" | |
24 #include "remoting/host/ipc_video_frame_capturer.h" | |
25 | |
26 #if defined(OS_WIN) | |
27 #include "base/win/scoped_handle.h" | |
28 #endif // defined(OS_WIN) | |
29 | 16 |
30 namespace remoting { | 17 namespace remoting { |
31 | 18 |
32 IpcDesktopEnvironment::IpcDesktopEnvironment( | 19 IpcDesktopEnvironment::IpcDesktopEnvironment( |
33 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
34 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 21 const std::string& client_jid, |
35 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 22 const base::Closure& disconnect_callback, |
36 DesktopSessionConnector* desktop_session_connector, | 23 base::WeakPtr<DesktopSessionConnector> desktop_session_connector) |
37 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) | 24 : caller_task_runner_(caller_task_runner), |
38 : DesktopEnvironment( | 25 connected_(false), |
39 scoped_ptr<AudioCapturer>( | |
40 new IpcAudioCapturer(desktop_session_proxy)), | |
41 scoped_ptr<EventExecutor>( | |
42 new IpcEventExecutor(desktop_session_proxy)), | |
43 scoped_ptr<VideoFrameCapturer>( | |
44 new IpcVideoFrameCapturer(desktop_session_proxy))), | |
45 network_task_runner_(network_task_runner), | |
46 desktop_session_connector_(desktop_session_connector), | 26 desktop_session_connector_(desktop_session_connector), |
47 desktop_session_proxy_(desktop_session_proxy), | 27 desktop_session_proxy_(new DesktopSessionProxy(caller_task_runner, |
48 connected_(false) { | 28 client_jid, |
| 29 disconnect_callback)) { |
| 30 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
49 } | 31 } |
50 | 32 |
51 IpcDesktopEnvironment::~IpcDesktopEnvironment() { | 33 IpcDesktopEnvironment::~IpcDesktopEnvironment() { |
52 if (connected_) { | 34 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
53 connected_ = false; | 35 |
| 36 if (connected_ && desktop_session_connector_) |
54 desktop_session_connector_->DisconnectTerminal(desktop_session_proxy_); | 37 desktop_session_connector_->DisconnectTerminal(desktop_session_proxy_); |
| 38 |
| 39 connected_ = false; |
| 40 } |
| 41 |
| 42 scoped_ptr<AudioCapturer> IpcDesktopEnvironment::CreateAudioCapturer( |
| 43 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) { |
| 44 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 45 |
| 46 RegisterDesktopSessionProxy(); |
| 47 return desktop_session_proxy_->CreateAudioCapturer(audio_task_runner); |
| 48 } |
| 49 |
| 50 scoped_ptr<EventExecutor> IpcDesktopEnvironment::CreateEventExecutor( |
| 51 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 52 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 53 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 54 |
| 55 RegisterDesktopSessionProxy(); |
| 56 return desktop_session_proxy_->CreateEventExecutor(input_task_runner, |
| 57 ui_task_runner); |
| 58 } |
| 59 |
| 60 scoped_ptr<VideoFrameCapturer> IpcDesktopEnvironment::CreateVideoCapturer( |
| 61 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 62 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { |
| 63 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 64 |
| 65 RegisterDesktopSessionProxy(); |
| 66 return desktop_session_proxy_->CreateVideoCapturer(capture_task_runner, |
| 67 encode_task_runner); |
| 68 } |
| 69 |
| 70 void IpcDesktopEnvironment::RegisterDesktopSessionProxy() { |
| 71 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 72 |
| 73 if (!connected_) { |
| 74 connected_ = true; |
| 75 desktop_session_connector_->ConnectTerminal(desktop_session_proxy_); |
55 } | 76 } |
56 } | 77 } |
57 | 78 |
58 void IpcDesktopEnvironment::Start( | |
59 scoped_ptr<protocol::ClipboardStub> client_clipboard, | |
60 const std::string& client_jid, | |
61 const base::Closure& disconnect_callback) { | |
62 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
63 DCHECK(!connected_); | |
64 | |
65 desktop_session_proxy_->Initialize(client_jid, disconnect_callback); | |
66 | |
67 // Register the proxy to receive AttachToDesktop() and DetachFromDesktop() | |
68 // notifications. | |
69 connected_ = true; | |
70 desktop_session_connector_->ConnectTerminal(desktop_session_proxy_); | |
71 | |
72 DesktopEnvironment::Start(client_clipboard.Pass(), client_jid, | |
73 disconnect_callback); | |
74 } | |
75 | |
76 } // namespace remoting | 79 } // namespace remoting |
OLD | NEW |