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/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "jni/NetworkChangeNotifier_jni.h" | 9 #include "jni/NetworkChangeNotifier_jni.h" |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 jint NetworkChangeNotifierAndroid::GetConnectionType(JNIEnv* env, jobject obj) { | 49 jint NetworkChangeNotifierAndroid::GetConnectionType(JNIEnv* env, jobject obj) { |
50 return GetCurrentConnectionType(); | 50 return GetCurrentConnectionType(); |
51 } | 51 } |
52 | 52 |
53 // static | 53 // static |
54 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { | 54 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { |
55 return RegisterNativesImpl(env); | 55 return RegisterNativesImpl(env); |
56 } | 56 } |
57 | 57 |
58 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid() { | 58 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid() |
| 59 : NetworkChangeNotifier(0, 0, 0, 0) { |
59 SetConnectionType(CONNECTION_UNKNOWN); | 60 SetConnectionType(CONNECTION_UNKNOWN); |
60 JNIEnv* env = base::android::AttachCurrentThread(); | 61 JNIEnv* env = base::android::AttachCurrentThread(); |
61 java_network_change_notifier_.Reset( | 62 java_network_change_notifier_.Reset( |
62 Java_NetworkChangeNotifier_createInstance( | 63 Java_NetworkChangeNotifier_createInstance( |
63 env, | 64 env, |
64 base::android::GetApplicationContext(), | 65 base::android::GetApplicationContext(), |
65 reinterpret_cast<jint>(this))); | 66 reinterpret_cast<jint>(this))); |
66 } | 67 } |
67 | 68 |
68 void NetworkChangeNotifierAndroid::SetConnectionType(int connection_type) { | 69 void NetworkChangeNotifierAndroid::SetConnectionType(int connection_type) { |
69 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
70 connection_type_ = connection_type; | 71 connection_type_ = connection_type; |
71 } | 72 } |
72 | 73 |
73 void NetworkChangeNotifierAndroid::ForceConnectivityState(bool state) { | 74 void NetworkChangeNotifierAndroid::ForceConnectivityState(bool state) { |
74 JNIEnv* env = base::android::AttachCurrentThread(); | 75 JNIEnv* env = base::android::AttachCurrentThread(); |
75 Java_NetworkChangeNotifier_forceConnectivityState(env, state); | 76 Java_NetworkChangeNotifier_forceConnectivityState(env, state); |
76 } | 77 } |
77 | 78 |
78 NetworkChangeNotifier::ConnectionType | 79 NetworkChangeNotifier::ConnectionType |
79 NetworkChangeNotifierAndroid::GetCurrentConnectionType() const { | 80 NetworkChangeNotifierAndroid::GetCurrentConnectionType() const { |
80 base::AutoLock auto_lock(lock_); | 81 base::AutoLock auto_lock(lock_); |
81 return static_cast<NetworkChangeNotifier::ConnectionType>(connection_type_); | 82 return static_cast<NetworkChangeNotifier::ConnectionType>(connection_type_); |
82 } | 83 } |
83 | 84 |
84 } // namespace net | 85 } // namespace net |
OLD | NEW |