OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/stream_message_pipe_adapter.h" | 5 #include "remoting/protocol/stream_message_pipe_adapter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "net/base/net_errors.h" |
11 #include "remoting/base/buffered_socket_writer.h" | 12 #include "remoting/base/buffered_socket_writer.h" |
12 #include "remoting/base/compound_buffer.h" | 13 #include "remoting/base/compound_buffer.h" |
13 #include "remoting/protocol/message_serialization.h" | 14 #include "remoting/protocol/message_serialization.h" |
14 #include "remoting/protocol/p2p_stream_socket.h" | 15 #include "remoting/protocol/p2p_stream_socket.h" |
| 16 #include "remoting/protocol/stream_channel_factory.h" |
15 | 17 |
16 namespace remoting { | 18 namespace remoting { |
17 namespace protocol { | 19 namespace protocol { |
18 | 20 |
19 StreamMessagePipeAdapter::StreamMessagePipeAdapter( | 21 StreamMessagePipeAdapter::StreamMessagePipeAdapter( |
20 scoped_ptr<P2PStreamSocket> socket, | 22 scoped_ptr<P2PStreamSocket> socket, |
21 const ErrorCallback& error_callback) | 23 const ErrorCallback& error_callback) |
22 : socket_(std::move(socket)), | 24 : socket_(std::move(socket)), |
23 error_callback_(error_callback), | 25 error_callback_(error_callback), |
24 writer_(new BufferedSocketWriter()) { | 26 writer_(new BufferedSocketWriter()) { |
(...skipping 22 matching lines...) Expand all Loading... |
47 } | 49 } |
48 | 50 |
49 void StreamMessagePipeAdapter::CloseOnError(int error) { | 51 void StreamMessagePipeAdapter::CloseOnError(int error) { |
50 // Stop writing on error. | 52 // Stop writing on error. |
51 writer_.reset(); | 53 writer_.reset(); |
52 | 54 |
53 if (!error_callback_.is_null()) | 55 if (!error_callback_.is_null()) |
54 base::ResetAndReturn(&error_callback_).Run(error); | 56 base::ResetAndReturn(&error_callback_).Run(error); |
55 } | 57 } |
56 | 58 |
| 59 StreamMessageChannelFactoryAdapter::StreamMessageChannelFactoryAdapter( |
| 60 StreamChannelFactory* stream_channel_factory, |
| 61 const ErrorCallback& error_callback) |
| 62 : stream_channel_factory_(stream_channel_factory), |
| 63 error_callback_(error_callback) {} |
| 64 |
| 65 StreamMessageChannelFactoryAdapter::~StreamMessageChannelFactoryAdapter() {} |
| 66 |
| 67 void StreamMessageChannelFactoryAdapter::CreateChannel( |
| 68 const std::string& name, |
| 69 const ChannelCreatedCallback& callback) { |
| 70 stream_channel_factory_->CreateChannel( |
| 71 name, base::Bind(&StreamMessageChannelFactoryAdapter::OnChannelCreated, |
| 72 base::Unretained(this), callback)); |
| 73 } |
| 74 |
| 75 void StreamMessageChannelFactoryAdapter::CancelChannelCreation( |
| 76 const std::string& name) { |
| 77 stream_channel_factory_->CancelChannelCreation(name); |
| 78 } |
| 79 |
| 80 void StreamMessageChannelFactoryAdapter::OnChannelCreated( |
| 81 const ChannelCreatedCallback& callback, |
| 82 scoped_ptr<P2PStreamSocket> socket) { |
| 83 if (!socket) { |
| 84 error_callback_.Run(net::ERR_FAILED); |
| 85 return; |
| 86 } |
| 87 callback.Run(make_scoped_ptr( |
| 88 new StreamMessagePipeAdapter(std::move(socket), error_callback_))); |
| 89 } |
| 90 |
57 } // namespace protocol | 91 } // namespace protocol |
58 } // namespace remoting | 92 } // namespace remoting |
OLD | NEW |