OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/client_control_dispatcher.h" | 5 #include "remoting/protocol/client_control_dispatcher.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "net/socket/stream_socket.h" | 10 #include "net/socket/stream_socket.h" |
11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
12 #include "remoting/proto/control.pb.h" | 12 #include "remoting/proto/control.pb.h" |
13 #include "remoting/proto/internal.pb.h" | 13 #include "remoting/proto/internal.pb.h" |
14 #include "remoting/protocol/buffered_socket_writer.h" | 14 #include "remoting/protocol/buffered_socket_writer.h" |
15 #include "remoting/protocol/client_stub.h" | 15 #include "remoting/protocol/client_stub.h" |
16 #include "remoting/protocol/util.h" | 16 #include "remoting/protocol/util.h" |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 namespace protocol { | 19 namespace protocol { |
20 | 20 |
21 ClientControlDispatcher::ClientControlDispatcher() | 21 ClientControlDispatcher::ClientControlDispatcher() |
22 : ChannelDispatcherBase(kControlChannelName), | 22 : ChannelDispatcherBase(kControlChannelName), |
23 client_stub_(NULL), | 23 client_stub_(NULL), |
24 clipboard_stub_(NULL), | |
24 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { | 25 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { |
25 } | 26 } |
26 | 27 |
27 ClientControlDispatcher::~ClientControlDispatcher() { | 28 ClientControlDispatcher::~ClientControlDispatcher() { |
28 writer_->Close(); | 29 writer_->Close(); |
29 } | 30 } |
30 | 31 |
31 void ClientControlDispatcher::OnInitialized() { | 32 void ClientControlDispatcher::OnInitialized() { |
32 // TODO(garykac): Set write failed callback. | 33 // TODO(garykac): Set write failed callback. |
33 writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback()); | 34 writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
34 reader_.Init(channel(), base::Bind( | 35 reader_.Init(channel(), base::Bind( |
35 &ClientControlDispatcher::OnMessageReceived, base::Unretained(this))); | 36 &ClientControlDispatcher::OnMessageReceived, base::Unretained(this))); |
36 } | 37 } |
37 | 38 |
38 void ClientControlDispatcher::InjectClipboardEvent( | 39 void ClientControlDispatcher::InjectClipboardEvent( |
39 const ClipboardEvent& event) { | 40 const ClipboardEvent& event) { |
40 ControlMessage message; | 41 ControlMessage message; |
41 message.mutable_clipboard_event()->CopyFrom(event); | 42 message.mutable_clipboard_event()->CopyFrom(event); |
42 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); | 43 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); |
43 } | 44 } |
44 | 45 |
45 void ClientControlDispatcher::OnMessageReceived( | 46 void ClientControlDispatcher::OnMessageReceived( |
46 scoped_ptr<ControlMessage> message, const base::Closure& done_task) { | 47 scoped_ptr<ControlMessage> message, const base::Closure& done_task) { |
47 DCHECK(client_stub_); | 48 DCHECK(client_stub_); |
49 DCHECK(clipboard_stub_); | |
Wez
2012/03/30 22:20:15
not for this CL: It feels like these checks belong
simonmorris
2012/03/30 22:36:07
Could be, though the stubs are used here.
Wez
2012/03/31 00:38:46
True. Checking in OnMessageReceived() risks us mi
| |
48 base::ScopedClosureRunner done_runner(done_task); | 50 base::ScopedClosureRunner done_runner(done_task); |
49 LOG(WARNING) << "Unknown control message received."; | 51 |
52 if (message->has_clipboard_event()) { | |
53 clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); | |
54 } else { | |
55 LOG(WARNING) << "Unknown control message received."; | |
56 } | |
50 } | 57 } |
51 | 58 |
52 } // namespace protocol | 59 } // namespace protocol |
53 } // namespace remoting | 60 } // namespace remoting |
OLD | NEW |