| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "jni/NetworkChangeNotifier_jni.h" | 8 #include "jni/NetworkChangeNotifier_jni.h" |
| 9 #include "net/android/network_change_notifier_android.h" | 9 #include "net/android/network_change_notifier_android.h" |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 env, java_network_change_notifier_.obj(), | 77 env, java_network_change_notifier_.obj(), |
| 78 reinterpret_cast<intptr_t>(this)); | 78 reinterpret_cast<intptr_t>(this)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 NetworkChangeNotifier::ConnectionType | 81 NetworkChangeNotifier::ConnectionType |
| 82 NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType() const { | 82 NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType() const { |
| 83 base::AutoLock auto_lock(connection_lock_); | 83 base::AutoLock auto_lock(connection_lock_); |
| 84 return connection_type_; | 84 return connection_type_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 double NetworkChangeNotifierDelegateAndroid::GetCurrentMaxBandwidth() const { | 87 double |
| 88 NetworkChangeNotifierDelegateAndroid::GetCurrentMaxBandwidthAndConnectionType( |
| 89 ConnectionType* connection_type) const { |
| 88 base::AutoLock auto_lock(connection_lock_); | 90 base::AutoLock auto_lock(connection_lock_); |
| 91 if (connection_type != nullptr) |
| 92 *connection_type = connection_type_; |
| 89 return connection_max_bandwidth_; | 93 return connection_max_bandwidth_; |
| 90 } | 94 } |
| 91 | 95 |
| 92 void NetworkChangeNotifierDelegateAndroid::NotifyConnectionTypeChanged( | 96 void NetworkChangeNotifierDelegateAndroid::NotifyConnectionTypeChanged( |
| 93 JNIEnv* env, | 97 JNIEnv* env, |
| 94 jobject obj, | 98 jobject obj, |
| 95 jint new_connection_type) { | 99 jint new_connection_type) { |
| 96 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 const ConnectionType actual_connection_type = ConvertConnectionType( | 101 const ConnectionType actual_connection_type = ConvertConnectionType( |
| 98 new_connection_type); | 102 new_connection_type); |
| 99 SetCurrentConnectionType(actual_connection_type); | 103 SetCurrentConnectionType(actual_connection_type); |
| 100 observers_->Notify(FROM_HERE, &Observer::OnConnectionTypeChanged); | 104 observers_->Notify(FROM_HERE, &Observer::OnConnectionTypeChanged); |
| 101 } | 105 } |
| 102 | 106 |
| 103 jint NetworkChangeNotifierDelegateAndroid::GetConnectionType(JNIEnv*, | 107 jint NetworkChangeNotifierDelegateAndroid::GetConnectionType(JNIEnv*, |
| 104 jobject) const { | 108 jobject) const { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 return GetCurrentConnectionType(); | 110 return GetCurrentConnectionType(); |
| 107 } | 111 } |
| 108 | 112 |
| 109 void NetworkChangeNotifierDelegateAndroid::NotifyMaxBandwidthChanged( | 113 void NetworkChangeNotifierDelegateAndroid::NotifyMaxBandwidthChanged( |
| 110 JNIEnv* env, | 114 JNIEnv* env, |
| 111 jobject obj, | 115 jobject obj, |
| 112 jdouble new_max_bandwidth) { | 116 jdouble new_max_bandwidth) { |
| 113 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 DCHECK(new_max_bandwidth != GetCurrentMaxBandwidth()); | 118 DCHECK(new_max_bandwidth != GetCurrentMaxBandwidthAndConnectionType(nullptr)); |
| 119 |
| 115 SetCurrentMaxBandwidth(new_max_bandwidth); | 120 SetCurrentMaxBandwidth(new_max_bandwidth); |
| 116 observers_->Notify(FROM_HERE, &Observer::OnMaxBandwidthChanged, | 121 observers_->Notify(FROM_HERE, &Observer::OnMaxBandwidthChanged, |
| 117 new_max_bandwidth); | 122 GetCurrentConnectionType(), new_max_bandwidth); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void NetworkChangeNotifierDelegateAndroid::AddObserver( | 125 void NetworkChangeNotifierDelegateAndroid::AddObserver( |
| 121 Observer* observer) { | 126 Observer* observer) { |
| 122 observers_->AddObserver(observer); | 127 observers_->AddObserver(observer); |
| 123 } | 128 } |
| 124 | 129 |
| 125 void NetworkChangeNotifierDelegateAndroid::RemoveObserver( | 130 void NetworkChangeNotifierDelegateAndroid::RemoveObserver( |
| 126 Observer* observer) { | 131 Observer* observer) { |
| 127 observers_->RemoveObserver(observer); | 132 observers_->RemoveObserver(observer); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 148 JNIEnv* env = base::android::AttachCurrentThread(); | 153 JNIEnv* env = base::android::AttachCurrentThread(); |
| 149 Java_NetworkChangeNotifier_forceConnectivityState(env, true); | 154 Java_NetworkChangeNotifier_forceConnectivityState(env, true); |
| 150 } | 155 } |
| 151 | 156 |
| 152 void NetworkChangeNotifierDelegateAndroid::SetOffline() { | 157 void NetworkChangeNotifierDelegateAndroid::SetOffline() { |
| 153 JNIEnv* env = base::android::AttachCurrentThread(); | 158 JNIEnv* env = base::android::AttachCurrentThread(); |
| 154 Java_NetworkChangeNotifier_forceConnectivityState(env, false); | 159 Java_NetworkChangeNotifier_forceConnectivityState(env, false); |
| 155 } | 160 } |
| 156 | 161 |
| 157 } // namespace net | 162 } // namespace net |
| OLD | NEW |