| 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/protocol/host_control_dispatcher.h" | 5 #include "remoting/protocol/host_control_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "net/socket/stream_socket.h" | 8 #include "net/socket/stream_socket.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/proto/control.pb.h" | 10 #include "remoting/proto/control.pb.h" |
| 11 #include "remoting/proto/internal.pb.h" | 11 #include "remoting/proto/internal.pb.h" |
| 12 #include "remoting/protocol/clipboard_stub.h" | 12 #include "remoting/protocol/clipboard_stub.h" |
| 13 #include "remoting/protocol/host_stub.h" | 13 #include "remoting/protocol/host_stub.h" |
| 14 #include "remoting/protocol/message_serialization.h" | 14 #include "remoting/protocol/message_serialization.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 namespace protocol { | 17 namespace protocol { |
| 18 | 18 |
| 19 HostControlDispatcher::HostControlDispatcher() | 19 HostControlDispatcher::HostControlDispatcher() |
| 20 : ChannelDispatcherBase(kControlChannelName), | 20 : ChannelDispatcherBase(kControlChannelName) {} |
| 21 clipboard_stub_(nullptr), | 21 HostControlDispatcher::~HostControlDispatcher() {} |
| 22 host_stub_(nullptr), | |
| 23 parser_(base::Bind(&HostControlDispatcher::OnMessageReceived, | |
| 24 base::Unretained(this)), | |
| 25 reader()) { | |
| 26 } | |
| 27 | |
| 28 HostControlDispatcher::~HostControlDispatcher() { | |
| 29 } | |
| 30 | 22 |
| 31 void HostControlDispatcher::SetCapabilities( | 23 void HostControlDispatcher::SetCapabilities( |
| 32 const Capabilities& capabilities) { | 24 const Capabilities& capabilities) { |
| 33 ControlMessage message; | 25 ControlMessage message; |
| 34 message.mutable_capabilities()->CopyFrom(capabilities); | 26 message.mutable_capabilities()->CopyFrom(capabilities); |
| 35 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 27 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 36 } | 28 } |
| 37 | 29 |
| 38 void HostControlDispatcher::SetPairingResponse( | 30 void HostControlDispatcher::SetPairingResponse( |
| 39 const PairingResponse& pairing_response) { | 31 const PairingResponse& pairing_response) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 55 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 47 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 56 } | 48 } |
| 57 | 49 |
| 58 void HostControlDispatcher::SetCursorShape( | 50 void HostControlDispatcher::SetCursorShape( |
| 59 const CursorShapeInfo& cursor_shape) { | 51 const CursorShapeInfo& cursor_shape) { |
| 60 ControlMessage message; | 52 ControlMessage message; |
| 61 message.mutable_cursor_shape()->CopyFrom(cursor_shape); | 53 message.mutable_cursor_shape()->CopyFrom(cursor_shape); |
| 62 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 54 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 63 } | 55 } |
| 64 | 56 |
| 65 void HostControlDispatcher::OnMessageReceived( | 57 void HostControlDispatcher::OnIncomingMessage( |
| 66 scoped_ptr<ControlMessage> message) { | 58 scoped_ptr<CompoundBuffer> buffer) { |
| 67 DCHECK(clipboard_stub_); | 59 DCHECK(clipboard_stub_); |
| 68 DCHECK(host_stub_); | 60 DCHECK(host_stub_); |
| 69 | 61 |
| 62 scoped_ptr<ControlMessage> message = |
| 63 ParseMessage<ControlMessage>(buffer.get()); |
| 64 if (!message) |
| 65 return; |
| 66 |
| 70 if (message->has_clipboard_event()) { | 67 if (message->has_clipboard_event()) { |
| 71 clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); | 68 clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); |
| 72 } else if (message->has_client_resolution()) { | 69 } else if (message->has_client_resolution()) { |
| 73 host_stub_->NotifyClientResolution(message->client_resolution()); | 70 host_stub_->NotifyClientResolution(message->client_resolution()); |
| 74 } else if (message->has_video_control()) { | 71 } else if (message->has_video_control()) { |
| 75 host_stub_->ControlVideo(message->video_control()); | 72 host_stub_->ControlVideo(message->video_control()); |
| 76 } else if (message->has_audio_control()) { | 73 } else if (message->has_audio_control()) { |
| 77 host_stub_->ControlAudio(message->audio_control()); | 74 host_stub_->ControlAudio(message->audio_control()); |
| 78 } else if (message->has_capabilities()) { | 75 } else if (message->has_capabilities()) { |
| 79 host_stub_->SetCapabilities(message->capabilities()); | 76 host_stub_->SetCapabilities(message->capabilities()); |
| 80 } else if (message->has_pairing_request()) { | 77 } else if (message->has_pairing_request()) { |
| 81 host_stub_->RequestPairing(message->pairing_request()); | 78 host_stub_->RequestPairing(message->pairing_request()); |
| 82 } else if (message->has_extension_message()) { | 79 } else if (message->has_extension_message()) { |
| 83 host_stub_->DeliverClientMessage(message->extension_message()); | 80 host_stub_->DeliverClientMessage(message->extension_message()); |
| 84 } else { | 81 } else { |
| 85 LOG(WARNING) << "Unknown control message received."; | 82 LOG(WARNING) << "Unknown control message received."; |
| 86 } | 83 } |
| 87 } | 84 } |
| 88 | 85 |
| 89 } // namespace protocol | 86 } // namespace protocol |
| 90 } // namespace remoting | 87 } // namespace remoting |
| OLD | NEW |