| 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_delegate_android.h" | 5 #include "net/android/network_change_notifier_delegate_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "jni/NetworkChangeNotifier_jni.h" | 10 #include "jni/NetworkChangeNotifier_jni.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 ConvertConnectionSubtype(subtype)); | 71 ConvertConnectionSubtype(subtype)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 NetworkChangeNotifierDelegateAndroid::NetworkChangeNotifierDelegateAndroid() | 74 NetworkChangeNotifierDelegateAndroid::NetworkChangeNotifierDelegateAndroid() |
| 75 : observers_(new base::ObserverListThreadSafe<Observer>()) { | 75 : observers_(new base::ObserverListThreadSafe<Observer>()) { |
| 76 JNIEnv* env = base::android::AttachCurrentThread(); | 76 JNIEnv* env = base::android::AttachCurrentThread(); |
| 77 java_network_change_notifier_.Reset( | 77 java_network_change_notifier_.Reset( |
| 78 Java_NetworkChangeNotifier_init( | 78 Java_NetworkChangeNotifier_init( |
| 79 env, base::android::GetApplicationContext())); | 79 env, base::android::GetApplicationContext())); |
| 80 Java_NetworkChangeNotifier_addNativeObserver( | 80 Java_NetworkChangeNotifier_addNativeObserver( |
| 81 env, java_network_change_notifier_.obj(), | 81 env, java_network_change_notifier_, reinterpret_cast<intptr_t>(this)); |
| 82 reinterpret_cast<intptr_t>(this)); | |
| 83 SetCurrentConnectionType( | 82 SetCurrentConnectionType( |
| 84 ConvertConnectionType( | 83 ConvertConnectionType(Java_NetworkChangeNotifier_getCurrentConnectionType( |
| 85 Java_NetworkChangeNotifier_getCurrentConnectionType( | 84 env, java_network_change_notifier_))); |
| 86 env, java_network_change_notifier_.obj()))); | |
| 87 SetCurrentMaxBandwidth( | 85 SetCurrentMaxBandwidth( |
| 88 Java_NetworkChangeNotifier_getCurrentMaxBandwidthInMbps( | 86 Java_NetworkChangeNotifier_getCurrentMaxBandwidthInMbps( |
| 89 env, java_network_change_notifier_.obj())); | 87 env, java_network_change_notifier_)); |
| 90 SetCurrentDefaultNetwork(Java_NetworkChangeNotifier_getCurrentDefaultNetId( | 88 SetCurrentDefaultNetwork(Java_NetworkChangeNotifier_getCurrentDefaultNetId( |
| 91 env, java_network_change_notifier_.obj())); | 89 env, java_network_change_notifier_)); |
| 92 NetworkMap network_map; | 90 NetworkMap network_map; |
| 93 ScopedJavaLocalRef<jlongArray> networks_and_types = | 91 ScopedJavaLocalRef<jlongArray> networks_and_types = |
| 94 Java_NetworkChangeNotifier_getCurrentNetworksAndTypes( | 92 Java_NetworkChangeNotifier_getCurrentNetworksAndTypes( |
| 95 env, java_network_change_notifier_.obj()); | 93 env, java_network_change_notifier_); |
| 96 JavaLongArrayToNetworkMap(env, networks_and_types.obj(), &network_map); | 94 JavaLongArrayToNetworkMap(env, networks_and_types.obj(), &network_map); |
| 97 SetCurrentNetworksAndTypes(network_map); | 95 SetCurrentNetworksAndTypes(network_map); |
| 98 } | 96 } |
| 99 | 97 |
| 100 NetworkChangeNotifierDelegateAndroid::~NetworkChangeNotifierDelegateAndroid() { | 98 NetworkChangeNotifierDelegateAndroid::~NetworkChangeNotifierDelegateAndroid() { |
| 101 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 observers_->AssertEmpty(); | 100 observers_->AssertEmpty(); |
| 103 JNIEnv* env = base::android::AttachCurrentThread(); | 101 JNIEnv* env = base::android::AttachCurrentThread(); |
| 104 Java_NetworkChangeNotifier_removeNativeObserver( | 102 Java_NetworkChangeNotifier_removeNativeObserver( |
| 105 env, java_network_change_notifier_.obj(), | 103 env, java_network_change_notifier_, reinterpret_cast<intptr_t>(this)); |
| 106 reinterpret_cast<intptr_t>(this)); | |
| 107 } | 104 } |
| 108 | 105 |
| 109 NetworkChangeNotifier::ConnectionType | 106 NetworkChangeNotifier::ConnectionType |
| 110 NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType() const { | 107 NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType() const { |
| 111 base::AutoLock auto_lock(connection_lock_); | 108 base::AutoLock auto_lock(connection_lock_); |
| 112 return connection_type_; | 109 return connection_type_; |
| 113 } | 110 } |
| 114 | 111 |
| 115 NetworkChangeNotifier::ConnectionSubtype | 112 NetworkChangeNotifier::ConnectionSubtype |
| 116 NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionSubtype() const { | 113 NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionSubtype() const { |
| 117 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
| 118 return ConvertConnectionSubtype( | 115 return ConvertConnectionSubtype( |
| 119 Java_NetworkChangeNotifier_getCurrentConnectionSubtype( | 116 Java_NetworkChangeNotifier_getCurrentConnectionSubtype( |
| 120 base::android::AttachCurrentThread(), | 117 base::android::AttachCurrentThread(), java_network_change_notifier_)); |
| 121 java_network_change_notifier_.obj())); | |
| 122 } | 118 } |
| 123 | 119 |
| 124 void NetworkChangeNotifierDelegateAndroid:: | 120 void NetworkChangeNotifierDelegateAndroid:: |
| 125 GetCurrentMaxBandwidthAndConnectionType( | 121 GetCurrentMaxBandwidthAndConnectionType( |
| 126 double* max_bandwidth_mbps, | 122 double* max_bandwidth_mbps, |
| 127 ConnectionType* connection_type) const { | 123 ConnectionType* connection_type) const { |
| 128 base::AutoLock auto_lock(connection_lock_); | 124 base::AutoLock auto_lock(connection_lock_); |
| 129 *connection_type = connection_type_; | 125 *connection_type = connection_type_; |
| 130 *max_bandwidth_mbps = connection_max_bandwidth_; | 126 *max_bandwidth_mbps = connection_max_bandwidth_; |
| 131 } | 127 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 void NetworkChangeNotifierDelegateAndroid::FakeNetworkDisconnected( | 347 void NetworkChangeNotifierDelegateAndroid::FakeNetworkDisconnected( |
| 352 NetworkChangeNotifier::NetworkHandle network) { | 348 NetworkChangeNotifier::NetworkHandle network) { |
| 353 JNIEnv* env = base::android::AttachCurrentThread(); | 349 JNIEnv* env = base::android::AttachCurrentThread(); |
| 354 Java_NetworkChangeNotifier_fakeNetworkDisconnected(env, network); | 350 Java_NetworkChangeNotifier_fakeNetworkDisconnected(env, network); |
| 355 } | 351 } |
| 356 | 352 |
| 357 void NetworkChangeNotifierDelegateAndroid::FakePurgeActiveNetworkList( | 353 void NetworkChangeNotifierDelegateAndroid::FakePurgeActiveNetworkList( |
| 358 NetworkChangeNotifier::NetworkList networks) { | 354 NetworkChangeNotifier::NetworkList networks) { |
| 359 JNIEnv* env = base::android::AttachCurrentThread(); | 355 JNIEnv* env = base::android::AttachCurrentThread(); |
| 360 Java_NetworkChangeNotifier_fakePurgeActiveNetworkList( | 356 Java_NetworkChangeNotifier_fakePurgeActiveNetworkList( |
| 361 env, base::android::ToJavaLongArray(env, networks).obj()); | 357 env, base::android::ToJavaLongArray(env, networks)); |
| 362 } | 358 } |
| 363 | 359 |
| 364 void NetworkChangeNotifierDelegateAndroid::FakeDefaultNetwork( | 360 void NetworkChangeNotifierDelegateAndroid::FakeDefaultNetwork( |
| 365 NetworkChangeNotifier::NetworkHandle network, | 361 NetworkChangeNotifier::NetworkHandle network, |
| 366 ConnectionType type) { | 362 ConnectionType type) { |
| 367 JNIEnv* env = base::android::AttachCurrentThread(); | 363 JNIEnv* env = base::android::AttachCurrentThread(); |
| 368 Java_NetworkChangeNotifier_fakeDefaultNetwork(env, network, type); | 364 Java_NetworkChangeNotifier_fakeDefaultNetwork(env, network, type); |
| 369 } | 365 } |
| 370 | 366 |
| 371 void NetworkChangeNotifierDelegateAndroid::FakeMaxBandwidthChanged( | 367 void NetworkChangeNotifierDelegateAndroid::FakeMaxBandwidthChanged( |
| 372 double max_bandwidth_mbps) { | 368 double max_bandwidth_mbps) { |
| 373 JNIEnv* env = base::android::AttachCurrentThread(); | 369 JNIEnv* env = base::android::AttachCurrentThread(); |
| 374 Java_NetworkChangeNotifier_fakeMaxBandwidthChanged(env, max_bandwidth_mbps); | 370 Java_NetworkChangeNotifier_fakeMaxBandwidthChanged(env, max_bandwidth_mbps); |
| 375 } | 371 } |
| 376 | 372 |
| 377 } // namespace net | 373 } // namespace net |
| OLD | NEW |