Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: talk/app/webrtc/java/jni/androidnetworkmonitor_jni.h

Issue 1556743002: Bind a socket to a network if the network handle is set. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a compiling issue for Windows Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 12 matching lines...) Expand all
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #ifndef TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ 28 #ifndef TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
29 #define TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ 29 #define TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
30 30
31 #include "webrtc/base/networkmonitor.h" 31 #include "webrtc/base/networkmonitor.h"
32 32
33 #include <map>
34
35 #include "webrtc/base/criticalsection.h"
33 #include "webrtc/base/thread_checker.h" 36 #include "webrtc/base/thread_checker.h"
34 #include "talk/app/webrtc/java/jni/jni_helpers.h" 37 #include "talk/app/webrtc/java/jni/jni_helpers.h"
35 38
36 namespace webrtc_jni { 39 namespace webrtc_jni {
37 40
41 // c++ equivalent of java NetworkMonitorAutoDetect.ConnectionType.
42 enum NetworkType {
43 NETWORK_UNKNOWN,
44 NETWORK_ETHERNET,
45 NETWORK_WIFI,
46 NETWORK_4G,
47 NETWORK_3G,
48 NETWORK_2G,
49 NETWORK_BLUETOOTH,
50 NETWORK_NONE
51 };
52
53 // c++ equivalent of NetworkMonitorAutoDetect.NetworkInformation.
pthatcher1 2016/01/14 20:07:24 The comments are mutually recursive. Could one of
honghaiz3 2016/01/15 01:00:38 Done.
54 struct NetworkInformation {
55 std::string interface_name;
56 rtc::NetworkHandle handle;
57 NetworkType type;
58 std::vector<rtc::IPAddress> ip_addresses;
59
60 std::string ToString() const;
61 };
62
38 class AndroidNetworkMonitor : public rtc::NetworkMonitorBase { 63 class AndroidNetworkMonitor : public rtc::NetworkMonitorBase {
39 public: 64 public:
40 AndroidNetworkMonitor(); 65 AndroidNetworkMonitor();
41 66
42 static void SetAndroidContext(JNIEnv* jni, jobject context); 67 static void SetAndroidContext(JNIEnv* jni, jobject context);
43 68
44 void Start() override; 69 void Start() override;
45 void Stop() override; 70 void Stop() override;
46 71
72 int BindSocketToNetwork(int socket_fd,
73 const rtc::IPAddress& address) override;
74 void OnNetworkAvailable(const NetworkInformation& network_info);
75
47 private: 76 private:
48 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); } 77 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); }
49 78
50 ScopedGlobalRef<jclass> j_network_monitor_class_; 79 ScopedGlobalRef<jclass> j_network_monitor_class_;
51 ScopedGlobalRef<jobject> j_network_monitor_; 80 ScopedGlobalRef<jobject> j_network_monitor_;
52 rtc::ThreadChecker thread_checker_; 81 rtc::ThreadChecker thread_checker_;
53 static jobject application_context_; 82 static jobject application_context_;
83 std::map<rtc::IPAddress, NetworkInformation> network_info_map_;
pthatcher1 2016/01/14 20:07:24 A better name might be networy_info_by_address_.
honghaiz3 2016/01/15 01:00:38 Done.
54 }; 84 };
55 85
56 class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory { 86 class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory {
57 public: 87 public:
58 AndroidNetworkMonitorFactory() {} 88 AndroidNetworkMonitorFactory() {}
59 89
60 rtc::NetworkMonitorInterface* CreateNetworkMonitor() override { 90 rtc::NetworkMonitorInterface* GetOrCreateNetworkMonitor() override;
61 return new AndroidNetworkMonitor(); 91
62 } 92 private:
93 rtc::CriticalSection crit_;
94 rtc::scoped_ptr<AndroidNetworkMonitor> network_monitor_;
63 }; 95 };
64 96
65 } // namespace webrtc_jni 97 } // namespace webrtc_jni
66 98
67 #endif // TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ 99 #endif // TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698