Chromium Code Reviews| 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 <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "remoting/protocol/errors.h" | 13 #include "remoting/protocol/message_pipe.h" |
| 14 #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 { | |
| 19 class PeerConnectionInterface; | |
| 20 } // namespace rtc | |
| 21 | |
| 22 namespace remoting { | 17 namespace remoting { |
| 23 namespace protocol { | 18 namespace protocol { |
| 24 | 19 |
| 25 // WebrtcDataStreamAdapter wraps MessagePipe for WebRTC data channels. | 20 // WebrtcDataStreamAdapter implements MessagePipe for WebRTC data channels. |
| 26 class WebrtcDataStreamAdapter { | 21 class WebrtcDataStreamAdapter : public MessagePipe, |
| 22 public webrtc::DataChannelObserver { | |
| 27 public: | 23 public: |
| 28 typedef base::Callback<void(ErrorCode)> ErrorCallback; | 24 explicit WebrtcDataStreamAdapter( |
| 25 rtc::scoped_refptr<webrtc::DataChannelInterface> channel); | |
| 26 ~WebrtcDataStreamAdapter() override; | |
| 29 | 27 |
| 30 explicit WebrtcDataStreamAdapter( | 28 std::string name() { return channel_->label(); } |
| 31 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection); | |
| 32 ~WebrtcDataStreamAdapter(); | |
| 33 | 29 |
| 34 // Creates outgoing data channel. | 30 // MessagePipe interface. |
| 35 std::unique_ptr<MessagePipe> CreateOutgoingChannel(const std::string& name); | 31 void Start(EventHandler* event_handler) override; |
| 36 | 32 void Send(google::protobuf::MessageLite* message, |
| 37 // Creates incoming data channel. | 33 const base::Closure& done) override; |
| 38 std::unique_ptr<MessagePipe> WrapIncomingDataChannel( | |
| 39 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel); | |
| 40 | 34 |
| 41 private: | 35 private: |
| 42 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 36 enum class State { CONNECTING, OPEN, CLOSED }; |
| 37 | |
| 38 // webrtc::DataChannelObserver interface. | |
| 39 void OnStateChange() override; | |
| 40 void OnMessage(const webrtc::DataBuffer& buffer) override; | |
|
Jamie
2016/07/25 18:25:59
These are public in the DataChannelObserver interf
Sergey Ulanov
2016/07/25 18:48:19
Putting this interface in private section makes it
| |
| 41 | |
| 42 void OnConnected(); | |
| 43 | |
| 44 void OnClosed(); | |
| 45 | |
| 46 rtc::scoped_refptr<webrtc::DataChannelInterface> channel_; | |
| 47 | |
| 48 EventHandler* event_handler_ = nullptr; | |
| 49 | |
| 50 State state_ = State::CONNECTING; | |
| 43 | 51 |
| 44 DISALLOW_COPY_AND_ASSIGN(WebrtcDataStreamAdapter); | 52 DISALLOW_COPY_AND_ASSIGN(WebrtcDataStreamAdapter); |
| 45 }; | 53 }; |
| 46 | 54 |
| 47 } // namespace protocol | 55 } // namespace protocol |
| 48 } // namespace remoting | 56 } // namespace remoting |
| 49 | 57 |
| 50 #endif // REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ | 58 #endif // REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
| OLD | NEW |