| 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 #ifndef REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ | 5 #ifndef REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ |
| 6 #define REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ | 6 #define REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "remoting/protocol/message_channel_factory.h" |
| 9 #include "remoting/protocol/message_pipe.h" | 10 #include "remoting/protocol/message_pipe.h" |
| 10 #include "remoting/protocol/message_reader.h" | 11 #include "remoting/protocol/message_reader.h" |
| 11 | 12 |
| 12 namespace remoting { | 13 namespace remoting { |
| 13 class BufferedSocketWriter; | 14 class BufferedSocketWriter; |
| 14 | 15 |
| 15 namespace protocol { | 16 namespace protocol { |
| 16 | 17 |
| 17 class P2PStreamSocket; | 18 class P2PStreamSocket; |
| 19 class StreamChannelFactory; |
| 18 | 20 |
| 19 // MessagePipe implementation that sends and receives messages over a | 21 // MessagePipe implementation that sends and receives messages over a |
| 20 // P2PStreamChannel. | 22 // P2PStreamChannel. |
| 21 class StreamMessagePipeAdapter : public MessagePipe { | 23 class StreamMessagePipeAdapter : public MessagePipe { |
| 22 public: | 24 public: |
| 23 typedef base::Callback<void(int)> ErrorCallback; | 25 typedef base::Callback<void(int)> ErrorCallback; |
| 24 | 26 |
| 25 StreamMessagePipeAdapter(scoped_ptr<P2PStreamSocket> socket, | 27 StreamMessagePipeAdapter(scoped_ptr<P2PStreamSocket> socket, |
| 26 const ErrorCallback& error_callback); | 28 const ErrorCallback& error_callback); |
| 27 ~StreamMessagePipeAdapter() override; | 29 ~StreamMessagePipeAdapter() override; |
| 28 | 30 |
| 29 // MessagePipe interface. | 31 // MessagePipe interface. |
| 30 void StartReceiving(const MessageReceivedCallback& callback) override; | 32 void StartReceiving(const MessageReceivedCallback& callback) override; |
| 31 void Send(google::protobuf::MessageLite* message, | 33 void Send(google::protobuf::MessageLite* message, |
| 32 const base::Closure& done) override; | 34 const base::Closure& done) override; |
| 33 | 35 |
| 34 private: | 36 private: |
| 35 void CloseOnError(int error); | 37 void CloseOnError(int error); |
| 36 | 38 |
| 37 scoped_ptr<P2PStreamSocket> socket_; | 39 scoped_ptr<P2PStreamSocket> socket_; |
| 38 ErrorCallback error_callback_; | 40 ErrorCallback error_callback_; |
| 39 | 41 |
| 40 MessageReader reader_; | 42 MessageReader reader_; |
| 41 scoped_ptr<BufferedSocketWriter> writer_; | 43 scoped_ptr<BufferedSocketWriter> writer_; |
| 42 | 44 |
| 43 DISALLOW_COPY_AND_ASSIGN(StreamMessagePipeAdapter); | 45 DISALLOW_COPY_AND_ASSIGN(StreamMessagePipeAdapter); |
| 44 }; | 46 }; |
| 45 | 47 |
| 48 class StreamMessageChannelFactoryAdapter : public MessageChannelFactory { |
| 49 public: |
| 50 typedef base::Callback<void(int)> ErrorCallback; |
| 51 |
| 52 StreamMessageChannelFactoryAdapter( |
| 53 StreamChannelFactory* stream_channel_factory, |
| 54 const ErrorCallback& error_callback); |
| 55 ~StreamMessageChannelFactoryAdapter() override; |
| 56 |
| 57 // MessageChannelFactory interface. |
| 58 void CreateChannel(const std::string& name, |
| 59 const ChannelCreatedCallback& callback) override; |
| 60 void CancelChannelCreation(const std::string& name) override; |
| 61 |
| 62 private: |
| 63 void OnChannelCreated(const ChannelCreatedCallback& callback, |
| 64 scoped_ptr<P2PStreamSocket> socket); |
| 65 |
| 66 StreamChannelFactory* stream_channel_factory_; |
| 67 ErrorCallback error_callback_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(StreamMessageChannelFactoryAdapter); |
| 70 }; |
| 71 |
| 46 } // namespace protocol | 72 } // namespace protocol |
| 47 } // namespace remoting | 73 } // namespace remoting |
| 48 | 74 |
| 49 #endif // REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ | 75 #endif // REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ |
| OLD | NEW |