| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 #include "net/android/network_change_notifier_android.h" | 60 #include "net/android/network_change_notifier_android.h" |
| 61 | 61 |
| 62 namespace net { | 62 namespace net { |
| 63 | 63 |
| 64 NetworkChangeNotifierAndroid::~NetworkChangeNotifierAndroid() { | 64 NetworkChangeNotifierAndroid::~NetworkChangeNotifierAndroid() { |
| 65 delegate_->RemoveObserver(this); | 65 delegate_->RemoveObserver(this); |
| 66 } | 66 } |
| 67 | 67 |
| 68 NetworkChangeNotifier::ConnectionType | 68 NetworkChangeNotifier::ConnectionType |
| 69 NetworkChangeNotifierAndroid::GetCurrentConnectionType() const { | 69 NetworkChangeNotifierAndroid::GetCurrentConnectionType() const { |
| 70 base::AutoLock auto_lock(connection_type_lock_); | 70 return delegate_->GetCurrentConnectionType(); |
| 71 return connection_type_; | |
| 72 } | 71 } |
| 73 | 72 |
| 74 void NetworkChangeNotifierAndroid::OnConnectionTypeChanged( | 73 void NetworkChangeNotifierAndroid::OnConnectionTypeChanged() { |
| 75 ConnectionType new_connection_type) { | |
| 76 SetConnectionType(new_connection_type); | |
| 77 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); | 74 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 78 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); | 75 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); |
| 79 } | 76 } |
| 80 | 77 |
| 81 // static | 78 // static |
| 82 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { | 79 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { |
| 83 return NetworkChangeNotifierDelegateAndroid::Register(env); | 80 return NetworkChangeNotifierDelegateAndroid::Register(env); |
| 84 } | 81 } |
| 85 | 82 |
| 86 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid( | 83 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid( |
| 87 NetworkChangeNotifierDelegateAndroid* delegate) | 84 NetworkChangeNotifierDelegateAndroid* delegate) |
| 88 : NetworkChangeNotifier(NetworkChangeCalculatorParamsAndroid()), | 85 : NetworkChangeNotifier(NetworkChangeCalculatorParamsAndroid()), |
| 89 delegate_(delegate) { | 86 delegate_(delegate) { |
| 90 SetConnectionType(NetworkChangeNotifier::CONNECTION_UNKNOWN); | |
| 91 delegate_->AddObserver(this); | 87 delegate_->AddObserver(this); |
| 92 } | 88 } |
| 93 | 89 |
| 94 // static | 90 // static |
| 95 NetworkChangeNotifier::NetworkChangeCalculatorParams | 91 NetworkChangeNotifier::NetworkChangeCalculatorParams |
| 96 NetworkChangeNotifierAndroid::NetworkChangeCalculatorParamsAndroid() { | 92 NetworkChangeNotifierAndroid::NetworkChangeCalculatorParamsAndroid() { |
| 97 NetworkChangeCalculatorParams params; | 93 NetworkChangeCalculatorParams params; |
| 98 // IPAddressChanged is produced immediately prior to ConnectionTypeChanged | 94 // IPAddressChanged is produced immediately prior to ConnectionTypeChanged |
| 99 // so delay IPAddressChanged so they get merged with the following | 95 // so delay IPAddressChanged so they get merged with the following |
| 100 // ConnectionTypeChanged signal. | 96 // ConnectionTypeChanged signal. |
| 101 params.ip_address_offline_delay_ = base::TimeDelta::FromSeconds(1); | 97 params.ip_address_offline_delay_ = base::TimeDelta::FromSeconds(1); |
| 102 params.ip_address_online_delay_ = base::TimeDelta::FromSeconds(1); | 98 params.ip_address_online_delay_ = base::TimeDelta::FromSeconds(1); |
| 103 params.connection_type_offline_delay_ = base::TimeDelta::FromSeconds(0); | 99 params.connection_type_offline_delay_ = base::TimeDelta::FromSeconds(0); |
| 104 params.connection_type_online_delay_ = base::TimeDelta::FromSeconds(0); | 100 params.connection_type_online_delay_ = base::TimeDelta::FromSeconds(0); |
| 105 return params; | 101 return params; |
| 106 } | 102 } |
| 107 | 103 |
| 108 void NetworkChangeNotifierAndroid::SetConnectionType( | |
| 109 ConnectionType new_connection_type) { | |
| 110 base::AutoLock auto_lock(connection_type_lock_); | |
| 111 connection_type_ = new_connection_type; | |
| 112 } | |
| 113 | |
| 114 } // namespace net | 104 } // namespace net |
| OLD | NEW |