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 #include "net/android/network_change_notifier_android.h" | 5 #include "net/android/network_change_notifier_android.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "jni/NetworkChangeNotifier_jni.h" | 9 #include "jni/NetworkChangeNotifier_jni.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace android { | 12 namespace android { |
13 | 13 |
14 NetworkChangeNotifier::NetworkChangeNotifier() { | 14 NetworkChangeNotifier::NetworkChangeNotifier() { |
15 JNIEnv* env = base::android::AttachCurrentThread(); | 15 JNIEnv* env = base::android::AttachCurrentThread(); |
16 CreateJavaObject(env); | |
17 } | |
18 | |
19 NetworkChangeNotifier::~NetworkChangeNotifier() { | |
20 JNIEnv* env = base::android::AttachCurrentThread(); | |
21 Java_NetworkChangeNotifier_destroy( | |
22 env, java_network_change_notifier_.obj()); | |
23 } | |
24 | |
25 void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { | |
26 java_network_change_notifier_.Reset( | 16 java_network_change_notifier_.Reset( |
27 Java_NetworkChangeNotifier_create( | 17 Java_NetworkChangeNotifier_createInstance( |
28 env, | 18 env, |
29 base::android::GetApplicationContext(), | 19 base::android::GetApplicationContext(), |
30 reinterpret_cast<jint>(this))); | 20 reinterpret_cast<jint>(this))); |
31 } | 21 } |
32 | 22 |
33 void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) { | 23 NetworkChangeNotifier::~NetworkChangeNotifier() { |
34 NotifyObserversOfConnectionTypeChange(); | 24 JNIEnv* env = base::android::AttachCurrentThread(); |
25 Java_NetworkChangeNotifier_destroyInstance(env); | |
26 java_network_change_notifier_.Reset(); | |
27 } | |
28 | |
29 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(JNIEnv* env, | |
szym
2012/09/14 19:07:29
watch out for conflict with http://codereview.chro
gone
2012/09/15 01:01:55
Keeping an eye on it.
| |
30 jobject obj) { | |
31 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); | |
32 } | |
33 | |
34 void NetworkChangeNotifier::ForceConnectivityState(bool state) { | |
35 JNIEnv* env = base::android::AttachCurrentThread(); | |
36 Java_NetworkChangeNotifier_forceConnectivityState(env, state); | |
35 } | 37 } |
36 | 38 |
37 net::NetworkChangeNotifier::ConnectionType | 39 net::NetworkChangeNotifier::ConnectionType |
38 NetworkChangeNotifier::GetCurrentConnectionType() const { | 40 NetworkChangeNotifier::GetCurrentConnectionType() const { |
39 JNIEnv* env = base::android::AttachCurrentThread(); | 41 JNIEnv* env = base::android::AttachCurrentThread(); |
40 | 42 |
41 // Pull the connection type from the Java-side then convert it to a | 43 // Pull the connection type from the Java-side then convert it to a |
42 // native-side NetworkChangeNotifier::ConnectionType. | 44 // native-side NetworkChangeNotifier::ConnectionType. |
43 jint connection_type = Java_NetworkChangeNotifier_connectionType( | 45 jint connection_type = Java_NetworkChangeNotifier_connectionType( |
44 env, java_network_change_notifier_.obj()); | 46 env, java_network_change_notifier_.obj()); |
(...skipping 18 matching lines...) Expand all Loading... | |
63 } | 65 } |
64 } | 66 } |
65 | 67 |
66 // static | 68 // static |
67 bool NetworkChangeNotifier::Register(JNIEnv* env) { | 69 bool NetworkChangeNotifier::Register(JNIEnv* env) { |
68 return RegisterNativesImpl(env); | 70 return RegisterNativesImpl(env); |
69 } | 71 } |
70 | 72 |
71 } // namespace android | 73 } // namespace android |
72 } // namespace net | 74 } // namespace net |
OLD | NEW |