OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/host_control_dispatcher.h" | 5 #include "remoting/protocol/host_control_dispatcher.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "net/socket/stream_socket.h" |
| 9 #include "remoting/base/constants.h" |
8 #include "remoting/proto/control.pb.h" | 10 #include "remoting/proto/control.pb.h" |
9 #include "remoting/proto/internal.pb.h" | 11 #include "remoting/proto/internal.pb.h" |
10 #include "remoting/protocol/buffered_socket_writer.h" | 12 #include "remoting/protocol/buffered_socket_writer.h" |
11 #include "remoting/protocol/host_stub.h" | 13 #include "remoting/protocol/host_stub.h" |
12 #include "remoting/protocol/session.h" | |
13 #include "remoting/protocol/util.h" | 14 #include "remoting/protocol/util.h" |
14 | 15 |
15 namespace remoting { | 16 namespace remoting { |
16 namespace protocol { | 17 namespace protocol { |
17 | 18 |
18 HostControlDispatcher::HostControlDispatcher() | 19 HostControlDispatcher::HostControlDispatcher() |
19 : host_stub_(NULL), | 20 : ChannelDispatcherBase(kControlChannelName), |
| 21 host_stub_(NULL), |
20 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { | 22 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { |
21 } | 23 } |
22 | 24 |
23 HostControlDispatcher::~HostControlDispatcher() { | 25 HostControlDispatcher::~HostControlDispatcher() { |
24 writer_->Close(); | 26 writer_->Close(); |
25 } | 27 } |
26 | 28 |
27 void HostControlDispatcher::Init(Session* session) { | 29 void HostControlDispatcher::OnInitialized() { |
28 DCHECK(session); | 30 reader_.Init(channel(), base::Bind( |
29 | |
30 reader_.Init(session->control_channel(), base::Bind( | |
31 &HostControlDispatcher::OnMessageReceived, base::Unretained(this))); | 31 &HostControlDispatcher::OnMessageReceived, base::Unretained(this))); |
32 writer_->Init(session->control_channel(), | 32 writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback()); |
33 BufferedSocketWriter::WriteFailedCallback()); | |
34 | 33 |
35 // Write legacy BeginSession message. | 34 // Write legacy BeginSession message. |
36 // TODO(sergeyu): Remove it. See http://crbug.com/104670 . | 35 // TODO(sergeyu): Remove it. See http://crbug.com/104670 . |
37 protocol::ControlMessage message; | 36 protocol::ControlMessage message; |
38 message.mutable_begin_session_deprecated()->mutable_login_status()-> | 37 message.mutable_begin_session_deprecated()->mutable_login_status()-> |
39 set_success(true); | 38 set_success(true); |
40 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); | 39 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); |
41 } | 40 } |
42 | 41 |
43 void HostControlDispatcher::OnMessageReceived( | 42 void HostControlDispatcher::OnMessageReceived( |
44 ControlMessage* message, const base::Closure& done_task) { | 43 ControlMessage* message, const base::Closure& done_task) { |
45 DCHECK(host_stub_); | 44 DCHECK(host_stub_); |
46 LOG(WARNING) << "Unknown control message received."; | 45 LOG(WARNING) << "Unknown control message received."; |
47 done_task.Run(); | 46 done_task.Run(); |
48 } | 47 } |
49 | 48 |
50 } // namespace protocol | 49 } // namespace protocol |
51 } // namespace remoting | 50 } // namespace remoting |
OLD | NEW |