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