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/desktop_session_agent.h" | 5 #include "remoting/host/desktop_session_agent.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "ipc/ipc_channel_proxy.h" | 10 #include "ipc/ipc_channel_proxy.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 113 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
114 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 114 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
115 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 115 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
116 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) | 116 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) |
117 : audio_capture_task_runner_(audio_capture_task_runner), | 117 : audio_capture_task_runner_(audio_capture_task_runner), |
118 caller_task_runner_(caller_task_runner), | 118 caller_task_runner_(caller_task_runner), |
119 input_task_runner_(input_task_runner), | 119 input_task_runner_(input_task_runner), |
120 io_task_runner_(io_task_runner), | 120 io_task_runner_(io_task_runner), |
121 video_capture_task_runner_(video_capture_task_runner), | 121 video_capture_task_runner_(video_capture_task_runner), |
122 control_factory_(this), | 122 control_factory_(this), |
123 desktop_pipe_(IPC::InvalidPlatformFileForTransit()), | |
124 next_shared_buffer_id_(1), | 123 next_shared_buffer_id_(1), |
125 shared_buffers_(0), | 124 shared_buffers_(0), |
126 started_(false) { | 125 started_(false) { |
127 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 126 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
128 } | 127 } |
129 | 128 |
130 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 129 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { |
131 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 130 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
132 | 131 |
133 bool handled = true; | 132 bool handled = true; |
(...skipping 23 matching lines...) Expand all Loading... |
157 | 156 |
158 CHECK(handled) << "Received unexpected IPC type: " << message.type(); | 157 CHECK(handled) << "Received unexpected IPC type: " << message.type(); |
159 return handled; | 158 return handled; |
160 } | 159 } |
161 | 160 |
162 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { | 161 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { |
163 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 162 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
164 | 163 |
165 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; | 164 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; |
166 | 165 |
167 CloseDesktopPipeHandle(); | 166 desktop_pipe_.Close(); |
168 } | 167 } |
169 | 168 |
170 void DesktopSessionAgent::OnChannelError() { | 169 void DesktopSessionAgent::OnChannelError() { |
171 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 170 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
172 | 171 |
173 // Make sure the channel is closed. | 172 // Make sure the channel is closed. |
174 network_channel_.reset(); | 173 network_channel_.reset(); |
175 CloseDesktopPipeHandle(); | 174 desktop_pipe_.Close(); |
176 | 175 |
177 // Notify the caller that the channel has been disconnected. | 176 // Notify the caller that the channel has been disconnected. |
178 if (delegate_.get()) | 177 if (delegate_.get()) |
179 delegate_->OnNetworkProcessDisconnected(); | 178 delegate_->OnNetworkProcessDisconnected(); |
180 } | 179 } |
181 | 180 |
182 webrtc::SharedMemory* DesktopSessionAgent::CreateSharedMemory(size_t size) { | 181 webrtc::SharedMemory* DesktopSessionAgent::CreateSharedMemory(size_t size) { |
183 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 182 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); |
184 | 183 |
185 scoped_ptr<SharedBuffer> buffer = | 184 scoped_ptr<SharedBuffer> buffer = |
(...skipping 23 matching lines...) Expand all Loading... |
209 | 208 |
210 return buffer.release(); | 209 return buffer.release(); |
211 } | 210 } |
212 | 211 |
213 DesktopSessionAgent::~DesktopSessionAgent() { | 212 DesktopSessionAgent::~DesktopSessionAgent() { |
214 DCHECK(!audio_capturer_); | 213 DCHECK(!audio_capturer_); |
215 DCHECK(!desktop_environment_); | 214 DCHECK(!desktop_environment_); |
216 DCHECK(!network_channel_); | 215 DCHECK(!network_channel_); |
217 DCHECK(!screen_controls_); | 216 DCHECK(!screen_controls_); |
218 DCHECK(!video_capturer_); | 217 DCHECK(!video_capturer_); |
219 | |
220 CloseDesktopPipeHandle(); | |
221 } | 218 } |
222 | 219 |
223 const std::string& DesktopSessionAgent::client_jid() const { | 220 const std::string& DesktopSessionAgent::client_jid() const { |
224 return client_jid_; | 221 return client_jid_; |
225 } | 222 } |
226 | 223 |
227 void DesktopSessionAgent::DisconnectSession() { | 224 void DesktopSessionAgent::DisconnectSession() { |
228 SendToNetwork(new ChromotingDesktopNetworkMsg_DisconnectSession()); | 225 SendToNetwork(new ChromotingDesktopNetworkMsg_DisconnectSession()); |
229 } | 226 } |
230 | 227 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 361 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
365 DCHECK(delegate_.get() == NULL); | 362 DCHECK(delegate_.get() == NULL); |
366 | 363 |
367 delegate_ = delegate; | 364 delegate_ = delegate; |
368 | 365 |
369 // Create an IPC channel to communicate with the network process. | 366 // Create an IPC channel to communicate with the network process. |
370 bool result = CreateConnectedIpcChannel(io_task_runner_, | 367 bool result = CreateConnectedIpcChannel(io_task_runner_, |
371 this, | 368 this, |
372 &desktop_pipe_, | 369 &desktop_pipe_, |
373 &network_channel_); | 370 &network_channel_); |
374 *desktop_pipe_out = desktop_pipe_; | 371 base::PlatformFile raw_desktop_pipe = desktop_pipe_.GetPlatformFile(); |
| 372 #if defined(OS_WIN) |
| 373 *desktop_pipe_out = IPC::PlatformFileForTransit(raw_desktop_pipe); |
| 374 #elif defined(OS_POSIX) |
| 375 *desktop_pipe_out = IPC::PlatformFileForTransit(raw_desktop_pipe, false); |
| 376 #else |
| 377 #error Unsupported platform. |
| 378 #endif |
375 return result; | 379 return result; |
376 } | 380 } |
377 | 381 |
378 void DesktopSessionAgent::Stop() { | 382 void DesktopSessionAgent::Stop() { |
379 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 383 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
380 | 384 |
381 delegate_.reset(); | 385 delegate_.reset(); |
382 | 386 |
383 // Make sure the channel is closed. | 387 // Make sure the channel is closed. |
384 network_channel_.reset(); | 388 network_channel_.reset(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 | 559 |
556 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { | 560 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { |
557 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 561 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); |
558 DCHECK(id != 0); | 562 DCHECK(id != 0); |
559 | 563 |
560 shared_buffers_--; | 564 shared_buffers_--; |
561 DCHECK_GE(shared_buffers_, 0); | 565 DCHECK_GE(shared_buffers_, 0); |
562 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); | 566 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); |
563 } | 567 } |
564 | 568 |
565 void DesktopSessionAgent::CloseDesktopPipeHandle() { | |
566 if (!(desktop_pipe_ == IPC::InvalidPlatformFileForTransit())) { | |
567 #if defined(OS_WIN) | |
568 base::ClosePlatformFile(desktop_pipe_); | |
569 #elif defined(OS_POSIX) | |
570 base::ClosePlatformFile(desktop_pipe_.fd); | |
571 #else // !defined(OS_POSIX) | |
572 #error Unsupported platform. | |
573 #endif // !defined(OS_POSIX) | |
574 | |
575 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); | |
576 } | |
577 } | |
578 | |
579 } // namespace remoting | 569 } // namespace remoting |
OLD | NEW |