Index: net/android/network_change_notifier_android.cc |
diff --git a/net/android/network_change_notifier_android.cc b/net/android/network_change_notifier_android.cc |
index 473fa644eca3a15a2904577f4f2df9087c0f5f70..ed05df17a0b61e0bbc0fc746fb5324719e2fd04b 100644 |
--- a/net/android/network_change_notifier_android.cc |
+++ b/net/android/network_change_notifier_android.cc |
@@ -4,24 +4,64 @@ |
#include "net/android/network_change_notifier_android.h" |
-#include "base/logging.h" |
#include "base/android/jni_android.h" |
+#include "base/logging.h" |
#include "jni/NetworkChangeNotifier_jni.h" |
namespace net { |
namespace android { |
-NetworkChangeNotifier::NetworkChangeNotifier() { |
- JNIEnv* env = base::android::AttachCurrentThread(); |
- CreateJavaObject(env); |
+namespace { |
+ |
+// Returns whether the provided connection type is known. |
+bool CheckConnectionType(int connection_type) { |
+ switch (connection_type) { |
+ case NetworkChangeNotifier::CONNECTION_UNKNOWN: |
+ case NetworkChangeNotifier::CONNECTION_ETHERNET: |
+ case NetworkChangeNotifier::CONNECTION_WIFI: |
+ case NetworkChangeNotifier::CONNECTION_2G: |
+ case NetworkChangeNotifier::CONNECTION_3G: |
+ case NetworkChangeNotifier::CONNECTION_4G: |
+ case NetworkChangeNotifier::CONNECTION_NONE: |
+ return true; |
+ default: |
+ NOTREACHED() << "Unknown connection type received: " << connection_type; |
+ return false; |
+ } |
} |
+} // namespace |
+ |
NetworkChangeNotifier::~NetworkChangeNotifier() { |
JNIEnv* env = base::android::AttachCurrentThread(); |
Java_NetworkChangeNotifier_destroy( |
env, java_network_change_notifier_.obj()); |
} |
+void NetworkChangeNotifier::NotifyObservers( |
+ JNIEnv* env, jobject obj, jint new_connection_type) { |
+ base::subtle::Release_Store( |
+ &connection_type_, |
+ CheckConnectionType(new_connection_type) ? |
szym
2012/09/14 18:25:23
Do this jint -> int and jint -> AtomicWord implici
|
+ new_connection_type : CONNECTION_UNKNOWN); |
+ NotifyObserversOfConnectionTypeChange(); |
+} |
+ |
+jint NetworkChangeNotifier::GetConnectionType(JNIEnv* env, jobject obj) { |
+ return GetCurrentConnectionType(); |
+} |
+ |
+// static |
+bool NetworkChangeNotifier::Register(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+NetworkChangeNotifier::NetworkChangeNotifier() { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ base::subtle::Release_Store(&connection_type_, CONNECTION_UNKNOWN); |
+ CreateJavaObject(env); |
+} |
+ |
void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { |
java_network_change_notifier_.Reset( |
Java_NetworkChangeNotifier_create( |
@@ -30,42 +70,10 @@ void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { |
reinterpret_cast<jint>(this))); |
} |
-void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) { |
- NotifyObserversOfConnectionTypeChange(); |
-} |
- |
net::NetworkChangeNotifier::ConnectionType |
NetworkChangeNotifier::GetCurrentConnectionType() const { |
- JNIEnv* env = base::android::AttachCurrentThread(); |
- |
- // Pull the connection type from the Java-side then convert it to a |
- // native-side NetworkChangeNotifier::ConnectionType. |
- jint connection_type = Java_NetworkChangeNotifier_connectionType( |
- env, java_network_change_notifier_.obj()); |
- switch (connection_type) { |
- case CONNECTION_UNKNOWN: |
- return CONNECTION_UNKNOWN; |
- case CONNECTION_ETHERNET: |
- return CONNECTION_ETHERNET; |
- case CONNECTION_WIFI: |
- return CONNECTION_WIFI; |
- case CONNECTION_2G: |
- return CONNECTION_2G; |
- case CONNECTION_3G: |
- return CONNECTION_3G; |
- case CONNECTION_4G: |
- return CONNECTION_4G; |
- case CONNECTION_NONE: |
- return CONNECTION_NONE; |
- default: |
- NOTREACHED() << "Unknown connection type received: " << connection_type; |
- return CONNECTION_NONE; |
- } |
-} |
- |
-// static |
-bool NetworkChangeNotifier::Register(JNIEnv* env) { |
- return RegisterNativesImpl(env); |
+ return static_cast<net::NetworkChangeNotifier::ConnectionType>( |
+ base::subtle::Acquire_Load(&connection_type_)); |
} |
} // namespace android |