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

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

Issue 12096071: Adding a unit test to verify the IPC channel between the network and desktop processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback. Created 7 years, 10 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
OLDNEW
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/logging.h" 8 #include "base/logging.h"
8 #include "ipc/ipc_channel_proxy.h" 9 #include "ipc/ipc_channel_proxy.h"
9 #include "ipc/ipc_message.h" 10 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_message_macros.h" 11 #include "ipc/ipc_message_macros.h"
11 #include "media/video/capture/screen/screen_capture_data.h" 12 #include "media/video/capture/screen/screen_capture_data.h"
12 #include "remoting/base/auto_thread_task_runner.h" 13 #include "remoting/base/auto_thread_task_runner.h"
13 #include "remoting/base/constants.h" 14 #include "remoting/base/constants.h"
14 #include "remoting/base/util.h" 15 #include "remoting/base/util.h"
15 #include "remoting/host/audio_capturer.h" 16 #include "remoting/host/audio_capturer.h"
16 #include "remoting/host/chromoting_messages.h" 17 #include "remoting/host/chromoting_messages.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } // namespace 69 } // namespace
69 70
70 DesktopSessionAgent::Delegate::~Delegate() { 71 DesktopSessionAgent::Delegate::~Delegate() {
71 } 72 }
72 73
73 DesktopSessionAgent::~DesktopSessionAgent() { 74 DesktopSessionAgent::~DesktopSessionAgent() {
74 DCHECK(!audio_capturer_); 75 DCHECK(!audio_capturer_);
75 DCHECK(!disconnect_window_); 76 DCHECK(!disconnect_window_);
76 DCHECK(!local_input_monitor_); 77 DCHECK(!local_input_monitor_);
77 DCHECK(!network_channel_); 78 DCHECK(!network_channel_);
79 DCHECK_EQ(desktop_pipe_, IPC::InvalidPlatformFileForTransit());
78 DCHECK(!video_capturer_); 80 DCHECK(!video_capturer_);
79 } 81 }
80 82
81 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { 83 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) {
82 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 84 DCHECK(caller_task_runner()->BelongsToCurrentThread());
83 85
84 bool handled = true; 86 bool handled = true;
85 if (started_) { 87 if (started_) {
86 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) 88 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message)
87 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, 89 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame,
(...skipping 24 matching lines...) Expand all
112 OnChannelError(); 114 OnChannelError();
113 } 115 }
114 116
115 return handled; 117 return handled;
116 } 118 }
117 119
118 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { 120 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) {
119 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 121 DCHECK(caller_task_runner()->BelongsToCurrentThread());
120 122
121 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; 123 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")";
124
125 CloseDesktopPipeHandle();
122 } 126 }
123 127
124 void DesktopSessionAgent::OnChannelError() { 128 void DesktopSessionAgent::OnChannelError() {
125 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 129 DCHECK(caller_task_runner()->BelongsToCurrentThread());
126 130
127 // Make sure the channel is closed. 131 // Make sure the channel is closed.
128 network_channel_.reset(); 132 network_channel_.reset();
133 CloseDesktopPipeHandle();
129 134
130 // Notify the caller that the channel has been disconnected. 135 // Notify the caller that the channel has been disconnected.
131 if (delegate_.get()) 136 if (delegate_.get())
132 delegate_->OnNetworkProcessDisconnected(); 137 delegate_->OnNetworkProcessDisconnected();
133 } 138 }
134 139
135 void DesktopSessionAgent::OnLocalMouseMoved(const SkIPoint& new_pos) { 140 void DesktopSessionAgent::OnLocalMouseMoved(const SkIPoint& new_pos) {
136 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 141 DCHECK(caller_task_runner()->BelongsToCurrentThread());
137 142
138 remote_input_filter_->LocalMouseMoved(new_pos); 143 remote_input_filter_->LocalMouseMoved(new_pos);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 291 }
287 292
288 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate, 293 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate,
289 IPC::PlatformFileForTransit* desktop_pipe_out) { 294 IPC::PlatformFileForTransit* desktop_pipe_out) {
290 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 295 DCHECK(caller_task_runner()->BelongsToCurrentThread());
291 DCHECK(delegate_.get() == NULL); 296 DCHECK(delegate_.get() == NULL);
292 297
293 delegate_ = delegate; 298 delegate_ = delegate;
294 299
295 // Create an IPC channel to communicate with the network process. 300 // Create an IPC channel to communicate with the network process.
296 return CreateChannelForNetworkProcess(desktop_pipe_out, &network_channel_); 301 bool result = CreateChannelForNetworkProcess(&desktop_pipe_,
302 &network_channel_);
303 *desktop_pipe_out = desktop_pipe_;
304 return result;
297 } 305 }
298 306
299 void DesktopSessionAgent::Stop() { 307 void DesktopSessionAgent::Stop() {
300 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 308 DCHECK(caller_task_runner()->BelongsToCurrentThread());
301 309
302 delegate_.reset(); 310 delegate_.reset();
303 311
304 // Make sure the channel is closed. 312 // Make sure the channel is closed.
305 network_channel_.reset(); 313 network_channel_.reset();
306 314
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, 529 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner,
522 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, 530 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
523 scoped_refptr<AutoThreadTaskRunner> input_task_runner, 531 scoped_refptr<AutoThreadTaskRunner> input_task_runner,
524 scoped_refptr<AutoThreadTaskRunner> io_task_runner, 532 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
525 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) 533 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner)
526 : audio_capture_task_runner_(audio_capture_task_runner), 534 : audio_capture_task_runner_(audio_capture_task_runner),
527 caller_task_runner_(caller_task_runner), 535 caller_task_runner_(caller_task_runner),
528 input_task_runner_(input_task_runner), 536 input_task_runner_(input_task_runner),
529 io_task_runner_(io_task_runner), 537 io_task_runner_(io_task_runner),
530 video_capture_task_runner_(video_capture_task_runner), 538 video_capture_task_runner_(video_capture_task_runner),
539 desktop_pipe_(IPC::InvalidPlatformFileForTransit()),
531 current_size_(SkISize::Make(0, 0)), 540 current_size_(SkISize::Make(0, 0)),
532 next_shared_buffer_id_(1), 541 next_shared_buffer_id_(1),
533 started_(false) { 542 started_(false) {
534 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 543 DCHECK(caller_task_runner_->BelongsToCurrentThread());
535 } 544 }
536 545
546 void DesktopSessionAgent::CloseDesktopPipeHandle() {
547 DCHECK(caller_task_runner_->BelongsToCurrentThread());
548
549 if (desktop_pipe_ != IPC::InvalidPlatformFileForTransit()) {
550 #if defined(OS_WIN)
551 base::ClosePlatformFile(desktop_pipe_);
552 #elif defined(OS_POSIX)
553 base::ClosePlatformFile(desktop_pipe_.fd);
554 #else // !defined(OS_POSIX)
555 #error Unsupported platform.
556 #endif // !defined(OS_POSIX)
557
558 desktop_pipe_ = IPC::InvalidPlatformFileForTransit();
559 }
560 }
561
537 } // namespace remoting 562 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698