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/channel_dispatcher_base.h" | 5 #include "remoting/protocol/channel_dispatcher_base.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "remoting/protocol/p2p_stream_socket.h" | 10 #include "remoting/protocol/p2p_stream_socket.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 void ChannelDispatcherBase::OnChannelReady( | 36 void ChannelDispatcherBase::OnChannelReady( |
37 scoped_ptr<P2PStreamSocket> socket) { | 37 scoped_ptr<P2PStreamSocket> socket) { |
38 if (!socket.get()) { | 38 if (!socket.get()) { |
39 event_handler_->OnChannelError(this, CHANNEL_CONNECTION_ERROR); | 39 event_handler_->OnChannelError(this, CHANNEL_CONNECTION_ERROR); |
40 return; | 40 return; |
41 } | 41 } |
42 | 42 |
43 channel_factory_ = nullptr; | 43 channel_factory_ = nullptr; |
44 channel_ = std::move(socket); | 44 message_pipe_.Initialize( |
45 writer_.Start( | 45 std::move(socket), |
46 base::Bind(&P2PStreamSocket::Write, base::Unretained(channel_.get())), | 46 base::Bind(&ChannelDispatcherBase::OnPipeError, base::Unretained(this))); |
47 base::Bind(&ChannelDispatcherBase::OnReadWriteFailed, | 47 message_pipe_.StartReceiving(base::Bind( |
48 base::Unretained(this))); | 48 &ChannelDispatcherBase::OnIncomingMessage, base::Unretained(this))); |
49 reader_.StartReading(channel_.get(), | |
50 base::Bind(&ChannelDispatcherBase::OnIncomingMessage, | |
51 base::Unretained(this)), | |
52 base::Bind(&ChannelDispatcherBase::OnReadWriteFailed, | |
53 base::Unretained(this))); | |
54 | 49 |
55 event_handler_->OnChannelInitialized(this); | 50 event_handler_->OnChannelInitialized(this); |
56 } | 51 } |
57 | 52 |
58 void ChannelDispatcherBase::OnIncomingMessage( | 53 void ChannelDispatcherBase::OnIncomingMessage( |
59 scoped_ptr<CompoundBuffer> message) { | 54 scoped_ptr<CompoundBuffer> message) { |
60 // By default incoming message are not expected. Child classes override | 55 // By default incoming message are not expected. Child classes override |
61 // OnIncomingMessage() if the want to handle incoming messages. | 56 // OnIncomingMessage() if the want to handle incoming messages. |
62 LOG(ERROR) << "Received unexpected message on " << channel_name(); | 57 LOG(ERROR) << "Received unexpected message on " << channel_name(); |
63 } | 58 } |
64 | 59 |
65 void ChannelDispatcherBase::OnReadWriteFailed(int error) { | 60 void ChannelDispatcherBase::OnPipeError(int error) { |
66 event_handler_->OnChannelError(this, CHANNEL_CONNECTION_ERROR); | 61 event_handler_->OnChannelError(this, CHANNEL_CONNECTION_ERROR); |
67 } | 62 } |
68 | 63 |
69 } // namespace protocol | 64 } // namespace protocol |
70 } // namespace remoting | 65 } // namespace remoting |
OLD | NEW |