[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 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/protocol/host_control_dispatcher.h" | ||||
6 | |||||
7 | #include "base/message_loop_proxy.h" | ||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 8 | #include "net/socket/stream_socket.h" |
9 | #include "remoting/base/constants.h" | ||||
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 10 | #include "remoting/proto/control.pb.h" |
11 | #include "remoting/proto/internal.pb.h" | ||||
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 12 | #include "remoting/protocol/clipboard_stub.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 13 | #include "remoting/protocol/host_stub.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 14 | #include "remoting/protocol/util.h" |
15 | |||||
16 | namespace remoting { | ||||
17 | namespace protocol { | ||||
18 | |||||
19 | HostControlDispatcher::HostControlDispatcher() | ||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 20 | : ChannelDispatcherBase(kControlChannelName), |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 21 | clipboard_stub_(NULL), |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 22 | host_stub_(NULL) { |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 23 | } |
24 | |||||
25 | HostControlDispatcher::~HostControlDispatcher() { | ||||
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 26 | writer_.Close(); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 27 | } |
28 | |||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 29 | void HostControlDispatcher::OnInitialized() { |
30 | reader_.Init(channel(), base::Bind( | ||||
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 31 | &HostControlDispatcher::OnMessageReceived, base::Unretained(this))); |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 32 | writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 33 | } |
34 | |||||
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 35 | void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { |
36 | ControlMessage message; | ||||
37 | message.mutable_clipboard_event()->CopyFrom(event); | ||||
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 38 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 39 | } |
40 | |||||
[email protected] | d65e15bd | 2012-06-02 22:16:41 | [diff] [blame] | 41 | void HostControlDispatcher::SetCursorShape( |
42 | const CursorShapeInfo& cursor_shape) { | ||||
43 | ControlMessage message; | ||||
44 | message.mutable_cursor_shape()->CopyFrom(cursor_shape); | ||||
45 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); | ||||
46 | } | ||||
47 | |||||
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 48 | void HostControlDispatcher::OnMessageReceived( |
[email protected] | 9302fce | 2012-03-28 03:57:57 | [diff] [blame] | 49 | scoped_ptr<ControlMessage> message, const base::Closure& done_task) { |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 50 | DCHECK(clipboard_stub_); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 51 | DCHECK(host_stub_); |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 52 | |
53 | base::ScopedClosureRunner done_runner(done_task); | ||||
54 | |||||
55 | if (message->has_clipboard_event()) { | ||||
56 | clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); | ||||
[email protected] | 48a8ca3 | 2013-02-13 04:31:01 | [diff] [blame^] | 57 | } else if (message->has_client_resolution()) { |
58 | host_stub_->NotifyClientResolution(message->client_resolution()); | ||||
[email protected] | 50d71c7 | 2012-05-03 01:28:55 | [diff] [blame] | 59 | } else if (message->has_video_control()) { |
60 | host_stub_->ControlVideo(message->video_control()); | ||||
[email protected] | f458bed | 2012-10-18 03:27:59 | [diff] [blame] | 61 | } else if (message->has_audio_control()) { |
62 | host_stub_->ControlAudio(message->audio_control()); | ||||
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 63 | } else { |
64 | LOG(WARNING) << "Unknown control message received."; | ||||
65 | } | ||||
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 66 | } |
67 | |||||
68 | } // namespace protocol | ||||
69 | } // namespace remoting |