OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ |
| 6 #define REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ |
| 7 |
| 8 #include "remoting/protocol/message_pipe.h" |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "remoting/base/buffered_socket_writer.h" |
| 12 #include "remoting/protocol/message_reader.h" |
| 13 |
| 14 namespace remoting { |
| 15 namespace protocol { |
| 16 |
| 17 class P2PStreamSocket; |
| 18 |
| 19 // MessagePipe implementation that sends and receives messages over a |
| 20 // P2PStreamChannel. |
| 21 class StreamMessagePipeAdapter : public MessagePipe { |
| 22 public: |
| 23 typedef base::Callback<void(int)> ErrorCallback; |
| 24 |
| 25 StreamMessagePipeAdapter(); |
| 26 ~StreamMessagePipeAdapter() override; |
| 27 |
| 28 // Starts reading from |socket|. |
| 29 void Initialize(scoped_ptr<P2PStreamSocket> socket, |
| 30 const ErrorCallback& error_callback); |
| 31 |
| 32 // MessagePipe interface. |
| 33 void StartReceiving(const MessageReceivedCallback& callback) override; |
| 34 void Send(google::protobuf::MessageLite* message, |
| 35 const base::Closure& done) override; |
| 36 |
| 37 private: |
| 38 void CloseOnError(int error); |
| 39 |
| 40 scoped_ptr<P2PStreamSocket> socket_; |
| 41 ErrorCallback error_callback_; |
| 42 |
| 43 bool closed_ = false; |
| 44 |
| 45 MessageReader reader_; |
| 46 BufferedSocketWriter writer_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(StreamMessagePipeAdapter); |
| 49 }; |
| 50 |
| 51 } // namespace protocol |
| 52 } // namespace remoting |
| 53 |
| 54 #endif // REMOTING_PROTOCOL_STREAM_MESSAGE_PIPE_ADAPTER_H_ |
OLD | NEW |