blob: 12bc795301757ad093611e7e74f97d3bb99ab2d9 [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]409ac612011-11-18 04:05:5753void ClientControlDispatcher::OnMessageReceived(
[email protected]9302fce2012-03-28 03:57:5754 scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
[email protected]409ac612011-11-18 04:05:5755 DCHECK(client_stub_);
[email protected]ba6d1c2d2012-03-31 01:28:3856 DCHECK(clipboard_stub_);
[email protected]409ac612011-11-18 04:05:5757 base::ScopedClosureRunner done_runner(done_task);
[email protected]ba6d1c2d2012-03-31 01:28:3858
59 if (message->has_clipboard_event()) {
60 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
61 } else {
62 LOG(WARNING) << "Unknown control message received.";
63 }
[email protected]409ac612011-11-18 04:05:5764}
65
66} // namespace protocol
67} // namespace remoting