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

Unified Diff: net/android/network_change_notifier_android.cc

Issue 10693068: Refactor Android's NetworckChangeNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
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 d810a33568c5b050ea221a9957a44dbb2fb04291..b9dc3e9d3ccf81477c8e0e0d87ab254db28c14c1 100644
--- a/net/android/network_change_notifier_android.cc
+++ b/net/android/network_change_notifier_android.cc
@@ -4,49 +4,29 @@
#include "net/android/network_change_notifier_android.h"
-#include "base/logging.h"
-#include "base/android/jni_android.h"
-#include "jni/network_change_notifier_jni.h"
-
namespace net {
namespace android {
-NetworkChangeNotifier::NetworkChangeNotifier() {
- JNIEnv* env = base::android::AttachCurrentThread();
- CreateJavaObject(env);
+NetworkChangeNotifier::NetworkChangeNotifier() : is_connected_(false) {
}
NetworkChangeNotifier::~NetworkChangeNotifier() {
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_NetworkChangeNotifier_unregisterReceiver(
- env, java_network_change_notifier_.obj());
-}
-
-void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) {
- java_network_change_notifier_.Reset(
- Java_NetworkChangeNotifier_create(
- env,
- base::android::GetApplicationContext(),
- reinterpret_cast<jint>(this)));
-}
-
-void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) {
- NotifyObserversOfConnectionTypeChange();
}
net::NetworkChangeNotifier::ConnectionType
NetworkChangeNotifier::GetCurrentConnectionType() const {
- JNIEnv* env = base::android::AttachCurrentThread();
- // TODO(droger): Return something more detailed than CONNECTION_UNKNOWN.
- return Java_NetworkChangeNotifier_isConnected(
- env, java_network_change_notifier_.obj()) ?
- net::NetworkChangeNotifier::CONNECTION_UNKNOWN :
- net::NetworkChangeNotifier::CONNECTION_NONE;
+ // TODO(benm): Add support for returning different types of connection here.
+ // See crbug.com/112937
+ return is_connected_ ?
+ net::NetworkChangeNotifier::CONNECTION_UNKNOWN :
+ net::NetworkChangeNotifier::CONNECTION_NONE;
}
-// static
-bool NetworkChangeNotifier::Register(JNIEnv* env) {
- return RegisterNativesImpl(env);
+void NetworkChangeNotifier::setConnected(bool network_up) {
+ if (is_connected_ != network_up) {
+ is_connected_ = network_up;
+ NotifyObserversOfConnectionTypeChange();
+ }
}
} // namespace android

Powered by Google App Engine
This is Rietveld 408576698