Introduce CreateDataChannelOrError
Deprecate CreateDataChannel, and make it a simple wrapper function.
Bug: webrtc:12796
Change-Id: I053d75a264596ba87ca734a29df9241de93a80c3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/219784
Reviewed-by: Xavier Lepaul <xalep@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34130}
diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h
index 75c4d3c..e815f19 100644
--- a/api/peer_connection_interface.h
+++ b/api/peer_connection_interface.h
@@ -920,9 +920,24 @@
// Also, calling CreateDataChannel is the only way to get a data "m=" section
// in SDP, so it should be done before CreateOffer is called, if the
// application plans to use data channels.
+ virtual RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>>
+ CreateDataChannelOrError(const std::string& label,
+ const DataChannelInit* config) {
+ return RTCError(RTCErrorType::INTERNAL_ERROR, "dummy function called");
+ }
+ // TODO(crbug.com/788659): Remove "virtual" below and default implementation
+ // above once mock in Chrome is fixed.
+ ABSL_DEPRECATED("Use CreateDataChannelOrError")
virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
const std::string& label,
- const DataChannelInit* config) = 0;
+ const DataChannelInit* config) {
+ auto result = CreateDataChannelOrError(label, config);
+ if (!result.ok()) {
+ return nullptr;
+ } else {
+ return result.MoveValue();
+ }
+ }
// NOTE: For the following 6 methods, it's only safe to dereference the
// SessionDescriptionInterface on signaling_thread() (for example, calling
diff --git a/api/peer_connection_proxy.h b/api/peer_connection_proxy.h
index cc9df10..de7664f 100644
--- a/api/peer_connection_proxy.h
+++ b/api/peer_connection_proxy.h
@@ -76,8 +76,8 @@
rtc::scoped_refptr<RtpReceiverInterface>,
rtc::scoped_refptr<RTCStatsCollectorCallback>)
PROXY_METHOD0(void, ClearStatsCache)
-PROXY_METHOD2(rtc::scoped_refptr<DataChannelInterface>,
- CreateDataChannel,
+PROXY_METHOD2(RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>>,
+ CreateDataChannelOrError,
const std::string&,
const DataChannelInit*)
PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, local_description)
diff --git a/api/test/dummy_peer_connection.h b/api/test/dummy_peer_connection.h
index 4d17aed..80ae20c 100644
--- a/api/test/dummy_peer_connection.h
+++ b/api/test/dummy_peer_connection.h
@@ -114,10 +114,10 @@
}
void ClearStatsCache() override {}
- rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
+ RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>> CreateDataChannelOrError(
const std::string& label,
const DataChannelInit* config) override {
- return nullptr;
+ return RTCError(RTCErrorType::INTERNAL_ERROR, "Dummy function called");
}
const SessionDescriptionInterface* local_description() const override {
diff --git a/api/test/mock_peerconnectioninterface.h b/api/test/mock_peerconnectioninterface.h
index be34df0..b5d9423 100644
--- a/api/test/mock_peerconnectioninterface.h
+++ b/api/test/mock_peerconnectioninterface.h
@@ -100,8 +100,8 @@
GetSctpTransport,
(),
(const override));
- MOCK_METHOD(rtc::scoped_refptr<DataChannelInterface>,
- CreateDataChannel,
+ MOCK_METHOD(RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>>,
+ CreateDataChannelOrError,
(const std::string&, const DataChannelInit*),
(override));
MOCK_METHOD(const SessionDescriptionInterface*,