[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
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] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 7 | #include "base/message_loop_proxy.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame^] | 8 | #include "net/socket/stream_socket.h" |
9 | #include "remoting/base/constants.h" | ||||
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 10 | #include "remoting/proto/control.pb.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 11 | #include "remoting/proto/internal.pb.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame^] | 12 | #include "remoting/protocol/buffered_socket_writer.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 13 | #include "remoting/protocol/client_stub.h" |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 14 | |
15 | namespace remoting { | ||||
16 | namespace protocol { | ||||
17 | |||||
18 | ClientControlDispatcher::ClientControlDispatcher() | ||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame^] | 19 | : ChannelDispatcherBase(kControlChannelName), |
20 | client_stub_(NULL), | ||||
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 21 | writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { |
22 | } | ||||
23 | |||||
24 | ClientControlDispatcher::~ClientControlDispatcher() { | ||||
25 | writer_->Close(); | ||||
26 | } | ||||
27 | |||||
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame^] | 28 | void ClientControlDispatcher::OnInitialized() { |
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 29 | // TODO(garykac): Set write failed callback. |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame^] | 30 | writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
31 | reader_.Init(channel(), base::Bind( | ||||
[email protected] | 409ac61 | 2011-11-18 04:05:57 | [diff] [blame] | 32 | &ClientControlDispatcher::OnMessageReceived, base::Unretained(this))); |
33 | } | ||||
34 | |||||
35 | void ClientControlDispatcher::OnMessageReceived( | ||||
36 | ControlMessage* message, const base::Closure& done_task) { | ||||
37 | DCHECK(client_stub_); | ||||
38 | |||||
39 | base::ScopedClosureRunner done_runner(done_task); | ||||
40 | |||||
41 | if (message->has_begin_session_deprecated()) { | ||||
42 | // Host sends legacy BeginSession message for compatibility with | ||||
43 | // older clients. Ignore it without warning. | ||||
44 | } else { | ||||
45 | LOG(WARNING) << "Unknown control message received."; | ||||
46 | } | ||||
47 | } | ||||
48 | |||||
49 | } // namespace protocol | ||||
50 | } // namespace remoting |