[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 | |
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 7 | #include "base/callback_helpers.h" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 8 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 9 | #include "net/socket/stream_socket.h" |
| 10 | #include "remoting/base/constants.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 11 | #include "remoting/proto/control.pb.h" |
| 12 | #include "remoting/proto/internal.pb.h" |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 13 | #include "remoting/protocol/clipboard_stub.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 14 | #include "remoting/protocol/host_stub.h" |
[email protected] | b76a274 | 2014-04-10 05:38:26 | [diff] [blame^] | 15 | #include "remoting/protocol/message_serialization.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 16 | |
| 17 | namespace remoting { |
| 18 | namespace protocol { |
| 19 | |
| 20 | HostControlDispatcher::HostControlDispatcher() |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 21 | : ChannelDispatcherBase(kControlChannelName), |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 22 | clipboard_stub_(NULL), |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 23 | host_stub_(NULL) { |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | HostControlDispatcher::~HostControlDispatcher() { |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 27 | writer_.Close(); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 30 | void HostControlDispatcher::OnInitialized() { |
| 31 | reader_.Init(channel(), base::Bind( |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 32 | &HostControlDispatcher::OnMessageReceived, base::Unretained(this))); |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 33 | writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 34 | } |
| 35 | |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 36 | void HostControlDispatcher::SetCapabilities( |
| 37 | const Capabilities& capabilities) { |
| 38 | ControlMessage message; |
| 39 | message.mutable_capabilities()->CopyFrom(capabilities); |
| 40 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
| 41 | } |
| 42 | |
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 43 | void HostControlDispatcher::SetPairingResponse( |
| 44 | const PairingResponse& pairing_response) { |
| 45 | ControlMessage message; |
| 46 | message.mutable_pairing_response()->CopyFrom(pairing_response); |
| 47 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
| 48 | } |
| 49 | |
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame] | 50 | void HostControlDispatcher::DeliverHostMessage( |
| 51 | const ExtensionMessage& message) { |
| 52 | ControlMessage control_message; |
| 53 | control_message.mutable_extension_message()->CopyFrom(message); |
| 54 | writer_.Write(SerializeAndFrameMessage(control_message), base::Closure()); |
| 55 | } |
| 56 | |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 57 | void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { |
| 58 | ControlMessage message; |
| 59 | message.mutable_clipboard_event()->CopyFrom(event); |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 60 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 61 | } |
| 62 | |
[email protected] | d65e15bd | 2012-06-02 22:16:41 | [diff] [blame] | 63 | void HostControlDispatcher::SetCursorShape( |
| 64 | const CursorShapeInfo& cursor_shape) { |
| 65 | ControlMessage message; |
| 66 | message.mutable_cursor_shape()->CopyFrom(cursor_shape); |
| 67 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
| 68 | } |
| 69 | |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 70 | void HostControlDispatcher::OnMessageReceived( |
[email protected] | 9302fce | 2012-03-28 03:57:57 | [diff] [blame] | 71 | scoped_ptr<ControlMessage> message, const base::Closure& done_task) { |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 72 | DCHECK(clipboard_stub_); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 73 | DCHECK(host_stub_); |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 74 | |
| 75 | base::ScopedClosureRunner done_runner(done_task); |
| 76 | |
| 77 | if (message->has_clipboard_event()) { |
| 78 | clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); |
[email protected] | 48a8ca3 | 2013-02-13 04:31:01 | [diff] [blame] | 79 | } else if (message->has_client_resolution()) { |
| 80 | host_stub_->NotifyClientResolution(message->client_resolution()); |
[email protected] | 50d71c7 | 2012-05-03 01:28:55 | [diff] [blame] | 81 | } else if (message->has_video_control()) { |
| 82 | host_stub_->ControlVideo(message->video_control()); |
[email protected] | f458bed | 2012-10-18 03:27:59 | [diff] [blame] | 83 | } else if (message->has_audio_control()) { |
| 84 | host_stub_->ControlAudio(message->audio_control()); |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 85 | } else if (message->has_capabilities()) { |
| 86 | host_stub_->SetCapabilities(message->capabilities()); |
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 87 | } else if (message->has_pairing_request()) { |
| 88 | host_stub_->RequestPairing(message->pairing_request()); |
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame] | 89 | } else if (message->has_extension_message()) { |
| 90 | host_stub_->DeliverClientMessage(message->extension_message()); |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 91 | } else { |
| 92 | LOG(WARNING) << "Unknown control message received."; |
| 93 | } |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | } // namespace protocol |
| 97 | } // namespace remoting |