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

Side by Side Diff: net/android/network_change_notifier_android.cc

Issue 10928193: Add native-side unit test for Android NetworkChangeNotifier (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebasing Created 8 years, 3 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 unified diff | Download patch
OLDNEW
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 {
13 12
14 NetworkChangeNotifier::NetworkChangeNotifier() { 13 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid() {
15 JNIEnv* env = base::android::AttachCurrentThread(); 14 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( 15 java_network_change_notifier_.Reset(
27 Java_NetworkChangeNotifier_create( 16 Java_NetworkChangeNotifier_createInstance(
28 env, 17 env,
29 base::android::GetApplicationContext(), 18 base::android::GetApplicationContext(),
30 reinterpret_cast<jint>(this))); 19 reinterpret_cast<jint>(this)));
31 } 20 }
32 21
33 void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) { 22 NetworkChangeNotifierAndroid::~NetworkChangeNotifierAndroid() {
34 NotifyObserversOfConnectionTypeChange(); 23 JNIEnv* env = base::android::AttachCurrentThread();
24 Java_NetworkChangeNotifier_destroyInstance(env);
25 java_network_change_notifier_.Reset();
35 } 26 }
36 27
37 net::NetworkChangeNotifier::ConnectionType 28 void NetworkChangeNotifierAndroid::NotifyObserversOfConnectionTypeChange(
38 NetworkChangeNotifier::GetCurrentConnectionType() const { 29 JNIEnv* env,
30 jobject obj) {
31 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange();
32 }
33
34 void NetworkChangeNotifierAndroid::ForceConnectivityState(bool state) {
35 JNIEnv* env = base::android::AttachCurrentThread();
36 Java_NetworkChangeNotifier_forceConnectivityState(env, state);
37 }
38
39 NetworkChangeNotifier::ConnectionType
40 NetworkChangeNotifierAndroid::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());
45 switch (connection_type) { 47 switch (connection_type) {
46 case CONNECTION_UNKNOWN: 48 case CONNECTION_UNKNOWN:
47 return CONNECTION_UNKNOWN; 49 return CONNECTION_UNKNOWN;
48 case CONNECTION_ETHERNET: 50 case CONNECTION_ETHERNET:
49 return CONNECTION_ETHERNET; 51 return CONNECTION_ETHERNET;
50 case CONNECTION_WIFI: 52 case CONNECTION_WIFI:
51 return CONNECTION_WIFI; 53 return CONNECTION_WIFI;
52 case CONNECTION_2G: 54 case CONNECTION_2G:
53 return CONNECTION_2G; 55 return CONNECTION_2G;
54 case CONNECTION_3G: 56 case CONNECTION_3G:
55 return CONNECTION_3G; 57 return CONNECTION_3G;
56 case CONNECTION_4G: 58 case CONNECTION_4G:
57 return CONNECTION_4G; 59 return CONNECTION_4G;
58 case CONNECTION_NONE: 60 case CONNECTION_NONE:
59 return CONNECTION_NONE; 61 return CONNECTION_NONE;
60 default: 62 default:
61 NOTREACHED() << "Unknown connection type received: " << connection_type; 63 NOTREACHED() << "Unknown connection type received: " << connection_type;
62 return CONNECTION_NONE; 64 return CONNECTION_NONE;
63 } 65 }
64 } 66 }
65 67
66 // static 68 // static
67 bool NetworkChangeNotifier::Register(JNIEnv* env) { 69 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) {
68 return RegisterNativesImpl(env); 70 return RegisterNativesImpl(env);
69 } 71 }
70 72
71 } // namespace android
72 } // namespace net 73 } // namespace net
OLDNEW
« no previous file with comments | « net/android/network_change_notifier_android.h ('k') | net/android/network_change_notifier_android_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698