Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #ifndef WEBRTC_BASE_NETWORKMONITOR_H_ | |
| 12 #define WEBRTC_BASE_NETWORKMONITOR_H_ | |
| 13 | |
| 14 #include "webrtc/base/logging.h" | |
| 15 #include "webrtc/base/scoped_ptr.h" | |
| 16 #include "webrtc/base/sigslot.h" | |
| 17 #include "webrtc/base/thread.h" | |
| 18 | |
| 19 namespace rtc { | |
| 20 /* | |
| 21 * Receives network-change events via |OnNetworksChanged| and signals the | |
| 22 * networks changed event. | |
| 23 * | |
| 24 * Threading consideration: | |
| 25 * It is expected that all upstream operations (from native to Java) are | |
| 26 * performed from the worker thread. This includes creating, starting and | |
| 27 * stopping the monitor. This avoids the potential race condition when creating | |
| 28 * the singleton Java NetworkMonitor class. Downstream operations can be from | |
| 29 * any thread, but this class will forward all the downstream operations onto | |
| 30 * the worker thread. | |
| 31 * | |
| 32 * Memory consideration: | |
| 33 * NetworkMonitor is owned by the caller (NetworkManager). The global network | |
| 34 * monitor factory is owned by the factory itself but needs to be released from | |
| 35 * the factory creator by setting it to null. | |
| 36 */ | |
| 37 class NetworkMonitor : public MessageHandler, public sigslot::has_slots<> { | |
|
pthatcher1
2015/10/15 08:11:43
It seems like this should be called NetworkMontior
honghaiz3
2015/10/15 19:02:42
Done.
| |
| 38 public: | |
| 39 sigslot::signal0<> SignalNetworksChanged; | |
| 40 | |
| 41 NetworkMonitor() : thread_(Thread::Current()) {} | |
| 42 virtual ~NetworkMonitor() {} | |
| 43 | |
| 44 // Creates and starts network monitoring | |
| 45 virtual void StartMonitoring() = 0; | |
| 46 // Stops and removes network monitoring | |
| 47 virtual void StopMonitoring() = 0; | |
|
pthatcher1
2015/10/15 08:11:43
Why not just Start() and Stop()? And I don't thin
honghaiz3
2015/10/15 19:02:42
Done.
| |
| 48 | |
| 49 // Called when it receives a network-change event from the network monitor. | |
|
pthatcher1
2015/10/15 08:11:43
The network monitor method is called when it recei
honghaiz3
2015/10/15 19:02:41
Done.
| |
| 50 void OnNetworksChanged(); | |
| 51 | |
| 52 void OnMessage(Message* msg) override; | |
| 53 | |
| 54 private: | |
| 55 Thread* thread_; | |
| 56 }; | |
| 57 | |
| 58 /* | |
| 59 * NetworkMonitorFactory creates NetworkMonitors. | |
| 60 */ | |
| 61 class NetworkMonitorFactory { | |
| 62 public: | |
| 63 static void SetFactory(NetworkMonitorFactory* factory); | |
| 64 static NetworkMonitorFactory* GetFactory(); | |
| 65 | |
| 66 virtual NetworkMonitor* CreateNetworkMonitor() = 0; | |
| 67 | |
| 68 virtual ~NetworkMonitorFactory() {} | |
| 69 | |
| 70 protected: | |
| 71 NetworkMonitorFactory() {} | |
| 72 }; | |
| 73 | |
| 74 } // namespace rtc | |
| 75 | |
| 76 #endif // WEBRTC_BASE_NETWORKMONITOR_H_ | |
| OLD | NEW |