[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 2 | // 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] | c694427 | 2012-01-06 22:12:28 | [diff] [blame] | 7 | #include "base/bind_helpers.h" |
8 | #include "base/callback.h" | ||||
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 9 | #include "base/message_loop_proxy.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 10 | #include "net/socket/stream_socket.h" |
11 | #include "remoting/base/constants.h" | ||||
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 12 | #include "remoting/proto/control.pb.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 13 | #include "remoting/proto/internal.pb.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 14 | #include "remoting/protocol/buffered_socket_writer.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 15 | #include "remoting/protocol/client_stub.h" |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 16 | #include "remoting/protocol/util.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 17 | |
18 | namespace remoting { | ||||
19 | namespace protocol { | ||||
20 | |||||
21 | ClientControlDispatcher::ClientControlDispatcher() | ||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 22 | : ChannelDispatcherBase(kControlChannelName), |
23 | client_stub_(NULL), | ||||
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 24 | clipboard_stub_(NULL), |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 25 | writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { |
26 | } | ||||
27 | |||||
28 | ClientControlDispatcher::~ClientControlDispatcher() { | ||||
29 | writer_->Close(); | ||||
30 | } | ||||
31 | |||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 32 | void ClientControlDispatcher::OnInitialized() { |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 33 | // TODO(garykac): Set write failed callback. |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 34 | writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
35 | reader_.Init(channel(), base::Bind( | ||||
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 36 | &ClientControlDispatcher::OnMessageReceived, base::Unretained(this))); |
37 | } | ||||
38 | |||||
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 39 | void 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] | f2b9cf3 | 2012-04-27 00:13:43 | [diff] [blame] | 46 | void 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] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 53 | void ClientControlDispatcher::OnMessageReceived( |
[email protected] | 9302fce | 2012-03-28 03:57:57 | [diff] [blame] | 54 | scoped_ptr<ControlMessage> message, const base::Closure& done_task) { |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 55 | DCHECK(client_stub_); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 56 | DCHECK(clipboard_stub_); |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 57 | base::ScopedClosureRunner done_runner(done_task); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 58 | |
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] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 64 | } |
65 | |||||
66 | } // namespace protocol | ||||
67 | } // namespace remoting |