| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_WEBRTC_DATA_STREAM_ADAPTER_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
| 6 #define REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "remoting/protocol/errors.h" | 13 #include "remoting/protocol/errors.h" |
| 13 #include "remoting/protocol/message_channel_factory.h" | 14 #include "remoting/protocol/message_channel_factory.h" |
| 14 #include "third_party/webrtc/api/peerconnectioninterface.h" | 15 #include "third_party/webrtc/api/peerconnectioninterface.h" |
| 15 #include "third_party/webrtc/base/refcount.h" | 16 #include "third_party/webrtc/base/refcount.h" |
| 16 | 17 |
| 17 namespace rtc { | 18 namespace rtc { |
| 18 class PeerConnectionInterface; | 19 class PeerConnectionInterface; |
| 19 } // namespace rtc | 20 } // namespace rtc |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace remoting { |
| 22 namespace protocol { | 23 namespace protocol { |
| 23 | 24 |
| 24 // WebrtcDataStreamAdapter is a MessageChannelFactory that creates channels that | 25 // WebrtcDataStreamAdapter wraps MessagePipe for WebRTC data channels. |
| 25 // send and receive messages over PeerConnection data channels. | 26 class WebrtcDataStreamAdapter { |
| 26 class WebrtcDataStreamAdapter : public MessageChannelFactory { | |
| 27 public: | 27 public: |
| 28 typedef base::Callback<void(ErrorCode)> ErrorCallback; | 28 typedef base::Callback<void(ErrorCode)> ErrorCallback; |
| 29 | 29 |
| 30 explicit WebrtcDataStreamAdapter(const ErrorCallback& error_callback); | 30 explicit WebrtcDataStreamAdapter( |
| 31 ~WebrtcDataStreamAdapter() override; | 31 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection); |
| 32 ~WebrtcDataStreamAdapter(); |
| 32 | 33 |
| 33 // Initializes the adapter for |peer_connection|. If |outgoing| is set to true | 34 // Creates outgoing data channel. |
| 34 // all channels will be created as outgoing. Otherwise CreateChannel() will | 35 std::unique_ptr<MessagePipe> CreateOutgoingChannel(const std::string& name); |
| 35 // wait for the other end to create connection. | |
| 36 void Initialize( | |
| 37 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection); | |
| 38 | 36 |
| 39 // Called by WebrtcTransport. | 37 // Creates incoming data channel. |
| 40 void WrapIncomingDataChannel( | 38 std::unique_ptr<MessagePipe> WrapIncomingDataChannel( |
| 41 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel, | 39 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel); |
| 42 const ChannelCreatedCallback& callback); | |
| 43 | |
| 44 // MessageChannelFactory interface. | |
| 45 void CreateChannel(const std::string& name, | |
| 46 const ChannelCreatedCallback& callback) override; | |
| 47 void CancelChannelCreation(const std::string& name) override; | |
| 48 | 40 |
| 49 private: | 41 private: |
| 50 class Channel; | |
| 51 friend class Channel; | |
| 52 | |
| 53 struct PendingChannel; | |
| 54 | |
| 55 void AddPendingChannel( | |
| 56 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel, | |
| 57 const ChannelCreatedCallback& callback); | |
| 58 | |
| 59 void OnChannelConnected(Channel* channel); | |
| 60 void OnChannelError(); | |
| 61 | |
| 62 ErrorCallback error_callback_; | |
| 63 | |
| 64 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 42 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 65 | 43 |
| 66 std::map<std::string, PendingChannel> pending_channels_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(WebrtcDataStreamAdapter); | 44 DISALLOW_COPY_AND_ASSIGN(WebrtcDataStreamAdapter); |
| 69 }; | 45 }; |
| 70 | 46 |
| 71 } // namespace protocol | 47 } // namespace protocol |
| 72 } // namespace remoting | 48 } // namespace remoting |
| 73 | 49 |
| 74 #endif // REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ | 50 #endif // REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
| OLD | NEW |