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

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

Issue 1662673002: Add MessageChanneFactory interface and use it in ChannelDispatcherBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@framing
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
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
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 StreamMessageChannelFactoryAdapter::~StreamMessageChannelFactoryAdapter() {}
Jamie 2016/02/03 02:01:02 Blank line after non-trivial ctor?
Sergey Ulanov 2016/02/03 20:09:18 Done.
65
66 void StreamMessageChannelFactoryAdapter::CreateChannel(
67 const std::string& name,
68 const ChannelCreatedCallback& callback) {
69 stream_channel_factory_->CreateChannel(
70 name, base::Bind(&StreamMessageChannelFactoryAdapter::OnChannelCreated,
71 base::Unretained(this), callback));
72 }
73
74 void StreamMessageChannelFactoryAdapter::CancelChannelCreation(
75 const std::string& name) {
76 stream_channel_factory_->CancelChannelCreation(name);
77 }
78
79 void StreamMessageChannelFactoryAdapter::OnChannelCreated(
80 const ChannelCreatedCallback& callback,
81 scoped_ptr<P2PStreamSocket> socket) {
82 if (!socket) {
83 error_callback_.Run(net::ERR_FAILED);
84 return;
85 }
86 callback.Run(make_scoped_ptr(
87 new StreamMessagePipeAdapter(std::move(socket), error_callback_)));
88 }
89
57 } // namespace protocol 90 } // namespace protocol
58 } // namespace remoting 91 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698