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