[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [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/client_control_dispatcher.h" |
| 6 | |
[email protected] | c694427 | 2012-01-06 22:12:28 | [diff] [blame] | 7 | #include "base/bind_helpers.h" |
| 8 | #include "base/callback.h" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 9 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 10 | #include "net/socket/stream_socket.h" |
| 11 | #include "remoting/base/constants.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 12 | #include "remoting/proto/control.pb.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 13 | #include "remoting/proto/internal.pb.h" |
| 14 | #include "remoting/protocol/client_stub.h" |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 15 | #include "remoting/protocol/util.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 16 | |
| 17 | namespace remoting { |
| 18 | namespace protocol { |
| 19 | |
| 20 | ClientControlDispatcher::ClientControlDispatcher() |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 21 | : ChannelDispatcherBase(kControlChannelName), |
| 22 | client_stub_(NULL), |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 23 | clipboard_stub_(NULL) { |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | ClientControlDispatcher::~ClientControlDispatcher() { |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 27 | writer_.Close(); |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 30 | void ClientControlDispatcher::OnInitialized() { |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 31 | // TODO(garykac): Set write failed callback. |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 32 | writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 33 | reader_.Init(channel(), base::Bind( |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 34 | &ClientControlDispatcher::OnMessageReceived, base::Unretained(this))); |
| 35 | } |
| 36 | |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 37 | void ClientControlDispatcher::InjectClipboardEvent( |
| 38 | const ClipboardEvent& event) { |
| 39 | ControlMessage message; |
| 40 | message.mutable_clipboard_event()->CopyFrom(event); |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 41 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | 48a8ca3 | 2013-02-13 04:31:01 | [diff] [blame] | 44 | void ClientControlDispatcher::NotifyClientResolution( |
| 45 | const ClientResolution& resolution) { |
[email protected] | f2b9cf3 | 2012-04-27 00:13:43 | [diff] [blame] | 46 | ControlMessage message; |
[email protected] | 48a8ca3 | 2013-02-13 04:31:01 | [diff] [blame] | 47 | message.mutable_client_resolution()->CopyFrom(resolution); |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 48 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
[email protected] | f2b9cf3 | 2012-04-27 00:13:43 | [diff] [blame] | 49 | } |
| 50 | |
[email protected] | 50d71c7 | 2012-05-03 01:28:55 | [diff] [blame] | 51 | void ClientControlDispatcher::ControlVideo(const VideoControl& video_control) { |
| 52 | ControlMessage message; |
| 53 | message.mutable_video_control()->CopyFrom(video_control); |
[email protected] | a3464dca | 2012-05-24 01:27:09 | [diff] [blame] | 54 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
[email protected] | 50d71c7 | 2012-05-03 01:28:55 | [diff] [blame] | 55 | } |
| 56 | |
[email protected] | f458bed | 2012-10-18 03:27:59 | [diff] [blame] | 57 | void ClientControlDispatcher::ControlAudio(const AudioControl& audio_control) { |
| 58 | ControlMessage message; |
| 59 | message.mutable_audio_control()->CopyFrom(audio_control); |
| 60 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
| 61 | } |
| 62 | |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 63 | void ClientControlDispatcher::SetCapabilities( |
| 64 | const Capabilities& capabilities) { |
| 65 | ControlMessage message; |
| 66 | message.mutable_capabilities()->CopyFrom(capabilities); |
| 67 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
| 68 | } |
| 69 | |
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 70 | void ClientControlDispatcher::RequestPairing( |
| 71 | const PairingRequest& pairing_request) { |
| 72 | ControlMessage message; |
| 73 | message.mutable_pairing_request()->CopyFrom(pairing_request); |
| 74 | writer_.Write(SerializeAndFrameMessage(message), base::Closure()); |
| 75 | } |
| 76 | |
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame^] | 77 | void ClientControlDispatcher::DeliverClientMessage( |
| 78 | const ExtensionMessage& message) { |
| 79 | ControlMessage control_message; |
| 80 | control_message.mutable_extension_message()->CopyFrom(message); |
| 81 | writer_.Write(SerializeAndFrameMessage(control_message), base::Closure()); |
| 82 | } |
| 83 | |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 84 | void ClientControlDispatcher::OnMessageReceived( |
[email protected] | 9302fce | 2012-03-28 03:57:57 | [diff] [blame] | 85 | scoped_ptr<ControlMessage> message, const base::Closure& done_task) { |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 86 | DCHECK(client_stub_); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 87 | DCHECK(clipboard_stub_); |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 88 | base::ScopedClosureRunner done_runner(done_task); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 89 | |
| 90 | if (message->has_clipboard_event()) { |
| 91 | clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 92 | } else if (message->has_capabilities()) { |
| 93 | client_stub_->SetCapabilities(message->capabilities()); |
[email protected] | d65e15bd | 2012-06-02 22:16:41 | [diff] [blame] | 94 | } else if (message->has_cursor_shape()) { |
| 95 | client_stub_->SetCursorShape(message->cursor_shape()); |
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 96 | } else if (message->has_pairing_response()) { |
| 97 | client_stub_->SetPairingResponse(message->pairing_response()); |
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame^] | 98 | } else if (message->has_extension_message()) { |
| 99 | client_stub_->DeliverHostMessage(message->extension_message()); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 100 | } else { |
| 101 | LOG(WARNING) << "Unknown control message received."; |
| 102 | } |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | } // namespace protocol |
| 106 | } // namespace remoting |