Partial reland: DataChannelObserver interface change.

This is a partial reland of:
https://webrtc-review.googlesource.com/c/src/+/299142

This CL includes the interface change in DataChannelObserver but
not the code behind it. The point of landing this change first is
to be able to override this method in downstream implementations in
preparation for relanding the rest of the changes.

Bug: webrtc:11547
Change-Id: Ic3fe4fb8084908ef12bd4916b763df5a75604113
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300362
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39776}
This commit is contained in:
Tommi 2023-04-05 17:17:17 +02:00 committed by WebRTC LUCI CQ
parent f7ed83f68e
commit a13b4d1d30
3 changed files with 43 additions and 10 deletions

View File

@ -100,6 +100,17 @@ class DataChannelObserver {
// The data channel's buffered_amount has changed.
virtual void OnBufferedAmountChange(uint64_t sent_data_size) {}
// Override this to get callbacks directly on the network thread.
// An implementation that does that must not block the network thread
// but rather only use the callback to trigger asynchronous processing
// elsewhere as a result of the notification.
// The default return value, `false`, means that notifications will be
// delivered on the signaling thread associated with the peerconnection
// instance.
// TODO(webrtc:11547): Eventually all DataChannelObserver implementations
// should be called on the network thread and this method removed.
virtual bool IsOkToCallOnTheNetworkThread() { return false; }
protected:
virtual ~DataChannelObserver() = default;
};

View File

@ -40,18 +40,15 @@ static constexpr int kDefaultTimeout = 10000;
class FakeDataChannelObserver : public DataChannelObserver {
public:
FakeDataChannelObserver()
: messages_received_(0),
on_state_change_count_(0),
on_buffered_amount_change_count_(0) {}
FakeDataChannelObserver() { RTC_DCHECK(!IsOkToCallOnTheNetworkThread()); }
void OnStateChange() { ++on_state_change_count_; }
void OnStateChange() override { ++on_state_change_count_; }
void OnBufferedAmountChange(uint64_t previous_amount) {
void OnBufferedAmountChange(uint64_t previous_amount) override {
++on_buffered_amount_change_count_;
}
void OnMessage(const DataBuffer& buffer) { ++messages_received_; }
void OnMessage(const DataBuffer& buffer) override { ++messages_received_; }
size_t messages_received() const { return messages_received_; }
@ -68,9 +65,9 @@ class FakeDataChannelObserver : public DataChannelObserver {
}
private:
size_t messages_received_;
size_t on_state_change_count_;
size_t on_buffered_amount_change_count_;
size_t messages_received_ = 0u;
size_t on_state_change_count_ = 0u;
size_t on_buffered_amount_change_count_ = 0u;
};
class SctpDataChannelTest : public ::testing::Test {

View File

@ -450,6 +450,31 @@ class ConstMethodCall {
return c_->method(); \
}
// Allows a custom implementation of a method where the otherwise proxied
// implementation can do a more efficient, yet thread-safe, job than the proxy
// can do by default or when more flexibility is needed than can be provided
// by a proxy.
// Note that calls to these methods should be expected to be made from unknown
// threads.
#define BYPASS_PROXY_METHOD0(r, method) \
r method() override { \
TRACE_BOILERPLATE(method); \
return c_->method(); \
}
// The 1 argument version of `BYPASS_PROXY_METHOD0`.
#define BYPASS_PROXY_METHOD1(r, method, t1) \
r method(t1 a1) override { \
TRACE_BOILERPLATE(method); \
return c_->method(std::move(a1)); \
}
// The 2 argument version of `BYPASS_PROXY_METHOD0`.
#define BYPASS_PROXY_METHOD2(r, method, t1, t2) \
r method(t1 a1, t2 a2) override { \
TRACE_BOILERPLATE(method); \
return c_->method(std::move(a1), std::move(a2)); \
}
} // namespace webrtc
#endif // PC_PROXY_H_