Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1181)

Unified Diff: net/base/network_change_notifier.h

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed a typo Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/network_change_notifier.h
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index 477d1f718cd6114710dd1b0ea5e374273025061e..20ee6eb48aac242773d24714c3fb4e089a81e106 100644
--- a/net/base/network_change_notifier.h
+++ b/net/base/network_change_notifier.h
@@ -38,6 +38,18 @@ class NET_EXPORT NetworkChangeNotifier {
CHANGE_DNS_WATCH_FAILED = 1 << 3,
};
+ // Using the terminology of the Network Information API:
+ // http://www.w3.org/TR/netinfo-api.
+ enum ConnectionType {
+ CONNECTION_UNKNOWN, // A connection exists, but its type is unknown.
+ CONNECTION_ETHERNET,
+ CONNECTION_WIFI,
+ CONNECTION_2G,
+ CONNECTION_3G,
+ CONNECTION_4G,
+ CONNECTION_NONE // No connection.
+};
+
class NET_EXPORT IPAddressObserver {
public:
virtual ~IPAddressObserver() {}
@@ -53,20 +65,21 @@ class NET_EXPORT NetworkChangeNotifier {
DISALLOW_COPY_AND_ASSIGN(IPAddressObserver);
};
- class NET_EXPORT OnlineStateObserver {
+ class NET_EXPORT ConnectionTypeObserver {
public:
- virtual ~OnlineStateObserver() {}
+ virtual ~ConnectionTypeObserver() {}
- // Will be called when the online state of the system may have changed.
- // See NetworkChangeNotifier::IsOffline() for important caveats about
- // the unreliability of this signal.
- virtual void OnOnlineStateChanged(bool online) = 0;
+ // Will be called when the connection type of the system has changed.
+ // See NetworkChangeNotifier::GetConnectionType() for important caveats
+ // about the unreliability of using this signal to infer the ability to
+ // reach remote sites.
+ virtual void OnConnectionTypeChanged(ConnectionType type) = 0;
protected:
- OnlineStateObserver() {}
+ ConnectionTypeObserver() {}
private:
- DISALLOW_COPY_AND_ASSIGN(OnlineStateObserver);
+ DISALLOW_COPY_AND_ASSIGN(ConnectionTypeObserver);
};
class NET_EXPORT DNSObserver {
@@ -86,10 +99,10 @@ class NET_EXPORT NetworkChangeNotifier {
virtual ~NetworkChangeNotifier();
- // See the description of NetworkChangeNotifier::IsOffline().
+ // See the description of NetworkChangeNotifier::GetConnectionType().
// Implementations must be thread-safe. Implementations must also be
// cheap as this could be called (repeatedly) from the IO thread.
- virtual bool IsCurrentlyOffline() const = 0;
+ virtual ConnectionType GetCurrentConnectionType() const = 0;
// Replaces the default class factory instance of NetworkChangeNotifier class.
// The method will take over the ownership of |factory| object.
@@ -103,6 +116,15 @@ class NET_EXPORT NetworkChangeNotifier {
// which might try to use it.
static NetworkChangeNotifier* Create();
+ // Returns the connection type.
+ // A return value of |CONNECTION_NONE| is a pretty strong indicator that the
+ // user won't be able to connect to remote sites. However, another return
+ // 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.
+ static ConnectionType GetConnectionType();
+
+ // Convenience method to determine if the user is offline.
// Returns true if there is currently no internet connection.
//
// A return value of |true| is a pretty strong indicator that the user
@@ -110,7 +132,9 @@ 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();
+ static bool IsOffline() {
+ return GetConnectionType() == CONNECTION_NONE;
+ }
// Returns true if DNS watcher is operational.
static bool IsWatchingDNS();
@@ -125,7 +149,7 @@ class NET_EXPORT NetworkChangeNotifier {
// been called (as long as it doesn't race the Create() call on another
// thread), in which case it will simply do nothing.
static void AddIPAddressObserver(IPAddressObserver* observer);
- static void AddOnlineStateObserver(OnlineStateObserver* observer);
+ static void AddConnectionTypeObserver(ConnectionTypeObserver* observer);
static void AddDNSObserver(DNSObserver* observer);
// Unregisters |observer| from receiving notifications. This must be called
@@ -136,7 +160,7 @@ class NET_EXPORT NetworkChangeNotifier {
// been destroyed, if the call doesn't race the notifier's destruction, but
// there's no reason to use the API in this risky way, so don't do it.
static void RemoveIPAddressObserver(IPAddressObserver* observer);
- static void RemoveOnlineStateObserver(OnlineStateObserver* observer);
+ static void RemoveConnectionTypeObserver(ConnectionTypeObserver* observer);
static void RemoveDNSObserver(DNSObserver* observer);
// Allow unit tests to trigger notifications.
@@ -153,7 +177,7 @@ class NET_EXPORT NetworkChangeNotifier {
// happens asynchronously, even for observers on the current thread, even in
// tests.
static void NotifyObserversOfIPAddressChange();
- static void NotifyObserversOfOnlineStateChange();
+ static void NotifyObserversOfConnectionTypeChange();
static void NotifyObserversOfDNSChange(unsigned detail);
private:
@@ -179,8 +203,8 @@ class NET_EXPORT NetworkChangeNotifier {
const scoped_refptr<ObserverListThreadSafe<IPAddressObserver> >
ip_address_observer_list_;
- const scoped_refptr<ObserverListThreadSafe<OnlineStateObserver> >
- online_state_observer_list_;
+ const scoped_refptr<ObserverListThreadSafe<ConnectionTypeObserver> >
+ connection_type_observer_list_;
const scoped_refptr<ObserverListThreadSafe<DNSObserver> >
resolver_state_observer_list_;
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698