| 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_pipe.h" |
| 14 #include "remoting/protocol/message_serialization.h" | 15 #include "remoting/protocol/message_serialization.h" |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| 17 namespace protocol { | 18 namespace protocol { |
| 18 | 19 |
| 19 HostControlDispatcher::HostControlDispatcher() | 20 HostControlDispatcher::HostControlDispatcher() |
| 20 : ChannelDispatcherBase(kControlChannelName) {} | 21 : ChannelDispatcherBase(kControlChannelName) {} |
| 21 HostControlDispatcher::~HostControlDispatcher() {} | 22 HostControlDispatcher::~HostControlDispatcher() {} |
| 22 | 23 |
| 23 void HostControlDispatcher::SetCapabilities( | 24 void HostControlDispatcher::SetCapabilities( |
| 24 const Capabilities& capabilities) { | 25 const Capabilities& capabilities) { |
| 25 ControlMessage message; | 26 ControlMessage message; |
| 26 message.mutable_capabilities()->CopyFrom(capabilities); | 27 message.mutable_capabilities()->CopyFrom(capabilities); |
| 27 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 28 message_pipe()->Send(&message, base::Closure()); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void HostControlDispatcher::SetPairingResponse( | 31 void HostControlDispatcher::SetPairingResponse( |
| 31 const PairingResponse& pairing_response) { | 32 const PairingResponse& pairing_response) { |
| 32 ControlMessage message; | 33 ControlMessage message; |
| 33 message.mutable_pairing_response()->CopyFrom(pairing_response); | 34 message.mutable_pairing_response()->CopyFrom(pairing_response); |
| 34 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 35 message_pipe()->Send(&message, base::Closure()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void HostControlDispatcher::DeliverHostMessage( | 38 void HostControlDispatcher::DeliverHostMessage( |
| 38 const ExtensionMessage& message) { | 39 const ExtensionMessage& message) { |
| 39 ControlMessage control_message; | 40 ControlMessage control_message; |
| 40 control_message.mutable_extension_message()->CopyFrom(message); | 41 control_message.mutable_extension_message()->CopyFrom(message); |
| 41 writer()->Write(SerializeAndFrameMessage(control_message), base::Closure()); | 42 message_pipe()->Send(&control_message, base::Closure()); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { | 45 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { |
| 45 ControlMessage message; | 46 ControlMessage message; |
| 46 message.mutable_clipboard_event()->CopyFrom(event); | 47 message.mutable_clipboard_event()->CopyFrom(event); |
| 47 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 48 message_pipe()->Send(&message, base::Closure()); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void HostControlDispatcher::SetCursorShape( | 51 void HostControlDispatcher::SetCursorShape( |
| 51 const CursorShapeInfo& cursor_shape) { | 52 const CursorShapeInfo& cursor_shape) { |
| 52 ControlMessage message; | 53 ControlMessage message; |
| 53 message.mutable_cursor_shape()->CopyFrom(cursor_shape); | 54 message.mutable_cursor_shape()->CopyFrom(cursor_shape); |
| 54 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 55 message_pipe()->Send(&message, base::Closure()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void HostControlDispatcher::OnIncomingMessage( | 58 void HostControlDispatcher::OnIncomingMessage( |
| 58 scoped_ptr<CompoundBuffer> buffer) { | 59 scoped_ptr<CompoundBuffer> buffer) { |
| 59 DCHECK(clipboard_stub_); | 60 DCHECK(clipboard_stub_); |
| 60 DCHECK(host_stub_); | 61 DCHECK(host_stub_); |
| 61 | 62 |
| 62 scoped_ptr<ControlMessage> message = | 63 scoped_ptr<ControlMessage> message = |
| 63 ParseMessage<ControlMessage>(buffer.get()); | 64 ParseMessage<ControlMessage>(buffer.get()); |
| 64 if (!message) | 65 if (!message) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 host_stub_->RequestPairing(message->pairing_request()); | 79 host_stub_->RequestPairing(message->pairing_request()); |
| 79 } else if (message->has_extension_message()) { | 80 } else if (message->has_extension_message()) { |
| 80 host_stub_->DeliverClientMessage(message->extension_message()); | 81 host_stub_->DeliverClientMessage(message->extension_message()); |
| 81 } else { | 82 } else { |
| 82 LOG(WARNING) << "Unknown control message received."; | 83 LOG(WARNING) << "Unknown control message received."; |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 } // namespace protocol | 87 } // namespace protocol |
| 87 } // namespace remoting | 88 } // namespace remoting |
| OLD | NEW |