Commit 87799658 authored by Harald Alvestrand's avatar Harald Alvestrand Committed by Commit Bot

Revise counting of allocated RTCPeerConnections

The old count wouldn't count RTCPeerConnections allocated when returning
an error saying "too many PeerConnections", but those would be garbage
collected later.

This change fixes that issue.

Tested: Before the fix, a different test failed on the (new) DCHECK.
After the fix, the same test didn't fail.

Bug: 827064
Change-Id: I4765ce7043fd8a4e0c9c54dc1ec403e986ffed77
Reviewed-on: https://chromium-review.googlesource.com/1061176Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Commit-Queue: Harald Alvestrand <hta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561044}
parent d8d380f1
......@@ -543,19 +543,18 @@ RTCPeerConnection::RTCPeerConnection(ExecutionContext* context,
sdp_semantics_(configuration.sdp_semantics) {
Document* document = ToDocument(GetExecutionContext());
InstanceCounters::IncrementCounter(
InstanceCounters::kRTCPeerConnectionCounter);
// If we fail, set |m_closed| and |m_stopped| to true, to avoid hitting the
// assert in the destructor.
if (InstanceCounters::CounterValue(
InstanceCounters::kRTCPeerConnectionCounter) >= kMaxPeerConnections) {
InstanceCounters::kRTCPeerConnectionCounter) > kMaxPeerConnections) {
closed_ = true;
stopped_ = true;
exception_state.ThrowDOMException(kUnknownError,
"Cannot create so many PeerConnections");
return;
}
InstanceCounters::IncrementCounter(
InstanceCounters::kRTCPeerConnectionCounter);
if (!document->GetFrame()) {
closed_ = true;
stopped_ = true;
......@@ -598,6 +597,8 @@ RTCPeerConnection::~RTCPeerConnection() {
DCHECK(closed_ || stopped_);
InstanceCounters::DecrementCounter(
InstanceCounters::kRTCPeerConnectionCounter);
DCHECK(InstanceCounters::CounterValue(
InstanceCounters::kRTCPeerConnectionCounter) >= 0);
}
void RTCPeerConnection::Dispose() {
......
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