Commit 23a34733 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Make RTCPeerConnectionHandler::Observer GC-ed by Oilpan

BUG=787254
R=guidou@chromium.org

Change-Id: Ib0980958f53a1b8c108fc864a7a4bcdae4cc4eb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944367
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722451}
parent 29c89f5d
...@@ -832,13 +832,14 @@ class RTCPeerConnectionHandler::WebRtcSetDescriptionObserverImpl ...@@ -832,13 +832,14 @@ class RTCPeerConnectionHandler::WebRtcSetDescriptionObserverImpl
// and checks for the existence of the RTCPeerConnectionHandler instance before // and checks for the existence of the RTCPeerConnectionHandler instance before
// delivering callbacks on the main thread. // delivering callbacks on the main thread.
class RTCPeerConnectionHandler::Observer class RTCPeerConnectionHandler::Observer
: public WTF::ThreadSafeRefCounted<RTCPeerConnectionHandler::Observer>, : public GarbageCollected<RTCPeerConnectionHandler::Observer>,
public PeerConnectionObserver, public PeerConnectionObserver,
public blink::RtcEventLogOutputSink { public blink::RtcEventLogOutputSink {
public: public:
Observer(const base::WeakPtr<RTCPeerConnectionHandler>& handler, Observer(const base::WeakPtr<RTCPeerConnectionHandler>& handler,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: handler_(handler), main_thread_(task_runner) {} : handler_(handler), main_thread_(task_runner) {}
~Observer() override = default;
// When an RTC event log is sent back from PeerConnection, it arrives here. // When an RTC event log is sent back from PeerConnection, it arrives here.
void OnWebRtcEventLogWrite(const std::string& output) override { void OnWebRtcEventLogWrite(const std::string& output) override {
...@@ -846,17 +847,16 @@ class RTCPeerConnectionHandler::Observer ...@@ -846,17 +847,16 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnWebRtcEventLogWrite, this, &RTCPeerConnectionHandler::Observer::OnWebRtcEventLogWrite,
output)); WrapCrossThreadPersistent(this), output));
} else if (handler_) { } else if (handler_) {
handler_->OnWebRtcEventLogWrite(output); handler_->OnWebRtcEventLogWrite(output);
} }
} }
protected: void Trace(Visitor* visitor) {}
friend class WTF::ThreadSafeRefCounted<RTCPeerConnectionHandler::Observer>;
~Observer() override = default;
protected:
// TODO(hbos): Remove once no longer mandatory to implement. // TODO(hbos): Remove once no longer mandatory to implement.
void OnSignalingChange(PeerConnectionInterface::SignalingState) override {} void OnSignalingChange(PeerConnectionInterface::SignalingState) override {}
void OnAddStream(rtc::scoped_refptr<MediaStreamInterface>) override {} void OnAddStream(rtc::scoped_refptr<MediaStreamInterface>) override {}
...@@ -867,7 +867,8 @@ class RTCPeerConnectionHandler::Observer ...@@ -867,7 +867,8 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnDataChannelImpl, this, &RTCPeerConnectionHandler::Observer::OnDataChannelImpl,
WrapCrossThreadPersistent(this),
base::WrapRefCounted<DataChannelInterface>(data_channel.get()))); base::WrapRefCounted<DataChannelInterface>(data_channel.get())));
} }
...@@ -877,7 +878,7 @@ class RTCPeerConnectionHandler::Observer ...@@ -877,7 +878,7 @@ class RTCPeerConnectionHandler::Observer
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnRenegotiationNeeded, &RTCPeerConnectionHandler::Observer::OnRenegotiationNeeded,
this)); WrapCrossThreadPersistent(this)));
} else if (handler_) { } else if (handler_) {
handler_->OnRenegotiationNeeded(); handler_->OnRenegotiationNeeded();
} }
...@@ -889,9 +890,10 @@ class RTCPeerConnectionHandler::Observer ...@@ -889,9 +890,10 @@ class RTCPeerConnectionHandler::Observer
PeerConnectionInterface::IceConnectionState new_state) override { PeerConnectionInterface::IceConnectionState new_state) override {
if (!main_thread_->BelongsToCurrentThread()) { if (!main_thread_->BelongsToCurrentThread()) {
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, base::BindOnce(&RTCPeerConnectionHandler::Observer:: FROM_HERE,
OnStandardizedIceConnectionChange, base::BindOnce(&RTCPeerConnectionHandler::Observer::
this, new_state)); OnStandardizedIceConnectionChange,
WrapCrossThreadPersistent(this), new_state));
} else if (handler_) { } else if (handler_) {
handler_->OnIceConnectionChange(new_state); handler_->OnIceConnectionChange(new_state);
} }
...@@ -903,8 +905,8 @@ class RTCPeerConnectionHandler::Observer ...@@ -903,8 +905,8 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnConnectionChange, this, &RTCPeerConnectionHandler::Observer::OnConnectionChange,
new_state)); WrapCrossThreadPersistent(this), new_state));
} else if (handler_) { } else if (handler_) {
handler_->OnConnectionChange(new_state); handler_->OnConnectionChange(new_state);
} }
...@@ -916,8 +918,8 @@ class RTCPeerConnectionHandler::Observer ...@@ -916,8 +918,8 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnIceGatheringChange, this, &RTCPeerConnectionHandler::Observer::OnIceGatheringChange,
new_state)); WrapCrossThreadPersistent(this), new_state));
} else if (handler_) { } else if (handler_) {
handler_->OnIceGatheringChange(new_state); handler_->OnIceGatheringChange(new_state);
} }
...@@ -932,11 +934,12 @@ class RTCPeerConnectionHandler::Observer ...@@ -932,11 +934,12 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(&RTCPeerConnectionHandler::Observer::OnIceCandidateImpl,
&RTCPeerConnectionHandler::Observer::OnIceCandidateImpl, this, WrapCrossThreadPersistent(this), String::FromUTF8(sdp),
String::FromUTF8(sdp), String::FromUTF8(candidate->sdp_mid()), String::FromUTF8(candidate->sdp_mid()),
candidate->sdp_mline_index(), candidate->candidate().component(), candidate->sdp_mline_index(),
candidate->candidate().address().family())); candidate->candidate().component(),
candidate->candidate().address().family()));
} }
void OnIceCandidateError(const std::string& host_candidate, void OnIceCandidateError(const std::string& host_candidate,
...@@ -946,9 +949,9 @@ class RTCPeerConnectionHandler::Observer ...@@ -946,9 +949,9 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnIceCandidateErrorImpl, this, &RTCPeerConnectionHandler::Observer::OnIceCandidateErrorImpl,
String::FromUTF8(host_candidate), String::FromUTF8(url), error_code, WrapCrossThreadPersistent(this), String::FromUTF8(host_candidate),
String::FromUTF8(error_text))); String::FromUTF8(url), error_code, String::FromUTF8(error_text)));
} }
void OnDataChannelImpl(scoped_refptr<DataChannelInterface> channel) { void OnDataChannelImpl(scoped_refptr<DataChannelInterface> channel) {
...@@ -984,8 +987,8 @@ class RTCPeerConnectionHandler::Observer ...@@ -984,8 +987,8 @@ class RTCPeerConnectionHandler::Observer
main_thread_->PostTask( main_thread_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnInterestingUsageImpl, this, &RTCPeerConnectionHandler::Observer::OnInterestingUsageImpl,
usage_pattern)); WrapCrossThreadPersistent(this), usage_pattern));
} }
void OnInterestingUsageImpl(int usage_pattern) { void OnInterestingUsageImpl(int usage_pattern) {
...@@ -1073,9 +1076,9 @@ bool RTCPeerConnectionHandler::Initialize( ...@@ -1073,9 +1076,9 @@ bool RTCPeerConnectionHandler::Initialize(
CopyConstraintsIntoRtcConfiguration(options, &configuration_); CopyConstraintsIntoRtcConfiguration(options, &configuration_);
peer_connection_observer_ = peer_connection_observer_ =
base::MakeRefCounted<Observer>(weak_factory_.GetWeakPtr(), task_runner_); MakeGarbageCollected<Observer>(weak_factory_.GetWeakPtr(), task_runner_);
native_peer_connection_ = dependency_factory_->CreatePeerConnection( native_peer_connection_ = dependency_factory_->CreatePeerConnection(
configuration_, frame_, peer_connection_observer_.get()); configuration_, frame_, peer_connection_observer_);
if (!native_peer_connection_.get()) { if (!native_peer_connection_.get()) {
LOG(ERROR) << "Failed to initialize native PeerConnection."; LOG(ERROR) << "Failed to initialize native PeerConnection.";
...@@ -1103,11 +1106,11 @@ bool RTCPeerConnectionHandler::InitializeForTest( ...@@ -1103,11 +1106,11 @@ bool RTCPeerConnectionHandler::InitializeForTest(
configuration_ = server_configuration; configuration_ = server_configuration;
peer_connection_observer_ = peer_connection_observer_ =
base::MakeRefCounted<Observer>(weak_factory_.GetWeakPtr(), task_runner_); MakeGarbageCollected<Observer>(weak_factory_.GetWeakPtr(), task_runner_);
CopyConstraintsIntoRtcConfiguration(options, &configuration_); CopyConstraintsIntoRtcConfiguration(options, &configuration_);
native_peer_connection_ = dependency_factory_->CreatePeerConnection( native_peer_connection_ = dependency_factory_->CreatePeerConnection(
configuration_, nullptr, peer_connection_observer_.get()); configuration_, nullptr, peer_connection_observer_);
if (!native_peer_connection_.get()) { if (!native_peer_connection_.get()) {
LOG(ERROR) << "Failed to initialize native PeerConnection."; LOG(ERROR) << "Failed to initialize native PeerConnection.";
return false; return false;
...@@ -2006,8 +2009,7 @@ void RTCPeerConnectionHandler::StartEventLog(int output_period_ms) { ...@@ -2006,8 +2009,7 @@ void RTCPeerConnectionHandler::StartEventLog(int output_period_ms) {
// or find a way to be able to use it. // or find a way to be able to use it.
// https://crbug.com/775415 // https://crbug.com/775415
native_peer_connection_->StartRtcEventLog( native_peer_connection_->StartRtcEventLog(
std::make_unique<RtcEventLogOutputSinkProxy>( std::make_unique<RtcEventLogOutputSinkProxy>(peer_connection_observer_),
peer_connection_observer_.get()),
output_period_ms); output_period_ms);
} }
......
...@@ -389,7 +389,7 @@ class MODULES_EXPORT RTCPeerConnectionHandler ...@@ -389,7 +389,7 @@ class MODULES_EXPORT RTCPeerConnectionHandler
// To make sure the observers are released after native_peer_connection_, // To make sure the observers are released after native_peer_connection_,
// they have to come first. // they have to come first.
scoped_refptr<Observer> peer_connection_observer_; CrossThreadPersistent<Observer> peer_connection_observer_;
// |native_peer_connection_| is the libjingle native PeerConnection object. // |native_peer_connection_| is the libjingle native PeerConnection object.
scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection_; scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment