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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 #if defined(OS_LINUX) | 268 #if defined(OS_LINUX) |
| 269 // static | 269 // static |
| 270 const internal::AddressTrackerLinux* | 270 const internal::AddressTrackerLinux* |
| 271 NetworkChangeNotifier::GetAddressTracker() { | 271 NetworkChangeNotifier::GetAddressTracker() { |
| 272 return g_network_change_notifier ? | 272 return g_network_change_notifier ? |
| 273 g_network_change_notifier->GetAddressTrackerInternal() : NULL; | 273 g_network_change_notifier->GetAddressTrackerInternal() : NULL; |
| 274 } | 274 } |
| 275 #endif | 275 #endif |
| 276 | 276 |
| 277 // static | 277 // static |
| 278 bool NetworkChangeNotifier::IsOffline() { | |
| 279 return GetConnectionType() == CONNECTION_NONE; | |
| 280 } | |
| 281 | |
| 282 // static | |
| 283 bool NetworkChangeNotifier::IsConnectionCellular() { | |
| 284 return IsConnectionCellular(GetConnectionType()); | |
| 285 } | |
| 286 | |
| 287 // static | |
| 288 bool NetworkChangeNotifier::IsConnectionCellular(ConnectionType type) { | |
| 289 switch (type) { | |
| 290 case CONNECTION_2G: | |
| 291 case CONNECTION_3G: | |
| 292 case CONNECTION_4G: | |
| 293 return true; | |
| 294 case CONNECTION_UNKNOWN: | |
| 295 case CONNECTION_ETHERNET: | |
| 296 case CONNECTION_WIFI: | |
| 297 case CONNECTION_NONE: | |
| 298 return false; | |
| 299 default: | |
|
Ryan Sleevi
2012/10/12 17:49:57
If you remove this "default", you should get a com
| |
| 300 NOTREACHED(); | |
| 301 return false; | |
| 302 } | |
| 303 } | |
| 304 | |
| 305 // static | |
| 278 NetworkChangeNotifier* NetworkChangeNotifier::CreateMock() { | 306 NetworkChangeNotifier* NetworkChangeNotifier::CreateMock() { |
| 279 return new MockNetworkChangeNotifier(); | 307 return new MockNetworkChangeNotifier(); |
| 280 } | 308 } |
| 281 | 309 |
| 282 void NetworkChangeNotifier::AddIPAddressObserver(IPAddressObserver* observer) { | 310 void NetworkChangeNotifier::AddIPAddressObserver(IPAddressObserver* observer) { |
| 283 if (g_network_change_notifier) | 311 if (g_network_change_notifier) |
| 284 g_network_change_notifier->ip_address_observer_list_->AddObserver(observer); | 312 g_network_change_notifier->ip_address_observer_list_->AddObserver(observer); |
| 285 } | 313 } |
| 286 | 314 |
| 287 void NetworkChangeNotifier::AddConnectionTypeObserver( | 315 void NetworkChangeNotifier::AddConnectionTypeObserver( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 DCHECK(g_network_change_notifier); | 410 DCHECK(g_network_change_notifier); |
| 383 g_network_change_notifier = NULL; | 411 g_network_change_notifier = NULL; |
| 384 } | 412 } |
| 385 | 413 |
| 386 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 414 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
| 387 DCHECK(!g_network_change_notifier); | 415 DCHECK(!g_network_change_notifier); |
| 388 g_network_change_notifier = network_change_notifier_; | 416 g_network_change_notifier = network_change_notifier_; |
| 389 } | 417 } |
| 390 | 418 |
| 391 } // namespace net | 419 } // namespace net |
| OLD | NEW |