blob: db041b4c5510e7b0b87c1c7612d72380fa50d4b3 [file] [log] [blame]
[email protected]e265ad72012-03-16 17:28:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a07ef3d2011-11-18 01:31:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/protocol/host_control_dispatcher.h"
6
7#include "base/message_loop_proxy.h"
[email protected]2e8b52c2011-11-22 00:07:138#include "net/socket/stream_socket.h"
9#include "remoting/base/constants.h"
[email protected]a07ef3d2011-11-18 01:31:4310#include "remoting/proto/control.pb.h"
11#include "remoting/proto/internal.pb.h"
[email protected]e265ad72012-03-16 17:28:0312#include "remoting/protocol/clipboard_stub.h"
[email protected]a07ef3d2011-11-18 01:31:4313#include "remoting/protocol/host_stub.h"
[email protected]a07ef3d2011-11-18 01:31:4314#include "remoting/protocol/util.h"
15
16namespace remoting {
17namespace protocol {
18
19HostControlDispatcher::HostControlDispatcher()
[email protected]2e8b52c2011-11-22 00:07:1320 : ChannelDispatcherBase(kControlChannelName),
[email protected]e265ad72012-03-16 17:28:0321 clipboard_stub_(NULL),
[email protected]a3464dca2012-05-24 01:27:0922 host_stub_(NULL) {
[email protected]a07ef3d2011-11-18 01:31:4323}
24
25HostControlDispatcher::~HostControlDispatcher() {
[email protected]a3464dca2012-05-24 01:27:0926 writer_.Close();
[email protected]a07ef3d2011-11-18 01:31:4327}
28
[email protected]2e8b52c2011-11-22 00:07:1329void HostControlDispatcher::OnInitialized() {
30 reader_.Init(channel(), base::Bind(
[email protected]a07ef3d2011-11-18 01:31:4331 &HostControlDispatcher::OnMessageReceived, base::Unretained(this)));
[email protected]a3464dca2012-05-24 01:27:0932 writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback());
[email protected]a07ef3d2011-11-18 01:31:4333}
34
[email protected]ba6d1c2d2012-03-31 01:28:3835void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
36 ControlMessage message;
37 message.mutable_clipboard_event()->CopyFrom(event);
[email protected]a3464dca2012-05-24 01:27:0938 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
[email protected]ba6d1c2d2012-03-31 01:28:3839}
40
[email protected]d65e15bd2012-06-02 22:16:4141void HostControlDispatcher::SetCursorShape(
42 const CursorShapeInfo& cursor_shape) {
43 ControlMessage message;
44 message.mutable_cursor_shape()->CopyFrom(cursor_shape);
45 writer_.Write(SerializeAndFrameMessage(message), base::Closure());
46}
47
[email protected]a07ef3d2011-11-18 01:31:4348void HostControlDispatcher::OnMessageReceived(
[email protected]9302fce2012-03-28 03:57:5749 scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
[email protected]e265ad72012-03-16 17:28:0350 DCHECK(clipboard_stub_);
[email protected]a07ef3d2011-11-18 01:31:4351 DCHECK(host_stub_);
[email protected]e265ad72012-03-16 17:28:0352
53 base::ScopedClosureRunner done_runner(done_task);
54
55 if (message->has_clipboard_event()) {
56 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
[email protected]48a8ca32013-02-13 04:31:0157 } else if (message->has_client_resolution()) {
58 host_stub_->NotifyClientResolution(message->client_resolution());
[email protected]50d71c72012-05-03 01:28:5559 } else if (message->has_video_control()) {
60 host_stub_->ControlVideo(message->video_control());
[email protected]f458bed2012-10-18 03:27:5961 } else if (message->has_audio_control()) {
62 host_stub_->ControlAudio(message->audio_control());
[email protected]e265ad72012-03-16 17:28:0363 } else {
64 LOG(WARNING) << "Unknown control message received.";
65 }
[email protected]a07ef3d2011-11-18 01:31:4366}
67
68} // namespace protocol
69} // namespace remoting