1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36

content / browser / webrtc / webrtc_connections_observer.cc [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/webrtc/webrtc_connections_observer.h"

#include "content/browser/webrtc/webrtc_internals.h"

namespace content {

WebRtcConnectionsObserver::WebRtcConnectionsObserver(
    const ConnectionsCountChangedCallback& connections_count_changed_callback)
    : connections_count_changed_callback_(connections_count_changed_callback) {
  DCHECK(!connections_count_changed_callback_.is_null());

  WebRTCInternals* webrtc_internals = WebRTCInternals::GetInstance();
  if (!webrtc_internals)
    return;
  webrtc_internals->AddConnectionsObserver(this);
}

WebRtcConnectionsObserver::~WebRtcConnectionsObserver() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  WebRTCInternals* webrtc_internals = WebRTCInternals::GetInstance();
  if (!webrtc_internals)
    return;
  webrtc_internals->RemoveConnectionsObserver(this);
}

void WebRtcConnectionsObserver::OnConnectionsCountChange(uint32_t count) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  connections_count_changed_callback_.Run(count);
}

}  // namespace content