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 //////////////////////////////////////////////////////////////////////////////// | 5 //////////////////////////////////////////////////////////////////////////////// |
6 // Threading considerations: | 6 // Threading considerations: |
7 // | 7 // |
8 // This class is designed to meet various threading guarantees starting from the | 8 // This class is designed to meet various threading guarantees starting from the |
9 // ones imposed by NetworkChangeNotifier: | 9 // ones imposed by NetworkChangeNotifier: |
10 // - The notifier can be constructed on any thread. | 10 // - The notifier can be constructed on any thread. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // delegate then forwards these notifications to the threads of each observer | 52 // delegate then forwards these notifications to the threads of each observer |
53 // (network change notifier). The network change notifier than processes the | 53 // (network change notifier). The network change notifier than processes the |
54 // state change, and notifies each of its observers on their threads. | 54 // state change, and notifies each of its observers on their threads. |
55 // | 55 // |
56 // This can also be seen as: | 56 // This can also be seen as: |
57 // Android platform -> NetworkChangeNotifier (Java) -> | 57 // Android platform -> NetworkChangeNotifier (Java) -> |
58 // NetworkChangeNotifierDelegateAndroid -> NetworkChangeNotifierAndroid. | 58 // NetworkChangeNotifierDelegateAndroid -> NetworkChangeNotifierAndroid. |
59 | 59 |
60 #include "net/android/network_change_notifier_android.h" | 60 #include "net/android/network_change_notifier_android.h" |
61 | 61 |
| 62 #include "base/android/build_info.h" |
62 #include "base/threading/thread.h" | 63 #include "base/threading/thread.h" |
63 #include "net/base/address_tracker_linux.h" | 64 #include "net/base/address_tracker_linux.h" |
64 #include "net/dns/dns_config_service_posix.h" | 65 #include "net/dns/dns_config_service_posix.h" |
65 | 66 |
66 namespace net { | 67 namespace net { |
67 | 68 |
68 // Expose kInvalidNetworkHandle out to Java as NetId.INVALID. The notion of | 69 // Expose kInvalidNetworkHandle out to Java as NetId.INVALID. The notion of |
69 // a NetID is an Android framework one, see android.net.Network.netId. | 70 // a NetID is an Android framework one, see android.net.Network.netId. |
70 // NetworkChangeNotifierAndroid implements NetworkHandle to simply be the NetID. | 71 // NetworkChangeNotifierAndroid implements NetworkHandle to simply be the NetID. |
71 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | 72 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 return delegate_->GetCurrentConnectionType(); | 156 return delegate_->GetCurrentConnectionType(); |
156 } | 157 } |
157 | 158 |
158 void NetworkChangeNotifierAndroid::GetCurrentMaxBandwidthAndConnectionType( | 159 void NetworkChangeNotifierAndroid::GetCurrentMaxBandwidthAndConnectionType( |
159 double* max_bandwidth_mbps, | 160 double* max_bandwidth_mbps, |
160 ConnectionType* connection_type) const { | 161 ConnectionType* connection_type) const { |
161 delegate_->GetCurrentMaxBandwidthAndConnectionType(max_bandwidth_mbps, | 162 delegate_->GetCurrentMaxBandwidthAndConnectionType(max_bandwidth_mbps, |
162 connection_type); | 163 connection_type); |
163 } | 164 } |
164 | 165 |
| 166 void NetworkChangeNotifierAndroid::ForceNetworkHandlesSupportedForTesting() { |
| 167 force_network_handles_supported_for_testing_ = true; |
| 168 } |
| 169 |
| 170 bool NetworkChangeNotifierAndroid::AreNetworkHandlesCurrentlySupported() const { |
| 171 // Notifications for API using NetworkHandles and querying using |
| 172 // NetworkHandles only implemented for Android versions >= L. |
| 173 return force_network_handles_supported_for_testing_ || |
| 174 (base::android::BuildInfo::GetInstance()->sdk_int() >= |
| 175 base::android::SDK_VERSION_LOLLIPOP); |
| 176 } |
| 177 |
165 void NetworkChangeNotifierAndroid::GetCurrentConnectedNetworks( | 178 void NetworkChangeNotifierAndroid::GetCurrentConnectedNetworks( |
166 NetworkChangeNotifier::NetworkList* networks) const { | 179 NetworkChangeNotifier::NetworkList* networks) const { |
167 delegate_->GetCurrentlyConnectedNetworks(networks); | 180 delegate_->GetCurrentlyConnectedNetworks(networks); |
168 } | 181 } |
169 | 182 |
170 NetworkChangeNotifier::ConnectionType | 183 NetworkChangeNotifier::ConnectionType |
171 NetworkChangeNotifierAndroid::GetCurrentNetworkConnectionType( | 184 NetworkChangeNotifierAndroid::GetCurrentNetworkConnectionType( |
172 NetworkHandle network) const { | 185 NetworkHandle network) const { |
173 return delegate_->GetNetworkConnectionType(network); | 186 return delegate_->GetNetworkConnectionType(network); |
174 } | 187 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { | 228 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { |
216 return NetworkChangeNotifierDelegateAndroid::Register(env); | 229 return NetworkChangeNotifierDelegateAndroid::Register(env); |
217 } | 230 } |
218 | 231 |
219 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid( | 232 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid( |
220 NetworkChangeNotifierDelegateAndroid* delegate, | 233 NetworkChangeNotifierDelegateAndroid* delegate, |
221 const DnsConfig* dns_config_for_testing) | 234 const DnsConfig* dns_config_for_testing) |
222 : NetworkChangeNotifier(NetworkChangeCalculatorParamsAndroid()), | 235 : NetworkChangeNotifier(NetworkChangeCalculatorParamsAndroid()), |
223 delegate_(delegate), | 236 delegate_(delegate), |
224 dns_config_service_thread_( | 237 dns_config_service_thread_( |
225 new DnsConfigServiceThread(dns_config_for_testing)) { | 238 new DnsConfigServiceThread(dns_config_for_testing)), |
| 239 force_network_handles_supported_for_testing_(false) { |
226 CHECK_EQ(NetId::INVALID, NetworkChangeNotifier::kInvalidNetworkHandle) | 240 CHECK_EQ(NetId::INVALID, NetworkChangeNotifier::kInvalidNetworkHandle) |
227 << "kInvalidNetworkHandle doesn't match NetId::INVALID"; | 241 << "kInvalidNetworkHandle doesn't match NetId::INVALID"; |
228 delegate_->AddObserver(this); | 242 delegate_->AddObserver(this); |
229 dns_config_service_thread_->StartWithOptions( | 243 dns_config_service_thread_->StartWithOptions( |
230 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 244 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
231 // Wait until Init is called on the DNS config thread before | 245 // Wait until Init is called on the DNS config thread before |
232 // calling InitAfterStart. | 246 // calling InitAfterStart. |
233 dns_config_service_thread_->WaitUntilThreadStarted(); | 247 dns_config_service_thread_->WaitUntilThreadStarted(); |
234 dns_config_service_thread_->InitAfterStart(); | 248 dns_config_service_thread_->InitAfterStart(); |
235 } | 249 } |
236 | 250 |
237 // static | 251 // static |
238 NetworkChangeNotifier::NetworkChangeCalculatorParams | 252 NetworkChangeNotifier::NetworkChangeCalculatorParams |
239 NetworkChangeNotifierAndroid::NetworkChangeCalculatorParamsAndroid() { | 253 NetworkChangeNotifierAndroid::NetworkChangeCalculatorParamsAndroid() { |
240 NetworkChangeCalculatorParams params; | 254 NetworkChangeCalculatorParams params; |
241 // IPAddressChanged is produced immediately prior to ConnectionTypeChanged | 255 // IPAddressChanged is produced immediately prior to ConnectionTypeChanged |
242 // so delay IPAddressChanged so they get merged with the following | 256 // so delay IPAddressChanged so they get merged with the following |
243 // ConnectionTypeChanged signal. | 257 // ConnectionTypeChanged signal. |
244 params.ip_address_offline_delay_ = base::TimeDelta::FromSeconds(1); | 258 params.ip_address_offline_delay_ = base::TimeDelta::FromSeconds(1); |
245 params.ip_address_online_delay_ = base::TimeDelta::FromSeconds(1); | 259 params.ip_address_online_delay_ = base::TimeDelta::FromSeconds(1); |
246 params.connection_type_offline_delay_ = base::TimeDelta::FromSeconds(0); | 260 params.connection_type_offline_delay_ = base::TimeDelta::FromSeconds(0); |
247 params.connection_type_online_delay_ = base::TimeDelta::FromSeconds(0); | 261 params.connection_type_online_delay_ = base::TimeDelta::FromSeconds(0); |
248 return params; | 262 return params; |
249 } | 263 } |
250 | 264 |
251 } // namespace net | 265 } // namespace net |
OLD | NEW |