| 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 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/observer_list_threadsafe.h" | 9 #include "base/observer_list_threadsafe.h" |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // threads try to access the API below, and it must outlive all other threads | 104 // threads try to access the API below, and it must outlive all other threads |
| 105 // which might try to use it. | 105 // which might try to use it. |
| 106 static NetworkChangeNotifier* Create(); | 106 static NetworkChangeNotifier* Create(); |
| 107 | 107 |
| 108 // Returns the connection type. | 108 // Returns the connection type. |
| 109 // A return value of |CONNECTION_NONE| is a pretty strong indicator that the | 109 // A return value of |CONNECTION_NONE| is a pretty strong indicator that the |
| 110 // user won't be able to connect to remote sites. However, another return | 110 // user won't be able to connect to remote sites. However, another return |
| 111 // value doesn't imply that the user will be able to connect to remote sites; | 111 // value doesn't imply that the user will be able to connect to remote sites; |
| 112 // even if some link is up, it is uncertain whether a particular connection | 112 // even if some link is up, it is uncertain whether a particular connection |
| 113 // attempt to a particular remote site will be successful. | 113 // attempt to a particular remote site will be successful. |
| 114 // The returned value only describes the connection currently used by the |
| 115 // device, and does not take into account other machines on the network. For |
| 116 // example, if the device is connected using Wifi to a 3G gateway to access |
| 117 // the internet, the connection type is CONNECTION_WIFI. |
| 114 static ConnectionType GetConnectionType(); | 118 static ConnectionType GetConnectionType(); |
| 115 | 119 |
| 116 // Retrieve the last read DnsConfig. This could be expensive if the system has | 120 // Retrieve the last read DnsConfig. This could be expensive if the system has |
| 117 // a large HOSTS file. | 121 // a large HOSTS file. |
| 118 static void GetDnsConfig(DnsConfig* config); | 122 static void GetDnsConfig(DnsConfig* config); |
| 119 | 123 |
| 120 #if defined(OS_LINUX) | 124 #if defined(OS_LINUX) |
| 121 // Returns the AddressTrackerLinux if present. | 125 // Returns the AddressTrackerLinux if present. |
| 122 static const internal::AddressTrackerLinux* GetAddressTracker(); | 126 static const internal::AddressTrackerLinux* GetAddressTracker(); |
| 123 #endif | 127 #endif |
| 124 | 128 |
| 125 // Convenience method to determine if the user is offline. | 129 // Convenience method to determine if the user is offline. |
| 126 // Returns true if there is currently no internet connection. | 130 // Returns true if there is currently no internet connection. |
| 127 // | 131 // |
| 128 // A return value of |true| is a pretty strong indicator that the user | 132 // A return value of |true| is a pretty strong indicator that the user |
| 129 // won't be able to connect to remote sites. However, a return value of | 133 // won't be able to connect to remote sites. However, a return value of |
| 130 // |false| is inconclusive; even if some link is up, it is uncertain | 134 // |false| is inconclusive; even if some link is up, it is uncertain |
| 131 // whether a particular connection attempt to a particular remote site | 135 // whether a particular connection attempt to a particular remote site |
| 132 // will be successfully. | 136 // will be successfully. |
| 133 static bool IsOffline() { | 137 static bool IsOffline(); |
| 134 return GetConnectionType() == CONNECTION_NONE; | 138 |
| 135 } | 139 // Returns true if |type| is a cellular connection. |
| 140 // Returns false if |type| is CONNECTION_UNKNOWN, and thus, depending on the |
| 141 // implementation of GetConnectionType(), it is possible that |
| 142 // IsConnectionCellular(GetConnectionType()) returns false even if the |
| 143 // current connection is cellular. |
| 144 static bool IsConnectionCellular(ConnectionType type); |
| 136 | 145 |
| 137 // Like Create(), but for use in tests. The mock object doesn't monitor any | 146 // Like Create(), but for use in tests. The mock object doesn't monitor any |
| 138 // events, it merely rebroadcasts notifications when requested. | 147 // events, it merely rebroadcasts notifications when requested. |
| 139 static NetworkChangeNotifier* CreateMock(); | 148 static NetworkChangeNotifier* CreateMock(); |
| 140 | 149 |
| 141 // Registers |observer| to receive notifications of network changes. The | 150 // Registers |observer| to receive notifications of network changes. The |
| 142 // thread on which this is called is the thread on which |observer| will be | 151 // thread on which this is called is the thread on which |observer| will be |
| 143 // called back with notifications. This is safe to call if Create() has not | 152 // called back with notifications. This is safe to call if Create() has not |
| 144 // been called (as long as it doesn't race the Create() call on another | 153 // been called (as long as it doesn't race the Create() call on another |
| 145 // thread), in which case it will simply do nothing. | 154 // thread), in which case it will simply do nothing. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 238 |
| 230 // A little-piggy-back observer that simply logs UMA histogram data. | 239 // A little-piggy-back observer that simply logs UMA histogram data. |
| 231 scoped_ptr<HistogramWatcher> histogram_watcher_; | 240 scoped_ptr<HistogramWatcher> histogram_watcher_; |
| 232 | 241 |
| 233 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 242 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
| 234 }; | 243 }; |
| 235 | 244 |
| 236 } // namespace net | 245 } // namespace net |
| 237 | 246 |
| 238 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 247 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| OLD | NEW |