Chromium Code Reviews| 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 #include "remoting/protocol/stream_message_pipe_adapter.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "remoting/base/compound_buffer.h" | |
| 11 #include "remoting/protocol/message_serialization.h" | |
| 12 #include "remoting/protocol/p2p_stream_socket.h" | |
| 13 | |
| 14 namespace remoting { | |
| 15 namespace protocol { | |
| 16 | |
| 17 StreamMessagePipeAdapter::StreamMessagePipeAdapter() {} | |
| 18 StreamMessagePipeAdapter::~StreamMessagePipeAdapter() {} | |
| 19 | |
| 20 void StreamMessagePipeAdapter::Initialize(scoped_ptr<P2PStreamSocket> socket, | |
| 21 const ErrorCallback& error_callback) { | |
| 22 DCHECK(socket); | |
| 23 DCHECK(!error_callback.is_null()); | |
| 24 | |
| 25 socket_ = std::move(socket); | |
| 26 error_callback_ = error_callback; | |
| 27 | |
| 28 writer_.Start( | |
| 29 base::Bind(&P2PStreamSocket::Write, base::Unretained(socket_.get())), | |
| 30 base::Bind(&StreamMessagePipeAdapter::CloseOnError, | |
| 31 base::Unretained(this))); | |
| 32 } | |
| 33 | |
| 34 void StreamMessagePipeAdapter::StartReceiving( | |
| 35 const MessageReceivedCallback& callback) { | |
| 36 reader_.StartReading(socket_.get(), callback, | |
| 37 base::Bind(&StreamMessagePipeAdapter::CloseOnError, | |
| 38 base::Unretained(this))); | |
| 39 } | |
| 40 | |
| 41 void StreamMessagePipeAdapter::Send(google::protobuf::MessageLite* message, | |
| 42 const base::Closure& done) { | |
| 43 if (closed_) | |
| 44 return; | |
|
Jamie
2016/02/01 22:48:20
Call the error callback here? Otherwise the caller
Sergey Ulanov
2016/02/02 21:16:42
I think just dropping the callback here is the rig
Jamie
2016/02/02 22:43:10
Based on off-line discussion, it sounds like there
Sergey Ulanov
2016/02/03 18:45:26
Done.
| |
| 45 | |
| 46 writer_.Write(SerializeAndFrameMessage(*message), done); | |
| 47 } | |
| 48 | |
| 49 void StreamMessagePipeAdapter::CloseOnError(int error) { | |
| 50 // Stop reading after any error. | |
| 51 closed_ = true; | |
| 52 | |
| 53 error_callback_.Run(error); | |
| 54 } | |
| 55 | |
| 56 } // namespace protocol | |
| 57 } // namespace remoting | |
| OLD | NEW |