Roll src/third_party/WebKit 2dc4bc6:34469ea (svn 182261:182277)
[chromium-blink-merge.git] / remoting / protocol / host_control_dispatcher.cc
blobdfb7d181ec0f7f22b4836d91dfc53fd28bbae303
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 "base/message_loop/message_loop_proxy.h"
9 #include "net/socket/stream_socket.h"
10 #include "remoting/base/constants.h"
11 #include "remoting/proto/control.pb.h"
12 #include "remoting/proto/internal.pb.h"
13 #include "remoting/protocol/clipboard_stub.h"
14 #include "remoting/protocol/host_stub.h"
15 #include "remoting/protocol/message_serialization.h"
17 namespace remoting {
18 namespace protocol {
20 HostControlDispatcher::HostControlDispatcher()
21 : ChannelDispatcherBase(kControlChannelName),
22 clipboard_stub_(NULL),
23 host_stub_(NULL) {
26 HostControlDispatcher::~HostControlDispatcher() {
27 writer_.Close();
30 void HostControlDispatcher::OnInitialized() {
31 reader_.Init(channel(), base::Bind(
32 &HostControlDispatcher::OnMessageReceived, base::Unretained(this)));
33 writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback());
36 void HostControlDispatcher::SetCapabilities(
37 const Capabilities& capabilities) {
38 ControlMessage message;
39 message.mutable_capabilities()->CopyFrom(capabilities);
40 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
43 void HostControlDispatcher::SetPairingResponse(
44 const PairingResponse& pairing_response) {
45 ControlMessage message;
46 message.mutable_pairing_response()->CopyFrom(pairing_response);
47 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
50 void HostControlDispatcher::DeliverHostMessage(
51 const ExtensionMessage& message) {
52 ControlMessage control_message;
53 control_message.mutable_extension_message()->CopyFrom(message);
54 writer_.Write(SerializeAndFrameMessage(control_message), base::Closure());
57 void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
58 ControlMessage message;
59 message.mutable_clipboard_event()->CopyFrom(event);
60 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
63 void HostControlDispatcher::SetCursorShape(
64 const CursorShapeInfo& cursor_shape) {
65 ControlMessage message;
66 message.mutable_cursor_shape()->CopyFrom(cursor_shape);
67 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
70 void HostControlDispatcher::OnMessageReceived(
71 scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
72 DCHECK(clipboard_stub_);
73 DCHECK(host_stub_);
75 base::ScopedClosureRunner done_runner(done_task);
77 if (message->has_clipboard_event()) {
78 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
79 } else if (message->has_client_resolution()) {
80 host_stub_->NotifyClientResolution(message->client_resolution());
81 } else if (message->has_video_control()) {
82 host_stub_->ControlVideo(message->video_control());
83 } else if (message->has_audio_control()) {
84 host_stub_->ControlAudio(message->audio_control());
85 } else if (message->has_capabilities()) {
86 host_stub_->SetCapabilities(message->capabilities());
87 } else if (message->has_pairing_request()) {
88 host_stub_->RequestPairing(message->pairing_request());
89 } else if (message->has_extension_message()) {
90 host_stub_->DeliverClientMessage(message->extension_message());
91 } else {
92 LOG(WARNING) << "Unknown control message received.";
96 } // namespace protocol
97 } // namespace remoting