blob: 73bff85023361e3376ef4f8e96fe11e1c5e2ce90 [file] [log] [blame]
[email protected]e265ad72012-03-16 17:28:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]409ac612011-11-18 04:05:572// 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/client_control_dispatcher.h"
6
[email protected]c6944272012-01-06 22:12:287#include "base/bind_helpers.h"
8#include "base/callback.h"
[email protected]409ac612011-11-18 04:05:579#include "base/message_loop_proxy.h"
[email protected]2e8b52c2011-11-22 00:07:1310#include "net/socket/stream_socket.h"
11#include "remoting/base/constants.h"
[email protected]409ac612011-11-18 04:05:5712#include "remoting/proto/control.pb.h"
[email protected]409ac612011-11-18 04:05:5713#include "remoting/proto/internal.pb.h"
[email protected]2e8b52c2011-11-22 00:07:1314#include "remoting/protocol/buffered_socket_writer.h"
[email protected]409ac612011-11-18 04:05:5715#include "remoting/protocol/client_stub.h"
[email protected]e265ad72012-03-16 17:28:0316#include "remoting/protocol/util.h"
[email protected]409ac612011-11-18 04:05:5717
18namespace remoting {
19namespace protocol {
20
21ClientControlDispatcher::ClientControlDispatcher()
[email protected]2e8b52c2011-11-22 00:07:1322 : ChannelDispatcherBase(kControlChannelName),
23 client_stub_(NULL),
[email protected]ba6d1c2d2012-03-31 01:28:3824 clipboard_stub_(NULL),
[email protected]409ac612011-11-18 04:05:5725 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) {
26}
27
28ClientControlDispatcher::~ClientControlDispatcher() {
29 writer_->Close();
30}
31
[email protected]2e8b52c2011-11-22 00:07:1332void ClientControlDispatcher::OnInitialized() {
[email protected]409ac612011-11-18 04:05:5733 // TODO(garykac): Set write failed callback.
[email protected]2e8b52c2011-11-22 00:07:1334 writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback());
35 reader_.Init(channel(), base::Bind(
[email protected]409ac612011-11-18 04:05:5736 &ClientControlDispatcher::OnMessageReceived, base::Unretained(this)));
37}
38
[email protected]e265ad72012-03-16 17:28:0339void ClientControlDispatcher::InjectClipboardEvent(
40 const ClipboardEvent& event) {
41 ControlMessage message;
42 message.mutable_clipboard_event()->CopyFrom(event);
43 writer_->Write(SerializeAndFrameMessage(message), base::Closure());
44}
45
[email protected]f2b9cf32012-04-27 00:13:4346void ClientControlDispatcher::NotifyClientDimensions(
47 const ClientDimensions& dimensions) {
48 ControlMessage message;
49 message.mutable_client_dimensions()->CopyFrom(dimensions);
50 writer_->Write(SerializeAndFrameMessage(message), base::Closure());
51}
52
[email protected]50d71c72012-05-03 01:28:5553void ClientControlDispatcher::ControlVideo(const VideoControl& video_control) {
54 ControlMessage message;
55 message.mutable_video_control()->CopyFrom(video_control);
56 writer_->Write(SerializeAndFrameMessage(message), base::Closure());
57}
58
[email protected]409ac612011-11-18 04:05:5759void ClientControlDispatcher::OnMessageReceived(
[email protected]9302fce2012-03-28 03:57:5760 scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
[email protected]409ac612011-11-18 04:05:5761 DCHECK(client_stub_);
[email protected]ba6d1c2d2012-03-31 01:28:3862 DCHECK(clipboard_stub_);
[email protected]409ac612011-11-18 04:05:5763 base::ScopedClosureRunner done_runner(done_task);
[email protected]ba6d1c2d2012-03-31 01:28:3864
65 if (message->has_clipboard_event()) {
66 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
67 } else {
68 LOG(WARNING) << "Unknown control message received.";
69 }
[email protected]409ac612011-11-18 04:05:5770}
71
72} // namespace protocol
73} // namespace remoting