MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / remoting / protocol / host_control_dispatcher.cc
blob3b11fc1fa3df09052481898c1c55173644bb689c
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
3 // found in the LICENSE file.
5 #include "remoting/protocol/host_control_dispatcher.h"
7 #include "base/callback_helpers.h"
8 #include "net/socket/stream_socket.h"
9 #include "remoting/base/constants.h"
10 #include "remoting/proto/control.pb.h"
11 #include "remoting/proto/internal.pb.h"
12 #include "remoting/protocol/clipboard_stub.h"
13 #include "remoting/protocol/host_stub.h"
14 #include "remoting/protocol/message_serialization.h"
16 namespace remoting {
17 namespace protocol {
19 HostControlDispatcher::HostControlDispatcher()
20 : ChannelDispatcherBase(kControlChannelName),
21 clipboard_stub_(nullptr),
22 host_stub_(nullptr),
23 parser_(base::Bind(&HostControlDispatcher::OnMessageReceived,
24 base::Unretained(this)),
25 reader()) {
28 HostControlDispatcher::~HostControlDispatcher() {
31 void HostControlDispatcher::SetCapabilities(
32 const Capabilities& capabilities) {
33 ControlMessage message;
34 message.mutable_capabilities()->CopyFrom(capabilities);
35 writer()->Write(SerializeAndFrameMessage(message), base::Closure());
38 void HostControlDispatcher::SetPairingResponse(
39 const PairingResponse& pairing_response) {
40 ControlMessage message;
41 message.mutable_pairing_response()->CopyFrom(pairing_response);
42 writer()->Write(SerializeAndFrameMessage(message), base::Closure());
45 void HostControlDispatcher::DeliverHostMessage(
46 const ExtensionMessage& message) {
47 ControlMessage control_message;
48 control_message.mutable_extension_message()->CopyFrom(message);
49 writer()->Write(SerializeAndFrameMessage(control_message), base::Closure());
52 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
53 ControlMessage message;
54 message.mutable_clipboard_event()->CopyFrom(event);
55 writer()->Write(SerializeAndFrameMessage(message), base::Closure());
58 void HostControlDispatcher::SetCursorShape(
59 const CursorShapeInfo& cursor_shape) {
60 ControlMessage message;
61 message.mutable_cursor_shape()->CopyFrom(cursor_shape);
62 writer()->Write(SerializeAndFrameMessage(message), base::Closure());
65 void HostControlDispatcher::OnMessageReceived(
66 scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
67 DCHECK(clipboard_stub_);
68 DCHECK(host_stub_);
70 base::ScopedClosureRunner done_runner(done_task);
72 if (message->has_clipboard_event()) {
73 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
74 } else if (message->has_client_resolution()) {
75 host_stub_->NotifyClientResolution(message->client_resolution());
76 } else if (message->has_video_control()) {
77 host_stub_->ControlVideo(message->video_control());
78 } else if (message->has_audio_control()) {
79 host_stub_->ControlAudio(message->audio_control());
80 } else if (message->has_capabilities()) {
81 host_stub_->SetCapabilities(message->capabilities());
82 } else if (message->has_pairing_request()) {
83 host_stub_->RequestPairing(message->pairing_request());
84 } else if (message->has_extension_message()) {
85 host_stub_->DeliverClientMessage(message->extension_message());
86 } else {
87 LOG(WARNING) << "Unknown control message received.";
91 } // namespace protocol
92 } // namespace remoting