Index: webrtc/base/networkmonitor.cc |
diff --git a/webrtc/base/networkmonitor.cc b/webrtc/base/networkmonitor.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6bdaf8656995b38dc2157976c170c881913a4367 |
--- /dev/null |
+++ b/webrtc/base/networkmonitor.cc |
@@ -0,0 +1,47 @@ |
+/* |
+ * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/base/networkmonitor.h" |
+ |
+#include "webrtc/base/common.h" |
+ |
+namespace { |
+const uint32_t UPDATE_NETWORKS_MESSAGE = 1; |
+ |
+// A global network monitor factory injected by the peer connection client. |
pthatcher1
2015/10/15 08:11:43
I don't think you need to say "by the peer connect
honghaiz3
2015/10/15 19:02:41
Done.
|
+// This can be NULL if the client has not injected any factory. In that case, |
+// no network monitor will be created. If a client injected a factory, it is |
pthatcher1
2015/10/15 08:11:43
Isn't it up to callers to decided what to do if th
honghaiz3
2015/10/15 19:02:41
Done.
|
+// up to the client to release the resource by setting it to nullptr. |
+rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
+} // namespace |
+ |
+namespace rtc { |
+void NetworkMonitor::OnNetworksChanged() { |
+ LOG(LS_VERBOSE) << "Network change is received at the network monitor"; |
+ thread_->Post(this, UPDATE_NETWORKS_MESSAGE); |
+} |
+ |
+void NetworkMonitor::OnMessage(Message* msg) { |
+ ASSERT(msg->message_id == UPDATE_NETWORKS_MESSAGE); |
+ SignalNetworksChanged(); |
+} |
+ |
+void NetworkMonitorFactory::SetFactory(NetworkMonitorFactory* factory) { |
+ if (network_monitor_factory != nullptr) { |
+ delete network_monitor_factory; |
+ } |
+ network_monitor_factory = factory; |
pthatcher1
2015/10/15 08:11:43
What's the thread safety on this? Do we have to s
honghaiz3
2015/10/15 19:02:41
Added comments.
|
+} |
+ |
+NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() { |
+ return network_monitor_factory; |
+} |
+ |
+} // namespace rtc |