diff options
author | droger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 14:05:54 +0000 |
---|---|---|
committer | droger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 14:05:54 +0000 |
commit | 720f2afe68cefeac520da528d08cc197983e44db (patch) | |
tree | 7d835e039b4f53744bd0942ffc76cb98fd172538 /net | |
parent | 6aac319b874e48034163817596a500e1310816d4 (diff) | |
download | chromium_src-720f2afe68cefeac520da528d08cc197983e44db.zip chromium_src-720f2afe68cefeac520da528d08cc197983e44db.tar.gz chromium_src-720f2afe68cefeac520da528d08cc197983e44db.tar.bz2 |
Helper functions in NetworkChangeNotifier related to WWAN use
On iOS, this is used to disable certain features when WWAN is active in order to
save network traffic and/or battery.
BUG=145954
Review URL: https://chromiumcodereview.appspot.com/11115009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_change_notifier.cc | 24 | ||||
-rw-r--r-- | net/base/network_change_notifier.h | 15 |
2 files changed, 36 insertions, 3 deletions
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc index ab3fd43..e8dd120 100644 --- a/net/base/network_change_notifier.cc +++ b/net/base/network_change_notifier.cc @@ -298,6 +298,30 @@ NetworkChangeNotifier::GetAddressTracker() { #endif // static +bool NetworkChangeNotifier::IsOffline() { + return GetConnectionType() == CONNECTION_NONE; +} + +// static +bool NetworkChangeNotifier::IsConnectionCellular(ConnectionType type) { + bool is_cellular = false; + switch (type) { + case CONNECTION_2G: + case CONNECTION_3G: + case CONNECTION_4G: + is_cellular = true; + break; + case CONNECTION_UNKNOWN: + case CONNECTION_ETHERNET: + case CONNECTION_WIFI: + case CONNECTION_NONE: + is_cellular = false; + break; + } + return is_cellular; +} + +// static NetworkChangeNotifier* NetworkChangeNotifier::CreateMock() { return new MockNetworkChangeNotifier(); } diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h index 21aa1a1..84e399e 100644 --- a/net/base/network_change_notifier.h +++ b/net/base/network_change_notifier.h @@ -111,6 +111,10 @@ class NET_EXPORT NetworkChangeNotifier { // value doesn't imply that the user will be able to connect to remote sites; // even if some link is up, it is uncertain whether a particular connection // attempt to a particular remote site will be successful. + // The returned value only describes the connection currently used by the + // device, and does not take into account other machines on the network. For + // example, if the device is connected using Wifi to a 3G gateway to access + // the internet, the connection type is CONNECTION_WIFI. static ConnectionType GetConnectionType(); // Retrieve the last read DnsConfig. This could be expensive if the system has @@ -130,9 +134,14 @@ class NET_EXPORT NetworkChangeNotifier { // |false| is inconclusive; even if some link is up, it is uncertain // whether a particular connection attempt to a particular remote site // will be successfully. - static bool IsOffline() { - return GetConnectionType() == CONNECTION_NONE; - } + static bool IsOffline(); + + // Returns true if |type| is a cellular connection. + // Returns false if |type| is CONNECTION_UNKNOWN, and thus, depending on the + // implementation of GetConnectionType(), it is possible that + // IsConnectionCellular(GetConnectionType()) returns false even if the + // current connection is cellular. + static bool IsConnectionCellular(ConnectionType type); // Like Create(), but for use in tests. The mock object doesn't monitor any // events, it merely rebroadcasts notifications when requested. |