blob: a23cc77e2c837038dab8256ffffcc90c0a4e53c9 [file] [log] [blame]
honghaiz1183eb62015-10-19 16:39:321/*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
kjellander19796962017-06-30 17:45:2111#include "webrtc/rtc_base/networkmonitor.h"
honghaiz1183eb62015-10-19 16:39:3212
kjellander19796962017-06-30 17:45:2113#include "webrtc/rtc_base/checks.h"
honghaiz1183eb62015-10-19 16:39:3214
15namespace {
16const uint32_t UPDATE_NETWORKS_MESSAGE = 1;
17
18// This is set by NetworkMonitorFactory::SetFactory and the caller of
19// NetworkMonitorFactory::SetFactory must be responsible for calling
20// ReleaseFactory to destroy the factory.
21rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
22} // namespace
23
24namespace rtc {
25NetworkMonitorInterface::NetworkMonitorInterface() {}
26
27NetworkMonitorInterface::~NetworkMonitorInterface() {}
28
honghaiz1d9eb312016-01-15 22:49:0929NetworkMonitorBase::NetworkMonitorBase() : worker_thread_(Thread::Current()) {}
honghaiz1183eb62015-10-19 16:39:3230NetworkMonitorBase::~NetworkMonitorBase() {}
31
32void NetworkMonitorBase::OnNetworksChanged() {
33 LOG(LS_VERBOSE) << "Network change is received at the network monitor";
Taylor Brandstetterc0bec8f2016-06-10 21:17:2734 worker_thread_->Post(RTC_FROM_HERE, this, UPDATE_NETWORKS_MESSAGE);
honghaiz1183eb62015-10-19 16:39:3235}
36
37void NetworkMonitorBase::OnMessage(Message* msg) {
nissea875ff82017-01-12 13:15:3638 RTC_DCHECK(msg->message_id == UPDATE_NETWORKS_MESSAGE);
honghaiz1183eb62015-10-19 16:39:3239 SignalNetworksChanged();
40}
41
42NetworkMonitorFactory::NetworkMonitorFactory() {}
43NetworkMonitorFactory::~NetworkMonitorFactory() {}
44
45void NetworkMonitorFactory::SetFactory(NetworkMonitorFactory* factory) {
46 if (network_monitor_factory != nullptr) {
47 delete network_monitor_factory;
48 }
49 network_monitor_factory = factory;
50}
51
52void NetworkMonitorFactory::ReleaseFactory(NetworkMonitorFactory* factory) {
53 if (factory == network_monitor_factory) {
54 SetFactory(nullptr);
55 }
56}
57
58NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() {
59 return network_monitor_factory;
60}
61
62} // namespace rtc