Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/android/network_change_notifier.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/android/jni_android.h" | |
| 9 | |
| 10 using net::android::NetworkChangeNotifier; | |
| 11 #include "jni/network_change_notifier_jni.h" | |
|
Ryan Sleevi
2012/04/13 22:37:58
This seems like a cheap hack to avoid the "don't u
Yaron
2012/04/17 16:18:03
Hmm. So the header is auto-generated by the jni_ge
Ryan Sleevi
2012/04/17 17:56:06
Update the jni generator? ;)
| |
| 12 | |
| 13 namespace net { | |
| 14 namespace android { | |
| 15 | |
| 16 | |
|
Ryan Sleevi
2012/04/13 22:37:58
nit: delete this whitespace
Yaron
2012/04/17 16:18:03
Done.
| |
| 17 NetworkChangeNotifier::NetworkChangeNotifier() { | |
| 18 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 19 CHECK(java_network_change_notifier_android_object_.is_null()); | |
|
Ryan Sleevi
2012/04/13 22:37:58
Why CHECK here? You're in a constructor - how is t
Yaron
2012/04/17 16:18:03
Done.
| |
| 20 CreateJavaObject(env); | |
| 21 } | |
| 22 | |
| 23 NetworkChangeNotifier::~NetworkChangeNotifier() { | |
| 24 CHECK(!java_network_change_notifier_android_object_.is_null()); | |
|
Ryan Sleevi
2012/04/13 22:37:58
Unnecessary CHECK? This is also guaranteed.
Yaron
2012/04/17 16:18:03
Done.
| |
| 25 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 26 Java_NetworkChangeNotifier_unregisterReceiver( | |
| 27 env, java_network_change_notifier_android_object_.obj()); | |
| 28 java_network_change_notifier_android_object_.Reset(); | |
|
Ryan Sleevi
2012/04/13 22:37:58
Isn't this unnecessary and guaranteed by the destr
Yaron
2012/04/17 16:18:03
Done.
| |
| 29 } | |
| 30 | |
| 31 void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { | |
| 32 java_network_change_notifier_android_object_.Reset( | |
| 33 Java_NetworkChangeNotifier_create( | |
| 34 env, | |
| 35 base::android::GetApplicationContext(), | |
| 36 reinterpret_cast<jint>(this))); | |
| 37 CHECK(!java_network_change_notifier_android_object_.is_null()); | |
|
Ryan Sleevi
2012/04/13 22:37:58
Do you really need to CHECK here? Would a DCHECK s
Yaron
2012/04/17 16:18:03
Done.
| |
| 38 } | |
| 39 | |
| 40 void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) { | |
| 41 NotifyObserversOfOnlineStateChange(); | |
| 42 } | |
| 43 | |
| 44 bool NetworkChangeNotifier::IsCurrentlyOffline() const { | |
| 45 CHECK(!java_network_change_notifier_android_object_.is_null()); | |
|
Ryan Sleevi
2012/04/13 22:37:58
And here
Yaron
2012/04/17 16:18:03
Done.
| |
| 46 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 47 return !Java_NetworkChangeNotifier_isConnected( | |
| 48 env, java_network_change_notifier_android_object_.obj()); | |
| 49 } | |
| 50 | |
| 51 bool RegisterNetworkChangeNotifier(JNIEnv* env) { | |
| 52 return RegisterNativesImpl(env); | |
| 53 } | |
| 54 | |
| 55 } // namespace android | |
| 56 } // namespace net | |
| OLD | NEW |