OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ | 5 #ifndef NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ |
6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ | 6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ~NetworkChangeNotifierDelegateAndroid(); | 47 ~NetworkChangeNotifierDelegateAndroid(); |
48 | 48 |
49 // Called from NetworkChangeNotifier.java on the JNI thread whenever | 49 // Called from NetworkChangeNotifier.java on the JNI thread whenever |
50 // the connection type changes. This updates the current connection type seen | 50 // the connection type changes. This updates the current connection type seen |
51 // by this class and forwards the notification to the observers that | 51 // by this class and forwards the notification to the observers that |
52 // subscribed through AddObserver(). | 52 // subscribed through AddObserver(). |
53 void NotifyConnectionTypeChanged( | 53 void NotifyConnectionTypeChanged( |
54 JNIEnv* env, | 54 JNIEnv* env, |
55 const base::android::JavaParamRef<jobject>& obj, | 55 const base::android::JavaParamRef<jobject>& obj, |
56 jint new_connection_type, | 56 jint new_connection_type, |
57 jint default_netid); | 57 jlong default_netid); |
58 jint GetConnectionType(JNIEnv* env, jobject obj) const; | 58 jint GetConnectionType(JNIEnv* env, jobject obj) const; |
59 | 59 |
60 // Called from NetworkChangeNotifier.java on the JNI thread whenever | 60 // Called from NetworkChangeNotifier.java on the JNI thread whenever |
61 // the maximum bandwidth of the connection changes. This updates the current | 61 // the maximum bandwidth of the connection changes. This updates the current |
62 // max bandwidth seen by this class and forwards the notification to the | 62 // max bandwidth seen by this class and forwards the notification to the |
63 // observers that subscribed through AddObserver(). | 63 // observers that subscribed through AddObserver(). |
64 void NotifyMaxBandwidthChanged( | 64 void NotifyMaxBandwidthChanged( |
65 JNIEnv* env, | 65 JNIEnv* env, |
66 const base::android::JavaParamRef<jobject>& obj, | 66 const base::android::JavaParamRef<jobject>& obj, |
67 jdouble new_max_bandwidth); | 67 jdouble new_max_bandwidth); |
68 | 68 |
69 // Called from NetworkChangeNotifier.java on the JNI thread to push | 69 // Called from NetworkChangeNotifier.java on the JNI thread to push |
70 // down notifications of network connectivity events. These functions in | 70 // down notifications of network connectivity events. These functions in |
71 // turn: | 71 // turn: |
72 // 1) Update |network_map_| and |default_network_|. | 72 // 1) Update |network_map_| and |default_network_|. |
73 // 2) Push notifications to NetworkChangeNotifier which in turn pushes | 73 // 2) Push notifications to NetworkChangeNotifier which in turn pushes |
74 // notifications to its NetworkObservers. Note that these functions | 74 // notifications to its NetworkObservers. Note that these functions |
75 // perform valuable transformations on the signals like deduplicating. | 75 // perform valuable transformations on the signals like deduplicating. |
76 // For descriptions of what individual calls mean, see | 76 // For descriptions of what individual calls mean, see |
77 // NetworkChangeNotifierAutoDetect.Observer functions of the same names. | 77 // NetworkChangeNotifierAutoDetect.Observer functions of the same names. |
78 void NotifyOfNetworkConnect(JNIEnv* env, | 78 void NotifyOfNetworkConnect(JNIEnv* env, |
79 const base::android::JavaParamRef<jobject>& obj, | 79 const base::android::JavaParamRef<jobject>& obj, |
80 jint net_id, | 80 jlong net_id, |
81 jint connection_type); | 81 jint connection_type); |
82 void NotifyOfNetworkSoonToDisconnect( | 82 void NotifyOfNetworkSoonToDisconnect( |
83 JNIEnv* env, | 83 JNIEnv* env, |
84 const base::android::JavaParamRef<jobject>& obj, | 84 const base::android::JavaParamRef<jobject>& obj, |
85 jint net_id); | 85 jlong net_id); |
86 void NotifyOfNetworkDisconnect( | 86 void NotifyOfNetworkDisconnect( |
87 JNIEnv* env, | 87 JNIEnv* env, |
88 const base::android::JavaParamRef<jobject>& obj, | 88 const base::android::JavaParamRef<jobject>& obj, |
89 jint net_id); | 89 jlong net_id); |
90 void NotifyPurgeActiveNetworkList( | 90 void NotifyPurgeActiveNetworkList( |
91 JNIEnv* env, | 91 JNIEnv* env, |
92 const base::android::JavaParamRef<jobject>& obj, | 92 const base::android::JavaParamRef<jobject>& obj, |
93 const base::android::JavaParamRef<jintArray>& active_networks); | 93 const base::android::JavaParamRef<jlongArray>& active_networks); |
94 | 94 |
95 // These methods can be called on any thread. Note that the provided observer | 95 // These methods can be called on any thread. Note that the provided observer |
96 // will be notified on the thread AddObserver() is called on. | 96 // will be notified on the thread AddObserver() is called on. |
97 void AddObserver(Observer* observer); | 97 void AddObserver(Observer* observer); |
98 void RemoveObserver(Observer* observer); | 98 void RemoveObserver(Observer* observer); |
99 | 99 |
100 // These methods are simply implementations of NetworkChangeNotifier APIs of | 100 // These methods are simply implementations of NetworkChangeNotifier APIs of |
101 // the same name. They can be called from any thread. | 101 // the same name. They can be called from any thread. |
102 ConnectionType GetCurrentConnectionType() const; | 102 ConnectionType GetCurrentConnectionType() const; |
103 void GetCurrentMaxBandwidthAndConnectionType( | 103 void GetCurrentMaxBandwidthAndConnectionType( |
104 double* max_bandwidth_mbps, | 104 double* max_bandwidth_mbps, |
105 ConnectionType* connection_type) const; | 105 ConnectionType* connection_type) const; |
106 ConnectionType GetNetworkConnectionType(NetworkHandle network) const; | 106 ConnectionType GetNetworkConnectionType(NetworkHandle network) const; |
107 NetworkHandle GetCurrentDefaultNetwork() const; | 107 NetworkHandle GetCurrentDefaultNetwork() const; |
108 void GetCurrentlyConnectedNetworks(NetworkList* network_list) const; | 108 void GetCurrentlyConnectedNetworks(NetworkList* network_list) const; |
109 | 109 |
110 // Can only be called from the main (Java) thread. | 110 // Can only be called from the main (Java) thread. |
111 NetworkChangeNotifier::ConnectionSubtype GetCurrentConnectionSubtype() const; | 111 NetworkChangeNotifier::ConnectionSubtype GetCurrentConnectionSubtype() const; |
112 | 112 |
113 // Initializes JNI bindings. | 113 // Initializes JNI bindings. |
114 static bool Register(JNIEnv* env); | 114 static bool Register(JNIEnv* env); |
115 | 115 |
116 private: | 116 private: |
117 friend class BaseNetworkChangeNotifierAndroidTest; | 117 friend class BaseNetworkChangeNotifierAndroidTest; |
118 | 118 |
119 // Map of active connected networks and their connection type. | 119 // Map of active connected networks and their connection type. |
120 typedef std::map<NetworkHandle, ConnectionType> NetworkMap; | 120 typedef std::map<NetworkHandle, ConnectionType> NetworkMap; |
121 | 121 |
122 // Converts a Java int[] into a NetworkMap. Expects int[] to contain | 122 // Converts a Java long[] into a NetworkMap. Expects long[] to contain |
123 // repeated instances of: NetworkHandle, ConnectionType | 123 // repeated instances of: NetworkHandle, ConnectionType |
124 static void JavaIntArrayToNetworkMap(JNIEnv* env, | 124 static void JavaLongArrayToNetworkMap(JNIEnv* env, |
125 jintArray int_array, | 125 jlongArray long_array, |
126 NetworkMap* network_map); | 126 NetworkMap* network_map); |
127 | 127 |
128 // Setters that grab appropriate lock. | 128 // Setters that grab appropriate lock. |
129 void SetCurrentConnectionType(ConnectionType connection_type); | 129 void SetCurrentConnectionType(ConnectionType connection_type); |
130 void SetCurrentMaxBandwidth(double max_bandwidth); | 130 void SetCurrentMaxBandwidth(double max_bandwidth); |
131 void SetCurrentDefaultNetwork(NetworkHandle default_network); | 131 void SetCurrentDefaultNetwork(NetworkHandle default_network); |
132 void SetCurrentNetworksAndTypes(NetworkMap network_map); | 132 void SetCurrentNetworksAndTypes(NetworkMap network_map); |
133 | 133 |
134 // Methods calling the Java side exposed for testing. | 134 // Methods calling the Java side exposed for testing. |
135 void SetOnline(); | 135 void SetOnline(); |
136 void SetOffline(); | 136 void SetOffline(); |
(...skipping 13 matching lines...) Expand all Loading... |
150 double connection_max_bandwidth_; | 150 double connection_max_bandwidth_; |
151 NetworkHandle default_network_; | 151 NetworkHandle default_network_; |
152 NetworkMap network_map_; | 152 NetworkMap network_map_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); | 154 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); |
155 }; | 155 }; |
156 | 156 |
157 } // namespace net | 157 } // namespace net |
158 | 158 |
159 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ | 159 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ |
OLD | NEW |