Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: remoting/protocol/stream_message_pipe_adapter.cc

Issue 1649063003: Add MessagePipe interface. Use it in ChannelDispatcherBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_parser
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/callback_helpers.h"
11 #include "remoting/base/buffered_socket_writer.h"
12 #include "remoting/base/compound_buffer.h"
13 #include "remoting/protocol/message_serialization.h"
14 #include "remoting/protocol/p2p_stream_socket.h"
15
16 namespace remoting {
17 namespace protocol {
18
19 StreamMessagePipeAdapter::StreamMessagePipeAdapter(
20 scoped_ptr<P2PStreamSocket> socket,
21 const ErrorCallback& error_callback)
22 : socket_(std::move(socket)),
23 error_callback_(error_callback),
24 writer_(new BufferedSocketWriter()) {
25 DCHECK(socket_);
26 DCHECK(!error_callback_.is_null());
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 StreamMessagePipeAdapter::~StreamMessagePipeAdapter() {}
35
36 void StreamMessagePipeAdapter::StartReceiving(
37 const MessageReceivedCallback& callback) {
38 reader_.StartReading(socket_.get(), callback,
39 base::Bind(&StreamMessagePipeAdapter::CloseOnError,
40 base::Unretained(this)));
41 }
42
43 void StreamMessagePipeAdapter::Send(google::protobuf::MessageLite* message,
44 const base::Closure& done) {
45 if (writer_)
46 writer_->Write(SerializeAndFrameMessage(*message), done);
47 }
48
49 void StreamMessagePipeAdapter::CloseOnError(int error) {
50 // Stop writing on error.
51 writer_.reset();
52
53 if (!error_callback_.is_null())
54 base::ResetAndReturn(&error_callback_).Run(error);
55 }
56
57 } // namespace protocol
58 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/stream_message_pipe_adapter.h ('k') | remoting/protocol/webrtc_connection_to_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698