| 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/client_control_dispatcher.h" | 5 #include "remoting/protocol/client_control_dispatcher.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "net/socket/stream_socket.h" | 11 #include "net/socket/stream_socket.h" |
| 12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 13 #include "remoting/proto/control.pb.h" | 13 #include "remoting/proto/control.pb.h" |
| 14 #include "remoting/proto/internal.pb.h" | 14 #include "remoting/proto/internal.pb.h" |
| 15 #include "remoting/protocol/client_stub.h" | 15 #include "remoting/protocol/client_stub.h" |
| 16 #include "remoting/protocol/message_pipe.h" |
| 16 #include "remoting/protocol/message_serialization.h" | 17 #include "remoting/protocol/message_serialization.h" |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 namespace protocol { | 20 namespace protocol { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // 32-bit BGRA is 4 bytes per pixel. | 24 // 32-bit BGRA is 4 bytes per pixel. |
| 24 const int kBytesPerPixel = 4; | 25 const int kBytesPerPixel = 4; |
| 25 | 26 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } // namespace | 60 } // namespace |
| 60 | 61 |
| 61 ClientControlDispatcher::ClientControlDispatcher() | 62 ClientControlDispatcher::ClientControlDispatcher() |
| 62 : ChannelDispatcherBase(kControlChannelName) {} | 63 : ChannelDispatcherBase(kControlChannelName) {} |
| 63 ClientControlDispatcher::~ClientControlDispatcher() {} | 64 ClientControlDispatcher::~ClientControlDispatcher() {} |
| 64 | 65 |
| 65 void ClientControlDispatcher::InjectClipboardEvent( | 66 void ClientControlDispatcher::InjectClipboardEvent( |
| 66 const ClipboardEvent& event) { | 67 const ClipboardEvent& event) { |
| 67 ControlMessage message; | 68 ControlMessage message; |
| 68 message.mutable_clipboard_event()->CopyFrom(event); | 69 message.mutable_clipboard_event()->CopyFrom(event); |
| 69 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 70 message_pipe()->Send(&message, base::Closure()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void ClientControlDispatcher::NotifyClientResolution( | 73 void ClientControlDispatcher::NotifyClientResolution( |
| 73 const ClientResolution& resolution) { | 74 const ClientResolution& resolution) { |
| 74 ControlMessage message; | 75 ControlMessage message; |
| 75 message.mutable_client_resolution()->CopyFrom(resolution); | 76 message.mutable_client_resolution()->CopyFrom(resolution); |
| 76 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 77 message_pipe()->Send(&message, base::Closure()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void ClientControlDispatcher::ControlVideo(const VideoControl& video_control) { | 80 void ClientControlDispatcher::ControlVideo(const VideoControl& video_control) { |
| 80 ControlMessage message; | 81 ControlMessage message; |
| 81 message.mutable_video_control()->CopyFrom(video_control); | 82 message.mutable_video_control()->CopyFrom(video_control); |
| 82 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 83 message_pipe()->Send(&message, base::Closure()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void ClientControlDispatcher::ControlAudio(const AudioControl& audio_control) { | 86 void ClientControlDispatcher::ControlAudio(const AudioControl& audio_control) { |
| 86 ControlMessage message; | 87 ControlMessage message; |
| 87 message.mutable_audio_control()->CopyFrom(audio_control); | 88 message.mutable_audio_control()->CopyFrom(audio_control); |
| 88 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 89 message_pipe()->Send(&message, base::Closure()); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void ClientControlDispatcher::SetCapabilities( | 92 void ClientControlDispatcher::SetCapabilities( |
| 92 const Capabilities& capabilities) { | 93 const Capabilities& capabilities) { |
| 93 ControlMessage message; | 94 ControlMessage message; |
| 94 message.mutable_capabilities()->CopyFrom(capabilities); | 95 message.mutable_capabilities()->CopyFrom(capabilities); |
| 95 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 96 message_pipe()->Send(&message, base::Closure()); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void ClientControlDispatcher::RequestPairing( | 99 void ClientControlDispatcher::RequestPairing( |
| 99 const PairingRequest& pairing_request) { | 100 const PairingRequest& pairing_request) { |
| 100 ControlMessage message; | 101 ControlMessage message; |
| 101 message.mutable_pairing_request()->CopyFrom(pairing_request); | 102 message.mutable_pairing_request()->CopyFrom(pairing_request); |
| 102 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 103 message_pipe()->Send(&message, base::Closure()); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void ClientControlDispatcher::DeliverClientMessage( | 106 void ClientControlDispatcher::DeliverClientMessage( |
| 106 const ExtensionMessage& message) { | 107 const ExtensionMessage& message) { |
| 107 ControlMessage control_message; | 108 ControlMessage control_message; |
| 108 control_message.mutable_extension_message()->CopyFrom(message); | 109 control_message.mutable_extension_message()->CopyFrom(message); |
| 109 writer()->Write(SerializeAndFrameMessage(control_message), base::Closure()); | 110 message_pipe()->Send(&control_message, base::Closure()); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void ClientControlDispatcher::OnIncomingMessage( | 113 void ClientControlDispatcher::OnIncomingMessage( |
| 113 scoped_ptr<CompoundBuffer> buffer) { | 114 scoped_ptr<CompoundBuffer> buffer) { |
| 114 DCHECK(client_stub_); | 115 DCHECK(client_stub_); |
| 115 DCHECK(clipboard_stub_); | 116 DCHECK(clipboard_stub_); |
| 116 | 117 |
| 117 scoped_ptr<ControlMessage> message = | 118 scoped_ptr<ControlMessage> message = |
| 118 ParseMessage<ControlMessage>(buffer.get()); | 119 ParseMessage<ControlMessage>(buffer.get()); |
| 119 if (!message) | 120 if (!message) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 130 client_stub_->SetPairingResponse(message->pairing_response()); | 131 client_stub_->SetPairingResponse(message->pairing_response()); |
| 131 } else if (message->has_extension_message()) { | 132 } else if (message->has_extension_message()) { |
| 132 client_stub_->DeliverHostMessage(message->extension_message()); | 133 client_stub_->DeliverHostMessage(message->extension_message()); |
| 133 } else { | 134 } else { |
| 134 LOG(WARNING) << "Unknown control message received."; | 135 LOG(WARNING) << "Unknown control message received."; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 } // namespace protocol | 139 } // namespace protocol |
| 139 } // namespace remoting | 140 } // namespace remoting |
| OLD | NEW |