| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 std::string GetCurrentWiFiSSID() const; |
| 109 | 110 |
| 110 // Can only be called from the main (Java) thread. | 111 // Can only be called from the main (Java) thread. |
| 111 NetworkChangeNotifier::ConnectionSubtype GetCurrentConnectionSubtype() const; | 112 NetworkChangeNotifier::ConnectionSubtype GetCurrentConnectionSubtype() const; |
| 112 | 113 |
| 113 // Initializes JNI bindings. | 114 // Initializes JNI bindings. |
| 114 static bool Register(JNIEnv* env); | 115 static bool Register(JNIEnv* env); |
| 115 | 116 |
| 116 private: | 117 private: |
| 117 friend class BaseNetworkChangeNotifierAndroidTest; | 118 friend class BaseNetworkChangeNotifierAndroidTest; |
| 118 | 119 |
| 119 // Map of active connected networks and their connection type. | 120 // Map of active connected networks and their connection type. |
| 120 typedef std::map<NetworkHandle, ConnectionType> NetworkMap; | 121 typedef std::map<NetworkHandle, ConnectionType> NetworkMap; |
| 121 | 122 |
| 122 // Converts a Java int[] into a NetworkMap. Expects int[] to contain | 123 // Converts a Java int[] into a NetworkMap. Expects int[] to contain |
| 123 // repeated instances of: NetworkHandle, ConnectionType | 124 // repeated instances of: NetworkHandle, ConnectionType |
| 124 static void JavaIntArrayToNetworkMap(JNIEnv* env, | 125 static void JavaIntArrayToNetworkMap(JNIEnv* env, |
| 125 jintArray int_array, | 126 jintArray int_array, |
| 126 NetworkMap* network_map); | 127 NetworkMap* network_map); |
| 127 | 128 |
| 128 // Setters that grab appropriate lock. | 129 // Setters that grab appropriate lock. |
| 129 void SetCurrentConnectionType(ConnectionType connection_type); | 130 void SetCurrentConnectionType(ConnectionType connection_type); |
| 131 void SetCurrentSSID(const std::string& new_ssid); |
| 130 void SetCurrentMaxBandwidth(double max_bandwidth); | 132 void SetCurrentMaxBandwidth(double max_bandwidth); |
| 131 void SetCurrentDefaultNetwork(NetworkHandle default_network); | 133 void SetCurrentDefaultNetwork(NetworkHandle default_network); |
| 132 void SetCurrentNetworksAndTypes(NetworkMap network_map); | 134 void SetCurrentNetworksAndTypes(NetworkMap network_map); |
| 133 | 135 |
| 134 // Methods calling the Java side exposed for testing. | 136 // Methods calling the Java side exposed for testing. |
| 135 void SetOnline(); | 137 void SetOnline(); |
| 136 void SetOffline(); | 138 void SetOffline(); |
| 137 void FakeNetworkConnected(NetworkHandle network, ConnectionType type); | 139 void FakeNetworkConnected(NetworkHandle network, ConnectionType type); |
| 138 void FakeNetworkSoonToBeDisconnected(NetworkHandle network); | 140 void FakeNetworkSoonToBeDisconnected(NetworkHandle network); |
| 139 void FakeNetworkDisconnected(NetworkHandle network); | 141 void FakeNetworkDisconnected(NetworkHandle network); |
| 140 void FakePurgeActiveNetworkList(NetworkList networks); | 142 void FakePurgeActiveNetworkList(NetworkList networks); |
| 141 void FakeDefaultNetwork(NetworkHandle network, ConnectionType type); | 143 void FakeDefaultNetwork(NetworkHandle network, ConnectionType type); |
| 142 void FakeMaxBandwidthChanged(double max_bandwidth_mbps); | 144 void FakeMaxBandwidthChanged(double max_bandwidth_mbps); |
| 143 | 145 |
| 144 base::ThreadChecker thread_checker_; | 146 base::ThreadChecker thread_checker_; |
| 145 scoped_refptr<base::ObserverListThreadSafe<Observer>> observers_; | 147 scoped_refptr<base::ObserverListThreadSafe<Observer>> observers_; |
| 146 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; | 148 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; |
| 147 | 149 |
| 148 mutable base::Lock connection_lock_; // Protects the state below. | 150 mutable base::Lock connection_lock_; // Protects the state below. |
| 149 ConnectionType connection_type_; | 151 ConnectionType connection_type_; |
| 152 std::string current_ssid_; |
| 150 double connection_max_bandwidth_; | 153 double connection_max_bandwidth_; |
| 151 NetworkHandle default_network_; | 154 NetworkHandle default_network_; |
| 152 NetworkMap network_map_; | 155 NetworkMap network_map_; |
| 153 | 156 |
| 154 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); | 157 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid); |
| 155 }; | 158 }; |
| 156 | 159 |
| 157 } // namespace net | 160 } // namespace net |
| 158 | 161 |
| 159 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ | 162 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_DELEGATE_ANDROID_H_ |
| OLD | NEW |