honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 11 | #include "rtc_base/network_monitor.h" |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include "rtc_base/location.h" |
Yves Gerey | 2e00abc | 2018-10-05 15:39:24 +0200 | [diff] [blame] | 17 | #include "rtc_base/logging.h" |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 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 { |
| 29 | NetworkMonitorInterface::NetworkMonitorInterface() {} |
| 30 | |
| 31 | NetworkMonitorInterface::~NetworkMonitorInterface() {} |
| 32 | |
honghaiz | cec0a08 | 2016-01-15 14:49:09 -0800 | [diff] [blame] | 33 | NetworkMonitorBase::NetworkMonitorBase() : worker_thread_(Thread::Current()) {} |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 34 | NetworkMonitorBase::~NetworkMonitorBase() {} |
| 35 | |
| 36 | void NetworkMonitorBase::OnNetworksChanged() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 37 | RTC_LOG(LS_VERBOSE) << "Network change is received at the network monitor"; |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 38 | worker_thread_->Post(RTC_FROM_HERE, this, UPDATE_NETWORKS_MESSAGE); |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void NetworkMonitorBase::OnMessage(Message* msg) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 42 | RTC_DCHECK(msg->message_id == UPDATE_NETWORKS_MESSAGE); |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 43 | SignalNetworksChanged(); |
| 44 | } |
| 45 | |
Qingsi Wang | de2ed7d | 2018-04-27 14:25:37 -0700 | [diff] [blame] | 46 | AdapterType NetworkMonitorBase::GetVpnUnderlyingAdapterType( |
| 47 | const std::string& interface_name) { |
| 48 | return ADAPTER_TYPE_UNKNOWN; |
| 49 | } |
| 50 | |
honghaiz | 023f3ef | 2015-10-19 09:39:32 -0700 | [diff] [blame] | 51 | NetworkMonitorFactory::NetworkMonitorFactory() {} |
| 52 | NetworkMonitorFactory::~NetworkMonitorFactory() {} |
| 53 | |
| 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 | |
| 61 | void NetworkMonitorFactory::ReleaseFactory(NetworkMonitorFactory* factory) { |
| 62 | if (factory == network_monitor_factory) { |
| 63 | SetFactory(nullptr); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() { |
| 68 | return network_monitor_factory; |
| 69 | } |
| 70 | |
| 71 | } // namespace rtc |