Chromium Code Reviews| 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/base/network_change_notifier.h" | 5 #include "net/base/network_change_notifier.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 class MockNetworkChangeNotifier : public NetworkChangeNotifier { | 36 class MockNetworkChangeNotifier : public NetworkChangeNotifier { |
| 37 public: | 37 public: |
| 38 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE { | 38 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE { |
| 39 return CONNECTION_UNKNOWN; | 39 return CONNECTION_UNKNOWN; |
| 40 } | 40 } |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // The main observer class that records UMAs for network events. | 45 // The main observer class that records UMAs for network events. |
| 46 class HistogramWatcher | 46 class NetworkChangeNotifier::HistogramWatcher |
| 47 : public NetworkChangeNotifier::ConnectionTypeObserver, | 47 : public ConnectionTypeObserver, |
| 48 public NetworkChangeNotifier::IPAddressObserver, | 48 public IPAddressObserver, |
| 49 public NetworkChangeNotifier::DNSObserver, | 49 public DNSObserver, |
| 50 public NetworkChangeNotifier::NetworkChangeObserver { | 50 public NetworkChangeObserver { |
| 51 public: | 51 public: |
| 52 HistogramWatcher() | 52 HistogramWatcher() |
| 53 : last_ip_address_change_(base::TimeTicks::Now()), | 53 : last_ip_address_change_(base::TimeTicks::Now()), |
| 54 last_connection_change_(base::TimeTicks::Now()), | 54 last_connection_change_(base::TimeTicks::Now()), |
| 55 last_dns_change_(base::TimeTicks::Now()), | 55 last_dns_change_(base::TimeTicks::Now()), |
| 56 last_network_change_(base::TimeTicks::Now()), | 56 last_network_change_(base::TimeTicks::Now()), |
| 57 last_connection_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN), | 57 last_connection_type_(CONNECTION_UNKNOWN), |
| 58 offline_packets_received_(0) {} | 58 offline_packets_received_(0) {} |
| 59 | 59 |
| 60 // Registers our three Observer implementations. This is called from the | 60 // Registers our three Observer implementations. This is called from the |
| 61 // network thread so that our Observer implementations are also called | 61 // network thread so that our Observer implementations are also called |
| 62 // from the network thread. This avoids multi-threaded race conditions | 62 // from the network thread. This avoids multi-threaded race conditions |
| 63 // because the only other interface, |NotifyDataReceived| is also | 63 // because the only other interface, |NotifyDataReceived| is also |
| 64 // only called from the network thread. | 64 // only called from the network thread. |
| 65 void Init() { | 65 void Init() { |
| 66 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 66 Deprecated::AddConnectionTypeObserver(this); |
| 67 NetworkChangeNotifier::AddIPAddressObserver(this); | 67 Deprecated::AddIPAddressObserver(this); |
| 68 NetworkChangeNotifier::AddDNSObserver(this); | 68 AddDNSObserver(this); |
| 69 NetworkChangeNotifier::AddNetworkChangeObserver(this); | 69 AddNetworkChangeObserver(this); |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual ~HistogramWatcher() {} | 72 virtual ~HistogramWatcher() {} |
| 73 | 73 |
| 74 // NetworkChangeNotifier::IPAddressObserver implementation. | 74 // IPAddressObserver implementation. |
| 75 virtual void OnIPAddressChanged() OVERRIDE { | 75 virtual void OnIPAddressChanged() OVERRIDE { |
| 76 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.IPAddressChange", | 76 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.IPAddressChange", |
| 77 SinceLast(&last_ip_address_change_)); | 77 SinceLast(&last_ip_address_change_)); |
| 78 UMA_HISTOGRAM_MEDIUM_TIMES( | 78 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 79 "NCN.ConnectionTypeChangeToIPAddressChange", | 79 "NCN.ConnectionTypeChangeToIPAddressChange", |
| 80 last_ip_address_change_ - last_connection_change_); | 80 last_ip_address_change_ - last_connection_change_); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 83 // ConnectionTypeObserver implementation. |
| 84 virtual void OnConnectionTypeChanged( | 84 virtual void OnConnectionTypeChanged(ConnectionType type) OVERRIDE { |
| 85 NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 85 if (type != CONNECTION_NONE) { |
| 86 if (type != NetworkChangeNotifier::CONNECTION_NONE) { | |
| 87 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OnlineChange", | 86 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OnlineChange", |
| 88 SinceLast(&last_connection_change_)); | 87 SinceLast(&last_connection_change_)); |
| 89 | 88 |
| 90 if (offline_packets_received_) { | 89 if (offline_packets_received_) { |
| 91 if ((last_connection_change_ - last_offline_packet_received_) < | 90 if ((last_connection_change_ - last_offline_packet_received_) < |
| 92 base::TimeDelta::FromSeconds(5)) { | 91 base::TimeDelta::FromSeconds(5)) { |
| 93 // We can compare this sum with the sum of NCN.OfflineDataRecv. | 92 // We can compare this sum with the sum of NCN.OfflineDataRecv. |
| 94 UMA_HISTOGRAM_COUNTS_10000( | 93 UMA_HISTOGRAM_COUNTS_10000( |
| 95 "NCN.OfflineDataRecvAny5sBeforeOnline", | 94 "NCN.OfflineDataRecvAny5sBeforeOnline", |
| 96 offline_packets_received_); | 95 offline_packets_received_); |
| 97 } | 96 } |
| 98 | 97 |
| 99 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecvUntilOnline", | 98 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecvUntilOnline", |
| 100 last_connection_change_ - | 99 last_connection_change_ - |
| 101 last_offline_packet_received_); | 100 last_offline_packet_received_); |
| 102 } | 101 } |
| 103 } else { | 102 } else { |
| 104 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineChange", | 103 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineChange", |
| 105 SinceLast(&last_connection_change_)); | 104 SinceLast(&last_connection_change_)); |
| 106 } | 105 } |
| 107 UMA_HISTOGRAM_MEDIUM_TIMES( | 106 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 108 "NCN.IPAddressChangeToConnectionTypeChange", | 107 "NCN.IPAddressChangeToConnectionTypeChange", |
| 109 last_connection_change_ - last_ip_address_change_); | 108 last_connection_change_ - last_ip_address_change_); |
| 110 | 109 |
| 111 offline_packets_received_ = 0; | 110 offline_packets_received_ = 0; |
| 112 last_connection_type_ = type; | 111 last_connection_type_ = type; |
| 113 polling_interval_ = base::TimeDelta::FromSeconds(1); | 112 polling_interval_ = base::TimeDelta::FromSeconds(1); |
| 114 } | 113 } |
| 115 | 114 |
| 116 // NetworkChangeNotifier::DNSObserver implementation. | 115 // DNSObserver implementation. |
| 117 virtual void OnDNSChanged() OVERRIDE { | 116 virtual void OnDNSChanged() OVERRIDE { |
| 118 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.DNSConfigChange", | 117 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.DNSConfigChange", |
| 119 SinceLast(&last_dns_change_)); | 118 SinceLast(&last_dns_change_)); |
| 120 } | 119 } |
| 121 | 120 |
| 122 // NetworkChangeNotifier::NetworkChangeObserver implementation. | 121 // NetworkChangeObserver implementation. |
| 123 virtual void OnNetworkChanged( | 122 virtual void OnNetworkChanged(ConnectionType type) OVERRIDE { |
| 124 NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 123 if (type != CONNECTION_NONE) { |
| 125 if (type != NetworkChangeNotifier::CONNECTION_NONE) { | |
| 126 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange", | 124 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange", |
| 127 SinceLast(&last_network_change_)); | 125 SinceLast(&last_network_change_)); |
| 128 } else { | 126 } else { |
| 129 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOfflineChange", | 127 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOfflineChange", |
| 130 SinceLast(&last_network_change_)); | 128 SinceLast(&last_network_change_)); |
| 131 } | 129 } |
| 132 } | 130 } |
| 133 | 131 |
| 134 // Record histogram data whenever we receive a packet but think we're | 132 // Record histogram data whenever we receive a packet but think we're |
| 135 // offline. Should only be called from the network thread. | 133 // offline. Should only be called from the network thread. |
| 136 void NotifyDataReceived(const GURL& source) { | 134 void NotifyDataReceived(const GURL& source) { |
| 137 if (last_connection_type_ != NetworkChangeNotifier::CONNECTION_NONE || | 135 if (last_connection_type_ != CONNECTION_NONE || |
| 138 IsLocalhost(source.host()) || | 136 IsLocalhost(source.host()) || |
| 139 !(source.SchemeIs("http") || source.SchemeIs("https"))) { | 137 !(source.SchemeIs("http") || source.SchemeIs("https"))) { |
| 140 return; | 138 return; |
| 141 } | 139 } |
| 142 | 140 |
| 143 base::TimeTicks current_time = base::TimeTicks::Now(); | 141 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 144 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecv", | 142 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecv", |
| 145 current_time - last_connection_change_); | 143 current_time - last_connection_change_); |
| 146 offline_packets_received_++; | 144 offline_packets_received_++; |
| 147 last_offline_packet_received_ = current_time; | 145 last_offline_packet_received_ = current_time; |
| 148 | 146 |
| 149 if ((current_time - last_polled_connection_) > polling_interval_) { | 147 if ((current_time - last_polled_connection_) > polling_interval_) { |
| 150 polling_interval_ *= 2; | 148 polling_interval_ *= 2; |
| 151 last_polled_connection_ = current_time; | 149 last_polled_connection_ = current_time; |
| 152 base::TimeTicks started_get_connection_type = base::TimeTicks::Now(); | 150 base::TimeTicks started_get_connection_type = base::TimeTicks::Now(); |
| 153 last_polled_connection_type_ = | 151 last_polled_connection_type_ = GetConnectionType(); |
| 154 NetworkChangeNotifier::GetConnectionType(); | |
| 155 UMA_HISTOGRAM_TIMES("NCN.GetConnectionTypeTime", | 152 UMA_HISTOGRAM_TIMES("NCN.GetConnectionTypeTime", |
| 156 base::TimeTicks::Now() - | 153 base::TimeTicks::Now() - |
| 157 started_get_connection_type); | 154 started_get_connection_type); |
| 158 } | 155 } |
| 159 if (last_polled_connection_type_ == | 156 if (last_polled_connection_type_ == CONNECTION_NONE) { |
| 160 NetworkChangeNotifier::CONNECTION_NONE) { | |
| 161 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.PollingOfflineDataRecv", | 157 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.PollingOfflineDataRecv", |
| 162 current_time - last_connection_change_); | 158 current_time - last_connection_change_); |
| 163 } | 159 } |
| 164 } | 160 } |
| 165 | 161 |
| 166 private: | 162 private: |
| 167 static base::TimeDelta SinceLast(base::TimeTicks *last_time) { | 163 static base::TimeDelta SinceLast(base::TimeTicks *last_time) { |
| 168 base::TimeTicks current_time = base::TimeTicks::Now(); | 164 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 169 base::TimeDelta delta = current_time - *last_time; | 165 base::TimeDelta delta = current_time - *last_time; |
| 170 *last_time = current_time; | 166 *last_time = current_time; |
| 171 return delta; | 167 return delta; |
| 172 } | 168 } |
| 173 | 169 |
| 174 base::TimeTicks last_ip_address_change_; | 170 base::TimeTicks last_ip_address_change_; |
| 175 base::TimeTicks last_connection_change_; | 171 base::TimeTicks last_connection_change_; |
| 176 base::TimeTicks last_dns_change_; | 172 base::TimeTicks last_dns_change_; |
| 177 base::TimeTicks last_network_change_; | 173 base::TimeTicks last_network_change_; |
| 178 base::TimeTicks last_offline_packet_received_; | 174 base::TimeTicks last_offline_packet_received_; |
| 179 base::TimeTicks last_polled_connection_; | 175 base::TimeTicks last_polled_connection_; |
| 180 // |polling_interval_| is initialized by |OnConnectionTypeChanged| on our | 176 // |polling_interval_| is initialized by |OnConnectionTypeChanged| on our |
| 181 // first transition to offline and on subsequent transitions. Once offline, | 177 // first transition to offline and on subsequent transitions. Once offline, |
| 182 // |polling_interval_| doubles as offline data is received and we poll | 178 // |polling_interval_| doubles as offline data is received and we poll |
| 183 // with |NetworkChangeNotifier::GetConnectionType| to verify the connection | 179 // with |GetConnectionType| to verify the connection |
| 184 // state. | 180 // state. |
| 185 base::TimeDelta polling_interval_; | 181 base::TimeDelta polling_interval_; |
| 186 // |last_connection_type_| is the last value passed to | 182 // |last_connection_type_| is the last value passed to |
| 187 // |OnConnectionTypeChanged|. | 183 // |OnConnectionTypeChanged|. |
| 188 NetworkChangeNotifier::ConnectionType last_connection_type_; | 184 ConnectionType last_connection_type_; |
| 189 // |last_polled_connection_type_| is last result from calling | 185 // |last_polled_connection_type_| is last result from calling |
| 190 // |NetworkChangeNotifier::GetConnectionType| in |NotifyDataReceived|. | 186 // |GetConnectionType| in |NotifyDataReceived|. |
| 191 NetworkChangeNotifier::ConnectionType last_polled_connection_type_; | 187 ConnectionType last_polled_connection_type_; |
| 192 int32 offline_packets_received_; | 188 int32 offline_packets_received_; |
| 193 | 189 |
| 194 DISALLOW_COPY_AND_ASSIGN(HistogramWatcher); | 190 DISALLOW_COPY_AND_ASSIGN(HistogramWatcher); |
| 195 }; | 191 }; |
| 196 | 192 |
| 197 // NetworkState is thread safe. | 193 // NetworkState is thread safe. |
| 198 class NetworkChangeNotifier::NetworkState { | 194 class NetworkChangeNotifier::NetworkState { |
| 199 public: | 195 public: |
| 200 NetworkState() {} | 196 NetworkState() {} |
| 201 ~NetworkState() {} | 197 ~NetworkState() {} |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 221 | 217 |
| 222 // Calculates NetworkChange signal from IPAddress and ConnectionType signals. | 218 // Calculates NetworkChange signal from IPAddress and ConnectionType signals. |
| 223 class NetworkChangeNotifier::NetworkChangeCalculator | 219 class NetworkChangeNotifier::NetworkChangeCalculator |
| 224 : public ConnectionTypeObserver, | 220 : public ConnectionTypeObserver, |
| 225 public IPAddressObserver { | 221 public IPAddressObserver { |
| 226 public: | 222 public: |
| 227 NetworkChangeCalculator(const NetworkChangeCalculatorParams& params) | 223 NetworkChangeCalculator(const NetworkChangeCalculatorParams& params) |
| 228 : params_(params), | 224 : params_(params), |
| 229 have_announced_(false), | 225 have_announced_(false), |
| 230 last_announced_connection_type_(CONNECTION_NONE), | 226 last_announced_connection_type_(CONNECTION_NONE), |
| 231 pending_connection_type_(CONNECTION_NONE) {} | 227 pending_connection_type_initialized_(false) {} |
| 232 | 228 |
| 233 void Init() { | 229 void Init() { |
| 234 AddConnectionTypeObserver(this); | 230 Deprecated::AddConnectionTypeObserver(this); |
| 235 AddIPAddressObserver(this); | 231 Deprecated::AddIPAddressObserver(this); |
| 236 } | 232 } |
| 237 | 233 |
| 238 virtual ~NetworkChangeCalculator() { | 234 virtual ~NetworkChangeCalculator() { |
| 239 RemoveConnectionTypeObserver(this); | 235 RemoveConnectionTypeObserver(this); |
| 240 RemoveIPAddressObserver(this); | 236 RemoveIPAddressObserver(this); |
| 241 } | 237 } |
| 242 | 238 |
| 243 // NetworkChangeNotifier::IPAddressObserver implementation. | 239 // NetworkChangeNotifier::IPAddressObserver implementation. |
| 244 virtual void OnIPAddressChanged() OVERRIDE { | 240 virtual void OnIPAddressChanged() OVERRIDE { |
| 241 if (!pending_connection_type_initialized_) { | |
| 242 pending_connection_type_initialized_ = true; | |
| 243 pending_connection_type_ = GetConnectionType(); | |
| 244 } | |
| 245 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE | 245 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE |
| 246 ? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_; | 246 ? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_; |
| 247 // Cancels any previous timer. | 247 // Cancels any previous timer. |
| 248 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); | 248 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); |
| 249 } | 249 } |
| 250 | 250 |
| 251 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 251 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 252 virtual void OnConnectionTypeChanged(ConnectionType type) OVERRIDE { | 252 virtual void OnConnectionTypeChanged(ConnectionType type) OVERRIDE { |
| 253 pending_connection_type_initialized_ = true; | |
| 253 pending_connection_type_ = type; | 254 pending_connection_type_ = type; |
| 254 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE | 255 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE |
| 255 ? params_.connection_type_offline_delay_ | 256 ? params_.connection_type_offline_delay_ |
| 256 : params_.connection_type_online_delay_; | 257 : params_.connection_type_online_delay_; |
| 257 // Cancels any previous timer. | 258 // Cancels any previous timer. |
| 258 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); | 259 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); |
| 259 } | 260 } |
| 260 | 261 |
| 261 private: | 262 private: |
| 262 void Notify() { | 263 void Notify() { |
| 264 DCHECK(pending_connection_type_initialized_); | |
| 263 // Don't bother signaling about dead connections. | 265 // Don't bother signaling about dead connections. |
| 264 if (have_announced_ && | 266 if (have_announced_ && |
| 265 (last_announced_connection_type_ == CONNECTION_NONE) && | 267 (last_announced_connection_type_ == CONNECTION_NONE) && |
| 266 (pending_connection_type_ == CONNECTION_NONE)) { | 268 (pending_connection_type_ == CONNECTION_NONE)) { |
| 267 return; | 269 return; |
| 268 } | 270 } |
| 269 have_announced_ = true; | 271 have_announced_ = true; |
| 270 last_announced_connection_type_ = pending_connection_type_; | 272 last_announced_connection_type_ = pending_connection_type_; |
| 271 // Immediately before sending out an online signal, send out an offline | 273 // Immediately before sending out an online signal, send out an offline |
| 272 // signal to perform any destructive actions before constructive actions. | 274 // signal to perform any destructive actions before constructive actions. |
| 273 if (pending_connection_type_ != CONNECTION_NONE) | 275 if (pending_connection_type_ != CONNECTION_NONE) |
| 274 NetworkChangeNotifier::NotifyObserversOfNetworkChange(CONNECTION_NONE); | 276 NetworkChangeNotifier::NotifyObserversOfNetworkChange(CONNECTION_NONE); |
| 275 NetworkChangeNotifier::NotifyObserversOfNetworkChange( | 277 NetworkChangeNotifier::NotifyObserversOfNetworkChange( |
| 276 pending_connection_type_); | 278 pending_connection_type_); |
| 277 } | 279 } |
| 278 | 280 |
| 279 const NetworkChangeCalculatorParams params_; | 281 const NetworkChangeCalculatorParams params_; |
| 280 | 282 |
| 281 // Indicates if NotifyObserversOfNetworkChange has been called yet. | 283 // Indicates if NotifyObserversOfNetworkChange has been called yet. |
| 282 bool have_announced_; | 284 bool have_announced_; |
| 283 // Last value passed to NotifyObserversOfNetworkChange. | 285 // Last value passed to NotifyObserversOfNetworkChange. |
| 284 ConnectionType last_announced_connection_type_; | 286 ConnectionType last_announced_connection_type_; |
| 285 // Value to pass to NotifyObserversOfNetworkChange when Notify is called. | 287 // Value to pass to NotifyObserversOfNetworkChange when Notify is called. |
| 286 ConnectionType pending_connection_type_; | 288 ConnectionType pending_connection_type_; |
| 289 // Indicates if pending_connection_type_ has been initialized. | |
| 290 bool pending_connection_type_initialized_; | |
| 287 // Used to delay notifications so duplicates can be combined. | 291 // Used to delay notifications so duplicates can be combined. |
| 288 base::OneShotTimer<NetworkChangeCalculator> timer_; | 292 base::OneShotTimer<NetworkChangeCalculator> timer_; |
| 289 }; | 293 }; |
| 290 | 294 |
| 291 NetworkChangeNotifier::~NetworkChangeNotifier() { | 295 NetworkChangeNotifier::~NetworkChangeNotifier() { |
| 292 DCHECK_EQ(this, g_network_change_notifier); | 296 DCHECK_EQ(this, g_network_change_notifier); |
| 293 g_network_change_notifier = NULL; | 297 g_network_change_notifier = NULL; |
| 294 } | 298 } |
| 295 | 299 |
| 296 // static | 300 // static |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 break; | 418 break; |
| 415 } | 419 } |
| 416 return is_cellular; | 420 return is_cellular; |
| 417 } | 421 } |
| 418 | 422 |
| 419 // static | 423 // static |
| 420 NetworkChangeNotifier* NetworkChangeNotifier::CreateMock() { | 424 NetworkChangeNotifier* NetworkChangeNotifier::CreateMock() { |
| 421 return new MockNetworkChangeNotifier(); | 425 return new MockNetworkChangeNotifier(); |
| 422 } | 426 } |
| 423 | 427 |
| 424 void NetworkChangeNotifier::AddIPAddressObserver(IPAddressObserver* observer) { | 428 void NetworkChangeNotifier::Deprecated::AddIPAddressObserver( |
| 429 IPAddressObserver* observer) { | |
| 425 if (g_network_change_notifier) | 430 if (g_network_change_notifier) |
| 426 g_network_change_notifier->ip_address_observer_list_->AddObserver(observer); | 431 g_network_change_notifier->ip_address_observer_list_->AddObserver(observer); |
| 427 } | 432 } |
| 428 | 433 |
| 429 void NetworkChangeNotifier::AddConnectionTypeObserver( | 434 void NetworkChangeNotifier::Deprecated::AddConnectionTypeObserver( |
| 430 ConnectionTypeObserver* observer) { | 435 ConnectionTypeObserver* observer) { |
| 431 if (g_network_change_notifier) { | 436 if (g_network_change_notifier) { |
| 437 // AddObserver does nothing without a valid MessageLoop | |
| 438 DCHECK(MessageLoop::current()); | |
| 432 g_network_change_notifier->connection_type_observer_list_->AddObserver( | 439 g_network_change_notifier->connection_type_observer_list_->AddObserver( |
| 433 observer); | 440 observer); |
| 434 } | 441 } |
| 435 } | 442 } |
| 436 | 443 |
| 437 void NetworkChangeNotifier::AddDNSObserver(DNSObserver* observer) { | 444 void NetworkChangeNotifier::AddDNSObserver(DNSObserver* observer) { |
| 438 if (g_network_change_notifier) { | 445 if (g_network_change_notifier) { |
| 446 // AddObserver does nothing without a valid MessageLoop | |
| 447 DCHECK(MessageLoop::current()); | |
| 439 g_network_change_notifier->resolver_state_observer_list_->AddObserver( | 448 g_network_change_notifier->resolver_state_observer_list_->AddObserver( |
| 440 observer); | 449 observer); |
| 441 } | 450 } |
| 442 } | 451 } |
| 443 | 452 |
| 444 void NetworkChangeNotifier::AddNetworkChangeObserver( | 453 void NetworkChangeNotifier::AddNetworkChangeObserver( |
| 445 NetworkChangeObserver* observer) { | 454 NetworkChangeObserver* observer) { |
| 446 if (g_network_change_notifier) { | 455 if (g_network_change_notifier) { |
| 456 // AddObserver does nothing without a valid MessageLoop | |
| 457 DCHECK(MessageLoop::current()); | |
| 447 g_network_change_notifier->network_change_observer_list_->AddObserver( | 458 g_network_change_notifier->network_change_observer_list_->AddObserver( |
| 448 observer); | 459 observer); |
| 449 } | 460 } |
| 450 } | 461 } |
| 451 | 462 |
| 452 void NetworkChangeNotifier::RemoveIPAddressObserver( | 463 void NetworkChangeNotifier::RemoveIPAddressObserver( |
| 453 IPAddressObserver* observer) { | 464 IPAddressObserver* observer) { |
| 454 if (g_network_change_notifier) { | 465 if (g_network_change_notifier) { |
| 455 g_network_change_notifier->ip_address_observer_list_->RemoveObserver( | 466 g_network_change_notifier->ip_address_observer_list_->RemoveObserver( |
| 456 observer); | 467 observer); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 : network_change_notifier_(g_network_change_notifier) { | 566 : network_change_notifier_(g_network_change_notifier) { |
| 556 DCHECK(g_network_change_notifier); | 567 DCHECK(g_network_change_notifier); |
| 557 g_network_change_notifier = NULL; | 568 g_network_change_notifier = NULL; |
| 558 } | 569 } |
| 559 | 570 |
| 560 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 571 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
| 561 DCHECK(!g_network_change_notifier); | 572 DCHECK(!g_network_change_notifier); |
| 562 g_network_change_notifier = network_change_notifier_; | 573 g_network_change_notifier = network_change_notifier_; |
| 563 } | 574 } |
| 564 | 575 |
| 576 void NetworkChangeNotifier::ResetNetworkChangeCalculatorParamsForTest( | |
| 577 NetworkChangeCalculatorParams params) { | |
| 578 network_change_calculator_.reset(new NetworkChangeCalculator(params)); | |
|
szym
2013/01/20 06:52:08
How thread-safe is this? It seems that this has to
| |
| 579 network_change_calculator_->Init(); | |
| 580 } | |
| 581 | |
| 565 } // namespace net | 582 } // namespace net |
| OLD | NEW |