1 /*
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 
11 #include "rtc_base/network_monitor.h"
12 
13 #include <stdint.h>
14 
15 #include "rtc_base/checks.h"
16 #include "rtc_base/location.h"
17 #include "rtc_base/logging.h"
18 
19 namespace {
20 const uint32_t UPDATE_NETWORKS_MESSAGE = 1;
21 
22 // This is set by NetworkMonitorFactory::SetFactory and the caller of
23 // NetworkMonitorFactory::SetFactory must be responsible for calling
24 // ReleaseFactory to destroy the factory.
25 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
26 }  // namespace
27 
28 namespace rtc {
NetworkMonitorInterface()29 NetworkMonitorInterface::NetworkMonitorInterface() {}
30 
~NetworkMonitorInterface()31 NetworkMonitorInterface::~NetworkMonitorInterface() {}
32 
NetworkMonitorBase()33 NetworkMonitorBase::NetworkMonitorBase() : worker_thread_(Thread::Current()) {}
~NetworkMonitorBase()34 NetworkMonitorBase::~NetworkMonitorBase() {}
35 
OnNetworksChanged()36 void NetworkMonitorBase::OnNetworksChanged() {
37   RTC_LOG(LS_VERBOSE) << "Network change is received at the network monitor";
38   worker_thread_->Post(RTC_FROM_HERE, this, UPDATE_NETWORKS_MESSAGE);
39 }
40 
OnMessage(Message * msg)41 void NetworkMonitorBase::OnMessage(Message* msg) {
42   RTC_DCHECK(msg->message_id == UPDATE_NETWORKS_MESSAGE);
43   SignalNetworksChanged();
44 }
45 
GetVpnUnderlyingAdapterType(const std::string & interface_name)46 AdapterType NetworkMonitorBase::GetVpnUnderlyingAdapterType(
47     const std::string& interface_name) {
48   return ADAPTER_TYPE_UNKNOWN;
49 }
50 
NetworkMonitorFactory()51 NetworkMonitorFactory::NetworkMonitorFactory() {}
~NetworkMonitorFactory()52 NetworkMonitorFactory::~NetworkMonitorFactory() {}
53 
SetFactory(NetworkMonitorFactory * factory)54 void NetworkMonitorFactory::SetFactory(NetworkMonitorFactory* factory) {
55   if (network_monitor_factory != nullptr) {
56     delete network_monitor_factory;
57   }
58   network_monitor_factory = factory;
59 }
60 
ReleaseFactory(NetworkMonitorFactory * factory)61 void NetworkMonitorFactory::ReleaseFactory(NetworkMonitorFactory* factory) {
62   if (factory == network_monitor_factory) {
63     SetFactory(nullptr);
64   }
65 }
66 
GetFactory()67 NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() {
68   return network_monitor_factory;
69 }
70 
71 }  // namespace rtc
72