| 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 "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "net/socket/stream_socket.h" | 9 #include "net/socket/stream_socket.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| 11 #include "remoting/proto/control.pb.h" | 11 #include "remoting/proto/control.pb.h" |
| 12 #include "remoting/proto/internal.pb.h" | 12 #include "remoting/proto/internal.pb.h" |
| 13 #include "remoting/protocol/clipboard_stub.h" | 13 #include "remoting/protocol/clipboard_stub.h" |
| 14 #include "remoting/protocol/host_stub.h" | 14 #include "remoting/protocol/host_stub.h" |
| 15 #include "remoting/protocol/message_serialization.h" | 15 #include "remoting/protocol/message_serialization.h" |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 namespace protocol { | 18 namespace protocol { |
| 19 | 19 |
| 20 HostControlDispatcher::HostControlDispatcher() | 20 HostControlDispatcher::HostControlDispatcher() |
| 21 : ChannelDispatcherBase(kControlChannelName), | 21 : ChannelDispatcherBase(kControlChannelName), |
| 22 clipboard_stub_(nullptr), | 22 clipboard_stub_(nullptr), |
| 23 host_stub_(nullptr) { | 23 host_stub_(nullptr), |
| 24 parser_(base::Bind(&HostControlDispatcher::OnMessageReceived, |
| 25 base::Unretained(this)), |
| 26 reader()) { |
| 24 } | 27 } |
| 25 | 28 |
| 26 HostControlDispatcher::~HostControlDispatcher() { | 29 HostControlDispatcher::~HostControlDispatcher() { |
| 27 writer_.Close(); | |
| 28 } | |
| 29 | |
| 30 void HostControlDispatcher::OnInitialized() { | |
| 31 reader_.Init(channel(), base::Bind( | |
| 32 &HostControlDispatcher::OnMessageReceived, base::Unretained(this))); | |
| 33 writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback()); | |
| 34 } | 30 } |
| 35 | 31 |
| 36 void HostControlDispatcher::SetCapabilities( | 32 void HostControlDispatcher::SetCapabilities( |
| 37 const Capabilities& capabilities) { | 33 const Capabilities& capabilities) { |
| 38 ControlMessage message; | 34 ControlMessage message; |
| 39 message.mutable_capabilities()->CopyFrom(capabilities); | 35 message.mutable_capabilities()->CopyFrom(capabilities); |
| 40 writer_.Write(SerializeAndFrameMessage(message), base::Closure()); | 36 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 41 } | 37 } |
| 42 | 38 |
| 43 void HostControlDispatcher::SetPairingResponse( | 39 void HostControlDispatcher::SetPairingResponse( |
| 44 const PairingResponse& pairing_response) { | 40 const PairingResponse& pairing_response) { |
| 45 ControlMessage message; | 41 ControlMessage message; |
| 46 message.mutable_pairing_response()->CopyFrom(pairing_response); | 42 message.mutable_pairing_response()->CopyFrom(pairing_response); |
| 47 writer_.Write(SerializeAndFrameMessage(message), base::Closure()); | 43 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 48 } | 44 } |
| 49 | 45 |
| 50 void HostControlDispatcher::DeliverHostMessage( | 46 void HostControlDispatcher::DeliverHostMessage( |
| 51 const ExtensionMessage& message) { | 47 const ExtensionMessage& message) { |
| 52 ControlMessage control_message; | 48 ControlMessage control_message; |
| 53 control_message.mutable_extension_message()->CopyFrom(message); | 49 control_message.mutable_extension_message()->CopyFrom(message); |
| 54 writer_.Write(SerializeAndFrameMessage(control_message), base::Closure()); | 50 writer()->Write(SerializeAndFrameMessage(control_message), base::Closure()); |
| 55 } | 51 } |
| 56 | 52 |
| 57 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { | 53 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { |
| 58 ControlMessage message; | 54 ControlMessage message; |
| 59 message.mutable_clipboard_event()->CopyFrom(event); | 55 message.mutable_clipboard_event()->CopyFrom(event); |
| 60 writer_.Write(SerializeAndFrameMessage(message), base::Closure()); | 56 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 61 } | 57 } |
| 62 | 58 |
| 63 void HostControlDispatcher::SetCursorShape( | 59 void HostControlDispatcher::SetCursorShape( |
| 64 const CursorShapeInfo& cursor_shape) { | 60 const CursorShapeInfo& cursor_shape) { |
| 65 ControlMessage message; | 61 ControlMessage message; |
| 66 message.mutable_cursor_shape()->CopyFrom(cursor_shape); | 62 message.mutable_cursor_shape()->CopyFrom(cursor_shape); |
| 67 writer_.Write(SerializeAndFrameMessage(message), base::Closure()); | 63 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 68 } | 64 } |
| 69 | 65 |
| 70 void HostControlDispatcher::OnMessageReceived( | 66 void HostControlDispatcher::OnMessageReceived( |
| 71 scoped_ptr<ControlMessage> message, const base::Closure& done_task) { | 67 scoped_ptr<ControlMessage> message, const base::Closure& done_task) { |
| 72 DCHECK(clipboard_stub_); | 68 DCHECK(clipboard_stub_); |
| 73 DCHECK(host_stub_); | 69 DCHECK(host_stub_); |
| 74 | 70 |
| 75 base::ScopedClosureRunner done_runner(done_task); | 71 base::ScopedClosureRunner done_runner(done_task); |
| 76 | 72 |
| 77 if (message->has_clipboard_event()) { | 73 if (message->has_clipboard_event()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 host_stub_->RequestPairing(message->pairing_request()); | 84 host_stub_->RequestPairing(message->pairing_request()); |
| 89 } else if (message->has_extension_message()) { | 85 } else if (message->has_extension_message()) { |
| 90 host_stub_->DeliverClientMessage(message->extension_message()); | 86 host_stub_->DeliverClientMessage(message->extension_message()); |
| 91 } else { | 87 } else { |
| 92 LOG(WARNING) << "Unknown control message received."; | 88 LOG(WARNING) << "Unknown control message received."; |
| 93 } | 89 } |
| 94 } | 90 } |
| 95 | 91 |
| 96 } // namespace protocol | 92 } // namespace protocol |
| 97 } // namespace remoting | 93 } // namespace remoting |
| OLD | NEW |