[email protected] | 446df295 | 2012-02-28 07:22:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| 6 | #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 10 | #include <memory> |
derekjchow | 5482d5e | 2015-01-31 01:04:51 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 14 | #include "base/observer_list_threadsafe.h" |
[email protected] | 9da992db | 2013-06-28 05:40:47 | [diff] [blame] | 15 | #include "base/time/time.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 16 | #include "net/base/net_export.h" |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 17 | |
| 18 | namespace net { |
| 19 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 20 | struct DnsConfig; |
[email protected] | 373badd | 2011-07-11 21:55:58 | [diff] [blame] | 21 | class NetworkChangeNotifierFactory; |
derekjchow | 5482d5e | 2015-01-31 01:04:51 | [diff] [blame] | 22 | struct NetworkInterface; |
| 23 | typedef std::vector<NetworkInterface> NetworkInterfaceList; |
[email protected] | 373badd | 2011-07-11 21:55:58 | [diff] [blame] | 24 | |
[email protected] | 6717280 | 2012-07-16 22:27:24 | [diff] [blame] | 25 | #if defined(OS_LINUX) |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 26 | namespace internal { |
[email protected] | 6717280 | 2012-07-16 22:27:24 | [diff] [blame] | 27 | class AddressTrackerLinux; |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 28 | } |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 29 | #endif |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 30 | |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 31 | // NetworkChangeNotifier monitors the system for network changes, and notifies |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 32 | // registered observers of those events. Observers may register on any thread, |
| 33 | // and will be called back on the thread from which they registered. |
[email protected] | aab6693 | 2011-10-05 17:08:13 | [diff] [blame] | 34 | // NetworkChangeNotifiers are threadsafe, though they must be created and |
| 35 | // destroyed on the same thread. |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 36 | class NET_EXPORT NetworkChangeNotifier { |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 37 | public: |
[email protected] | 078cab2 | 2014-06-04 14:08:40 | [diff] [blame] | 38 | // This is a superset of the connection types in the NetInfo v3 specification: |
| 39 | // http://w3c.github.io/netinfo/. |
jkarlin | 0818d525 | 2014-12-02 21:06:02 | [diff] [blame] | 40 | // |
| 41 | // A Java counterpart will be generated for this enum. |
| 42 | // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
gayane | 4849a807 | 2015-03-27 16:49:28 | [diff] [blame] | 43 | // |
| 44 | // New enum values should only be added to the end of the enum and no values |
| 45 | // should be modified or reused, as this is reported via UMA. |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 46 | enum ConnectionType { |
[email protected] | d7ff5fb | 2014-05-29 19:50:25 | [diff] [blame] | 47 | CONNECTION_UNKNOWN = 0, // A connection exists, but its type is unknown. |
| 48 | // Also used as a default value. |
[email protected] | e0535b0 | 2012-09-11 00:30:37 | [diff] [blame] | 49 | CONNECTION_ETHERNET = 1, |
| 50 | CONNECTION_WIFI = 2, |
| 51 | CONNECTION_2G = 3, |
| 52 | CONNECTION_3G = 4, |
| 53 | CONNECTION_4G = 5, |
[email protected] | d7ff5fb | 2014-05-29 19:50:25 | [diff] [blame] | 54 | CONNECTION_NONE = 6, // No connection. |
[email protected] | 078cab2 | 2014-06-04 14:08:40 | [diff] [blame] | 55 | CONNECTION_BLUETOOTH = 7, |
| 56 | CONNECTION_LAST = CONNECTION_BLUETOOTH |
[email protected] | a6b32f6e | 2012-06-20 23:46:26 | [diff] [blame] | 57 | }; |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 58 | |
jkarlin | 0818d525 | 2014-12-02 21:06:02 | [diff] [blame] | 59 | // This is the NetInfo v3 set of connection technologies as seen in |
bmcquade | 3f55de79 | 2016-02-26 22:10:37 | [diff] [blame] | 60 | // http://w3c.github.io/netinfo/. This enum is duplicated in histograms.xml |
| 61 | // so be sure to change both at once. Additionally, since this enum is used in |
| 62 | // a UMA histogram, it should not be re-ordered and any new values should be |
| 63 | // added to the end. |
jkarlin | 0818d525 | 2014-12-02 21:06:02 | [diff] [blame] | 64 | // |
| 65 | // A Java counterpart will be generated for this enum. |
| 66 | // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
| 67 | enum ConnectionSubtype { |
bmcquade | 25781b4 | 2016-02-26 05:41:14 | [diff] [blame] | 68 | SUBTYPE_UNKNOWN = 0, |
| 69 | SUBTYPE_NONE, |
| 70 | SUBTYPE_OTHER, |
| 71 | SUBTYPE_GSM, |
jkarlin | 0818d525 | 2014-12-02 21:06:02 | [diff] [blame] | 72 | SUBTYPE_IDEN, |
| 73 | SUBTYPE_CDMA, |
| 74 | SUBTYPE_1XRTT, |
| 75 | SUBTYPE_GPRS, |
| 76 | SUBTYPE_EDGE, |
| 77 | SUBTYPE_UMTS, |
| 78 | SUBTYPE_EVDO_REV_0, |
| 79 | SUBTYPE_EVDO_REV_A, |
| 80 | SUBTYPE_HSPA, |
| 81 | SUBTYPE_EVDO_REV_B, |
| 82 | SUBTYPE_HSDPA, |
| 83 | SUBTYPE_HSUPA, |
| 84 | SUBTYPE_EHRPD, |
| 85 | SUBTYPE_HSPAP, |
| 86 | SUBTYPE_LTE, |
| 87 | SUBTYPE_LTE_ADVANCED, |
| 88 | SUBTYPE_BLUETOOTH_1_2, |
| 89 | SUBTYPE_BLUETOOTH_2_1, |
| 90 | SUBTYPE_BLUETOOTH_3_0, |
| 91 | SUBTYPE_BLUETOOTH_4_0, |
| 92 | SUBTYPE_ETHERNET, |
| 93 | SUBTYPE_FAST_ETHERNET, |
| 94 | SUBTYPE_GIGABIT_ETHERNET, |
| 95 | SUBTYPE_10_GIGABIT_ETHERNET, |
| 96 | SUBTYPE_WIFI_B, |
| 97 | SUBTYPE_WIFI_G, |
| 98 | SUBTYPE_WIFI_N, |
| 99 | SUBTYPE_WIFI_AC, |
| 100 | SUBTYPE_WIFI_AD, |
bmcquade | 25781b4 | 2016-02-26 05:41:14 | [diff] [blame] | 101 | SUBTYPE_LAST = SUBTYPE_WIFI_AD |
jkarlin | 0818d525 | 2014-12-02 21:06:02 | [diff] [blame] | 102 | }; |
| 103 | |
Helen Li | f234a7f | 2017-08-11 16:06:51 | [diff] [blame] | 104 | // DEPRECATED. Please use NetworkChangeObserver instead. crbug.com/754695. |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 105 | class NET_EXPORT IPAddressObserver { |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 106 | public: |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 107 | // Will be called when the IP address of the primary interface changes. |
| 108 | // This includes when the primary interface itself changes. |
| 109 | virtual void OnIPAddressChanged() = 0; |
| 110 | |
| 111 | protected: |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 112 | IPAddressObserver() {} |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 113 | virtual ~IPAddressObserver() {} |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 114 | |
| 115 | private: |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 116 | DISALLOW_COPY_AND_ASSIGN(IPAddressObserver); |
| 117 | }; |
| 118 | |
Helen Li | f234a7f | 2017-08-11 16:06:51 | [diff] [blame] | 119 | // DEPRECATED. Please use NetworkChangeObserver instead. crbug.com/754695. |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 120 | class NET_EXPORT ConnectionTypeObserver { |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 121 | public: |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 122 | // Will be called when the connection type of the system has changed. |
| 123 | // See NetworkChangeNotifier::GetConnectionType() for important caveats |
| 124 | // about the unreliability of using this signal to infer the ability to |
| 125 | // reach remote sites. |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 126 | virtual void OnConnectionTypeChanged(ConnectionType type) = 0; |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 127 | |
| 128 | protected: |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 129 | ConnectionTypeObserver() {} |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 130 | virtual ~ConnectionTypeObserver() {} |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 131 | |
| 132 | private: |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(ConnectionTypeObserver); |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 134 | }; |
| 135 | |
[email protected] | 46018c9d | 2011-09-06 03:42:34 | [diff] [blame] | 136 | class NET_EXPORT DNSObserver { |
| 137 | public: |
[email protected] | 446df295 | 2012-02-28 07:22:51 | [diff] [blame] | 138 | // Will be called when the DNS settings of the system may have changed. |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 139 | // Use GetDnsConfig to obtain the current settings. |
| 140 | virtual void OnDNSChanged() = 0; |
pauljensen | 101ed37 | 2015-04-17 00:11:42 | [diff] [blame] | 141 | // Will be called when DNS settings of the system have been loaded. |
| 142 | // Use GetDnsConfig to obtain the current settings. |
Paul Jensen | 1ef04a3 | 2018-05-04 15:12:15 | [diff] [blame] | 143 | // NOTE(pauljensen): This will not be called if the initial DNS config |
| 144 | // has already been read before this observer is registered. |
| 145 | // Determining if a DNS config has already been read can be done by |
| 146 | // calling GetDnsConfig() after registering an observer, and seeing if |
| 147 | // the DnsConfig's IsValid() returns true. |
pauljensen | 101ed37 | 2015-04-17 00:11:42 | [diff] [blame] | 148 | virtual void OnInitialDNSConfigRead(); |
[email protected] | 46018c9d | 2011-09-06 03:42:34 | [diff] [blame] | 149 | |
| 150 | protected: |
| 151 | DNSObserver() {} |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 152 | virtual ~DNSObserver() {} |
[email protected] | 46018c9d | 2011-09-06 03:42:34 | [diff] [blame] | 153 | |
| 154 | private: |
| 155 | DISALLOW_COPY_AND_ASSIGN(DNSObserver); |
| 156 | }; |
| 157 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 158 | class NET_EXPORT NetworkChangeObserver { |
| 159 | public: |
| 160 | // OnNetworkChanged will be called when a change occurs to the host |
| 161 | // computer's hardware or software that affects the route network packets |
| 162 | // take to any network server. Some examples: |
| 163 | // 1. A network connection becoming available or going away. For example |
| 164 | // plugging or unplugging an Ethernet cable, WiFi or cellular modem |
| 165 | // connecting or disconnecting from a network, or a VPN tunnel being |
| 166 | // established or taken down. |
| 167 | // 2. An active network connection's IP address changes. |
| 168 | // 3. A change to the local IP routing tables. |
| 169 | // The signal shall only be produced when the change is complete. For |
| 170 | // example if a new network connection has become available, only give the |
| 171 | // signal once we think the O/S has finished establishing the connection |
| 172 | // (i.e. DHCP is done) to the point where the new connection is usable. |
| 173 | // The signal shall not be produced spuriously as it will be triggering some |
| 174 | // expensive operations, like socket pools closing all connections and |
| 175 | // sockets and then re-establishing them. |
| 176 | // |type| indicates the type of the active primary network connection after |
| 177 | // the change. Observers performing "constructive" activities like trying |
| 178 | // to establish a connection to a server should only do so when |
| 179 | // |type != CONNECTION_NONE|. Observers performing "destructive" activities |
| 180 | // like resetting already established server connections should only do so |
| 181 | // when |type == CONNECTION_NONE|. OnNetworkChanged will always be called |
| 182 | // with CONNECTION_NONE immediately prior to being called with an online |
| 183 | // state; this is done to make sure that destructive actions take place |
| 184 | // prior to constructive actions. |
| 185 | virtual void OnNetworkChanged(ConnectionType type) = 0; |
| 186 | |
| 187 | protected: |
| 188 | NetworkChangeObserver() {} |
| 189 | virtual ~NetworkChangeObserver() {} |
| 190 | |
| 191 | private: |
| 192 | DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserver); |
| 193 | }; |
| 194 | |
jkarlin | 7b25e6c | 2014-12-16 19:59:47 | [diff] [blame] | 195 | class NET_EXPORT MaxBandwidthObserver { |
| 196 | public: |
jkarlin | bce49186 | 2015-09-18 15:14:07 | [diff] [blame] | 197 | // Called when a change occurs to the network's maximum bandwidth as |
| 198 | // defined in http://w3c.github.io/netinfo/. Also called on type change, |
| 199 | // even if the maximum bandwidth doesn't change. See the documentation of |
| 200 | // GetMaxBanwidthAndConnectionType for what to expect for the values of |
| 201 | // |max_bandwidth_mbps|. |
| 202 | virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps, |
| 203 | ConnectionType type) = 0; |
jkarlin | 7b25e6c | 2014-12-16 19:59:47 | [diff] [blame] | 204 | |
| 205 | protected: |
| 206 | MaxBandwidthObserver() {} |
| 207 | virtual ~MaxBandwidthObserver() {} |
| 208 | |
| 209 | private: |
| 210 | DISALLOW_COPY_AND_ASSIGN(MaxBandwidthObserver); |
| 211 | }; |
| 212 | |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 213 | // Opaque handle for device-wide connection to a particular network. For |
| 214 | // example an association with a particular WiFi network with a particular |
| 215 | // SSID or a connection to particular cellular network. |
| 216 | // The meaning of this handle is target-dependent. On Android NetworkHandles |
pauljensen | 479143c | 2016-07-22 12:35:09 | [diff] [blame] | 217 | // are equivalent to: |
| 218 | // On Lollipop, the framework's concept of NetIDs (e.g. Network.netId), and |
| 219 | // On Marshmallow and newer releases, network handles |
| 220 | // (e.g. Network.getNetworkHandle()). |
| 221 | typedef int64_t NetworkHandle; |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 222 | |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 223 | // A list of networks. |
| 224 | typedef std::vector<NetworkHandle> NetworkList; |
| 225 | |
| 226 | // An interface that when implemented and added via AddNeworkObserver(), |
| 227 | // provides notifications when networks come and go. |
| 228 | // Only implemented for Android (Lollipop and newer), no callbacks issued when |
| 229 | // unimplemented. |
| 230 | class NET_EXPORT NetworkObserver { |
| 231 | public: |
| 232 | // Called when device connects to |network|. For example device associates |
| 233 | // with a WiFi access point. This does not imply the network has Internet |
| 234 | // access as it may well be behind a captive portal. |
| 235 | virtual void OnNetworkConnected(NetworkHandle network) = 0; |
| 236 | // Called when device disconnects from |network|. |
| 237 | virtual void OnNetworkDisconnected(NetworkHandle network) = 0; |
| 238 | // Called when device determines the connection to |network| is no longer |
| 239 | // preferred, for example when a device transitions from cellular to WiFi |
| 240 | // it might deem the cellular connection no longer preferred. The device |
| 241 | // will disconnect from |network| in a period of time (30s on Android), |
| 242 | // allowing network communications via |network| to wrap up. |
| 243 | virtual void OnNetworkSoonToDisconnect(NetworkHandle network) = 0; |
| 244 | // Called when |network| is made the default network for communication. |
| 245 | virtual void OnNetworkMadeDefault(NetworkHandle network) = 0; |
| 246 | |
| 247 | protected: |
| 248 | NetworkObserver() {} |
| 249 | virtual ~NetworkObserver() {} |
| 250 | |
| 251 | private: |
| 252 | DISALLOW_COPY_AND_ASSIGN(NetworkObserver); |
| 253 | }; |
| 254 | |
| 255 | // An invalid NetworkHandle. |
| 256 | static const NetworkHandle kInvalidNetworkHandle; |
| 257 | |
| 258 | virtual ~NetworkChangeNotifier(); |
[email protected] | 2d3b776 | 2010-10-09 00:35:47 | [diff] [blame] | 259 | |
Pengcheng | eaf5ae2 | 2018-01-18 01:57:17 | [diff] [blame] | 260 | // Returns the factory or nullptr if it is not set. |
| 261 | static NetworkChangeNotifierFactory* GetFactory(); |
| 262 | |
[email protected] | 373badd | 2011-07-11 21:55:58 | [diff] [blame] | 263 | // Replaces the default class factory instance of NetworkChangeNotifier class. |
| 264 | // The method will take over the ownership of |factory| object. |
| 265 | static void SetFactory(NetworkChangeNotifierFactory* factory); |
| 266 | |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 267 | // Creates the process-wide, platform-specific NetworkChangeNotifier. The |
| 268 | // caller owns the returned pointer. You may call this on any thread. You |
| 269 | // may also avoid creating this entirely (in which case nothing will be |
| 270 | // monitored), but if you do create it, you must do so before any other |
| 271 | // threads try to access the API below, and it must outlive all other threads |
| 272 | // which might try to use it. |
| 273 | static NetworkChangeNotifier* Create(); |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 274 | |
Helen Li | d19d0f0 | 2017-10-23 13:49:57 | [diff] [blame] | 275 | // Returns whether the process-wide, platform-specific NetworkChangeNotifier |
| 276 | // has been created. |
| 277 | static bool HasNetworkChangeNotifier(); |
| 278 | |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 279 | // Returns the connection type. |
| 280 | // A return value of |CONNECTION_NONE| is a pretty strong indicator that the |
| 281 | // user won't be able to connect to remote sites. However, another return |
| 282 | // value doesn't imply that the user will be able to connect to remote sites; |
| 283 | // even if some link is up, it is uncertain whether a particular connection |
| 284 | // attempt to a particular remote site will be successful. |
tbansal | 880e49e7 | 2017-03-25 04:44:25 | [diff] [blame] | 285 | // The returned value only describes the first-hop connection, for example if |
| 286 | // the device is connected via WiFi to a 4G hotspot, the returned value will |
| 287 | // be CONNECTION_WIFI, not CONNECTION_4G. |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 288 | static ConnectionType GetConnectionType(); |
| 289 | |
tbansal | 880e49e7 | 2017-03-25 04:44:25 | [diff] [blame] | 290 | // Returns the device's current default active network connection's subtype. |
| 291 | // The returned value only describes the first-hop connection, for example if |
| 292 | // the device is connected via WiFi to a 4G hotspot, the returned value will |
| 293 | // reflect WiFi, not 4G. This method may return SUBTYPE_UNKNOWN even if the |
| 294 | // connection type is known. |
| 295 | static ConnectionSubtype GetConnectionSubtype(); |
| 296 | |
jkarlin | bce49186 | 2015-09-18 15:14:07 | [diff] [blame] | 297 | // Sets |max_bandwidth_mbps| to a theoretical upper limit on download |
| 298 | // bandwidth, potentially based on underlying connection type, signal |
| 299 | // strength, or some other signal. If the network subtype is unknown then |
| 300 | // |max_bandwidth_mbps| is set to +Infinity and if there is no network |
| 301 | // connection then it is set to 0.0. The circumstances in which a more |
| 302 | // specific value is given are: when an Android device is connected to a |
| 303 | // cellular or WiFi network, and when a ChromeOS device is connected to a |
| 304 | // cellular network. See the NetInfo spec for the mapping of |
| 305 | // specific subtypes to bandwidth values: http://w3c.github.io/netinfo/. |
| 306 | // |connection_type| is set to the current active default network's connection |
| 307 | // type. |
| 308 | static void GetMaxBandwidthAndConnectionType(double* max_bandwidth_mbps, |
| 309 | ConnectionType* connection_type); |
jkarlin | 59a81093 | 2014-10-06 18:00:43 | [diff] [blame] | 310 | |
jkarlin | 300a1d2 | 2015-09-18 19:32:52 | [diff] [blame] | 311 | // Returns a theoretical upper limit (in Mbps) on download bandwidth given a |
| 312 | // connection subtype. The mapping of connection type to maximum bandwidth is |
| 313 | // provided in the NetInfo spec: http://w3c.github.io/netinfo/. |
zhuoyu.qian | 4d65140 | 2017-10-30 13:03:33 | [diff] [blame] | 314 | static double GetMaxBandwidthMbpsForConnectionSubtype( |
| 315 | ConnectionSubtype subtype); |
jkarlin | 300a1d2 | 2015-09-18 19:32:52 | [diff] [blame] | 316 | |
jri | c94943b | 2015-12-03 18:50:22 | [diff] [blame] | 317 | // Returns true if the platform supports use of APIs based on NetworkHandles. |
| 318 | // Public methods that use NetworkHandles are GetNetworkConnectionType(), |
| 319 | // GetNetworkConnectionType(), GetDefaultNetwork(), AddNetworkObserver(), |
| 320 | // RemoveNetworkObserver(), and all public NetworkObserver methods. |
| 321 | static bool AreNetworkHandlesSupported(); |
| 322 | |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 323 | // Sets |network_list| to a list of all networks that are currently connected. |
| 324 | // Only implemented for Android (Lollipop and newer), leaves |network_list| |
jri | c94943b | 2015-12-03 18:50:22 | [diff] [blame] | 325 | // empty when unimplemented. Requires NetworkHandles support, see |
| 326 | // AreNetworkHandlesSupported(). |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 327 | static void GetConnectedNetworks(NetworkList* network_list); |
| 328 | |
| 329 | // Returns the type of connection |network| uses. Note that this may vary |
| 330 | // slightly over time (e.g. CONNECTION_2G to CONNECTION_3G). If |network| |
| 331 | // is no longer connected, it will return CONNECTION_UNKNOWN. |
| 332 | // Only implemented for Android (Lollipop and newer), returns |
jri | c94943b | 2015-12-03 18:50:22 | [diff] [blame] | 333 | // CONNECTION_UNKNOWN when unimplemented. Requires NetworkHandles support, |
| 334 | // see AreNetworkHandlesSupported(). |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 335 | static ConnectionType GetNetworkConnectionType(NetworkHandle network); |
| 336 | |
| 337 | // Returns the device's current default network connection. This is the |
| 338 | // network used for newly created socket communication for sockets that are |
| 339 | // not explicitly bound to a particular network (e.g. via |
| 340 | // DatagramClientSocket.BindToNetwork). Returns |kInvalidNetworkHandle| if |
| 341 | // there is no default connected network. |
| 342 | // Only implemented for Android (Lollipop and newer), returns |
| 343 | // |kInvalidNetworkHandle| when unimplemented. |
jri | c94943b | 2015-12-03 18:50:22 | [diff] [blame] | 344 | // Requires NetworkHandles support, see AreNetworkHandlesSupported(). |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 345 | static NetworkHandle GetDefaultNetwork(); |
| 346 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 347 | // Retrieve the last read DnsConfig. This could be expensive if the system has |
| 348 | // a large HOSTS file. |
| 349 | static void GetDnsConfig(DnsConfig* config); |
| 350 | |
[email protected] | 6717280 | 2012-07-16 22:27:24 | [diff] [blame] | 351 | #if defined(OS_LINUX) |
| 352 | // Returns the AddressTrackerLinux if present. |
| 353 | static const internal::AddressTrackerLinux* GetAddressTracker(); |
| 354 | #endif |
| 355 | |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 356 | // Convenience method to determine if the user is offline. |
[email protected] | 2d3b776 | 2010-10-09 00:35:47 | [diff] [blame] | 357 | // Returns true if there is currently no internet connection. |
| 358 | // |
| 359 | // A return value of |true| is a pretty strong indicator that the user |
| 360 | // won't be able to connect to remote sites. However, a return value of |
| 361 | // |false| is inconclusive; even if some link is up, it is uncertain |
| 362 | // whether a particular connection attempt to a particular remote site |
| 363 | // will be successfully. |
[email protected] | 720f2afe | 2012-11-05 14:05:54 | [diff] [blame] | 364 | static bool IsOffline(); |
| 365 | |
| 366 | // Returns true if |type| is a cellular connection. |
| 367 | // Returns false if |type| is CONNECTION_UNKNOWN, and thus, depending on the |
| 368 | // implementation of GetConnectionType(), it is possible that |
| 369 | // IsConnectionCellular(GetConnectionType()) returns false even if the |
| 370 | // current connection is cellular. |
| 371 | static bool IsConnectionCellular(ConnectionType type); |
[email protected] | 2d3b776 | 2010-10-09 00:35:47 | [diff] [blame] | 372 | |
derekjchow | 5482d5e | 2015-01-31 01:04:51 | [diff] [blame] | 373 | // Gets the current connection type based on |interfaces|. Returns |
| 374 | // CONNECTION_NONE if there are no interfaces, CONNECTION_UNKNOWN if two |
| 375 | // interfaces have different connection types or the connection type of all |
| 376 | // interfaces if they have the same interface type. |
| 377 | static ConnectionType ConnectionTypeFromInterfaceList( |
| 378 | const NetworkInterfaceList& interfaces); |
| 379 | |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 380 | // Like Create(), but for use in tests. The mock object doesn't monitor any |
| 381 | // events, it merely rebroadcasts notifications when requested. |
[email protected] | 2d3b776 | 2010-10-09 00:35:47 | [diff] [blame] | 382 | static NetworkChangeNotifier* CreateMock(); |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 383 | |
| 384 | // Registers |observer| to receive notifications of network changes. The |
| 385 | // thread on which this is called is the thread on which |observer| will be |
| 386 | // called back with notifications. This is safe to call if Create() has not |
| 387 | // been called (as long as it doesn't race the Create() call on another |
| 388 | // thread), in which case it will simply do nothing. |
Helen Li | f234a7f | 2017-08-11 16:06:51 | [diff] [blame] | 389 | |
| 390 | // DEPRECATED. IPAddressObserver is deprecated. Please use |
| 391 | // NetworkChangeObserver instead. crbug.com/754695. |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 392 | static void AddIPAddressObserver(IPAddressObserver* observer); |
Helen Li | f234a7f | 2017-08-11 16:06:51 | [diff] [blame] | 393 | // DEPRECATED. ConnectionTypeObserver is deprecated. Please use |
| 394 | // NetworkChangeObserver instead. crbug.com/754695. |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 395 | static void AddConnectionTypeObserver(ConnectionTypeObserver* observer); |
[email protected] | 46018c9d | 2011-09-06 03:42:34 | [diff] [blame] | 396 | static void AddDNSObserver(DNSObserver* observer); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 397 | static void AddNetworkChangeObserver(NetworkChangeObserver* observer); |
jkarlin | 7b25e6c | 2014-12-16 19:59:47 | [diff] [blame] | 398 | static void AddMaxBandwidthObserver(MaxBandwidthObserver* observer); |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 399 | static void AddNetworkObserver(NetworkObserver* observer); |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 400 | |
| 401 | // Unregisters |observer| from receiving notifications. This must be called |
| 402 | // on the same thread on which AddObserver() was called. Like AddObserver(), |
| 403 | // this is safe to call if Create() has not been called (as long as it doesn't |
| 404 | // race the Create() call on another thread), in which case it will simply do |
| 405 | // nothing. Technically, it's also safe to call after the notifier object has |
| 406 | // been destroyed, if the call doesn't race the notifier's destruction, but |
| 407 | // there's no reason to use the API in this risky way, so don't do it. |
Helen Li | f234a7f | 2017-08-11 16:06:51 | [diff] [blame] | 408 | |
| 409 | // DEPRECATED. IPAddressObserver is deprecated. Please use |
| 410 | // NetworkChangeObserver instead. crbug.com/754695. |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 411 | static void RemoveIPAddressObserver(IPAddressObserver* observer); |
Helen Li | f234a7f | 2017-08-11 16:06:51 | [diff] [blame] | 412 | // DEPRECATED. ConnectionTypeObserver is deprecated. Please use |
| 413 | // NetworkChangeObserver instead. crbug.com/754695. |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 414 | static void RemoveConnectionTypeObserver(ConnectionTypeObserver* observer); |
[email protected] | 46018c9d | 2011-09-06 03:42:34 | [diff] [blame] | 415 | static void RemoveDNSObserver(DNSObserver* observer); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 416 | static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); |
jkarlin | 7b25e6c | 2014-12-16 19:59:47 | [diff] [blame] | 417 | static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 418 | static void RemoveNetworkObserver(NetworkObserver* observer); |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 419 | |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 420 | // Allow unit tests to trigger notifications. |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 421 | static void NotifyObserversOfIPAddressChangeForTests(); |
| 422 | static void NotifyObserversOfConnectionTypeChangeForTests( |
| 423 | ConnectionType type); |
mgersh | 92b1af1 | 2017-03-29 15:49:23 | [diff] [blame] | 424 | static void NotifyObserversOfDNSChangeForTests(); |
jaekyun | 22b4769 | 2014-09-04 23:22:41 | [diff] [blame] | 425 | static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); |
pauljensen | 101ed37 | 2015-04-17 00:11:42 | [diff] [blame] | 426 | static void NotifyObserversOfInitialDNSConfigReadForTests(); |
jkarlin | bce49186 | 2015-09-18 15:14:07 | [diff] [blame] | 427 | static void NotifyObserversOfMaxBandwidthChangeForTests( |
| 428 | double max_bandwidth_mbps, |
| 429 | ConnectionType type); |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 430 | |
| 431 | // Enable or disable notifications from the host. After setting to true, be |
| 432 | // sure to pump the RunLoop until idle to finish any preexisting |
jkarlin | e160f6b | 2015-07-31 17:04:08 | [diff] [blame] | 433 | // notifications. To use this, it must must be called before a |
| 434 | // NetworkChangeNotifier is created. |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 435 | static void SetTestNotificationsOnly(bool test_only); |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 436 | |
[email protected] | 3d5aaad | 2012-10-27 12:31:28 | [diff] [blame] | 437 | // Return a string equivalent to |type|. |
| 438 | static const char* ConnectionTypeToString(ConnectionType type); |
| 439 | |
bmcquade | 3f55de79 | 2016-02-26 22:10:37 | [diff] [blame] | 440 | // Invoked at the time a new user metrics log record is being finalized, on |
| 441 | // the main thread. NCN Histograms that want to be logged once per record |
| 442 | // should be logged in this method. Platform-specific histograms should be |
| 443 | // logged in an overridden implementaton of OnFinalizingMetricsLogRecord. |
| 444 | static void FinalizingMetricsLogRecord(); |
| 445 | |
[email protected] | 2a321de3 | 2014-05-10 19:59:06 | [diff] [blame] | 446 | // Log the |NCN.NetworkOperatorMCCMNC| histogram. |
| 447 | static void LogOperatorCodeHistogram(ConnectionType type); |
| 448 | |
[email protected] | ca45640 | 2013-05-21 01:07:07 | [diff] [blame] | 449 | // Allows a second NetworkChangeNotifier to be created for unit testing, so |
| 450 | // the test suite can create a MockNetworkChangeNotifier, but platform |
| 451 | // specific NetworkChangeNotifiers can also be created for testing. To use, |
| 452 | // create an DisableForTest object, and then create the new |
| 453 | // NetworkChangeNotifier object. The NetworkChangeNotifier must be |
| 454 | // destroyed before the DisableForTest object, as its destruction will restore |
| 455 | // the original NetworkChangeNotifier. |
| 456 | class NET_EXPORT DisableForTest { |
| 457 | public: |
| 458 | DisableForTest(); |
| 459 | ~DisableForTest(); |
| 460 | |
| 461 | private: |
| 462 | // The original NetworkChangeNotifier to be restored on destruction. |
| 463 | NetworkChangeNotifier* network_change_notifier_; |
| 464 | }; |
| 465 | |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 466 | protected: |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 467 | // Types of network changes specified to |
| 468 | // NotifyObserversOfSpecificNetworkChange. |
| 469 | enum NetworkChangeType { |
| 470 | CONNECTED, |
| 471 | DISCONNECTED, |
| 472 | SOON_TO_DISCONNECT, |
| 473 | MADE_DEFAULT |
| 474 | }; |
| 475 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 476 | // NetworkChanged signal is calculated from the IPAddressChanged and |
| 477 | // ConnectionTypeChanged signals. Delay parameters control how long to delay |
| 478 | // producing NetworkChanged signal after particular input signals so as to |
| 479 | // combine duplicates. In other words if an input signal is repeated within |
| 480 | // the corresponding delay period, only one resulting NetworkChange signal is |
| 481 | // produced. |
| 482 | struct NET_EXPORT NetworkChangeCalculatorParams { |
| 483 | NetworkChangeCalculatorParams(); |
| 484 | // Controls delay after OnIPAddressChanged when transitioning from an |
| 485 | // offline state. |
| 486 | base::TimeDelta ip_address_offline_delay_; |
| 487 | // Controls delay after OnIPAddressChanged when transitioning from an |
| 488 | // online state. |
| 489 | base::TimeDelta ip_address_online_delay_; |
| 490 | // Controls delay after OnConnectionTypeChanged when transitioning from an |
| 491 | // offline state. |
| 492 | base::TimeDelta connection_type_offline_delay_; |
| 493 | // Controls delay after OnConnectionTypeChanged when transitioning from an |
| 494 | // online state. |
| 495 | base::TimeDelta connection_type_online_delay_; |
| 496 | }; |
| 497 | |
| 498 | explicit NetworkChangeNotifier( |
| 499 | const NetworkChangeCalculatorParams& params = |
| 500 | NetworkChangeCalculatorParams()); |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 501 | |
[email protected] | 6717280 | 2012-07-16 22:27:24 | [diff] [blame] | 502 | #if defined(OS_LINUX) |
| 503 | // Returns the AddressTrackerLinux if present. |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 504 | // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212 |
[email protected] | 6717280 | 2012-07-16 22:27:24 | [diff] [blame] | 505 | virtual const internal::AddressTrackerLinux* |
| 506 | GetAddressTrackerInternal() const; |
| 507 | #endif |
| 508 | |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 509 | // These are the actual implementations of the static queryable APIs. |
| 510 | // See the description of the corresponding functions named without "Current". |
jkarlin | 59a81093 | 2014-10-06 18:00:43 | [diff] [blame] | 511 | // Implementations must be thread-safe. Implementations must also be |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 512 | // cheap as they are called often. |
| 513 | virtual ConnectionType GetCurrentConnectionType() const = 0; |
tbansal | 880e49e7 | 2017-03-25 04:44:25 | [diff] [blame] | 514 | virtual ConnectionSubtype GetCurrentConnectionSubtype() const; |
jkarlin | bce49186 | 2015-09-18 15:14:07 | [diff] [blame] | 515 | virtual void GetCurrentMaxBandwidthAndConnectionType( |
| 516 | double* max_bandwidth_mbps, |
| 517 | ConnectionType* connection_type) const; |
jri | c94943b | 2015-12-03 18:50:22 | [diff] [blame] | 518 | virtual bool AreNetworkHandlesCurrentlySupported() const; |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 519 | virtual void GetCurrentConnectedNetworks(NetworkList* network_list) const; |
| 520 | virtual ConnectionType GetCurrentNetworkConnectionType( |
| 521 | NetworkHandle network) const; |
| 522 | virtual NetworkHandle GetCurrentDefaultNetwork() const; |
jkarlin | 59a81093 | 2014-10-06 18:00:43 | [diff] [blame] | 523 | |
bmcquade | 3f55de79 | 2016-02-26 22:10:37 | [diff] [blame] | 524 | // Hook that allows derived implementations to log histograms at the time a |
| 525 | // new histogram record is being finalized. |
| 526 | virtual void OnFinalizingMetricsLogRecord() {} |
| 527 | |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 528 | // Broadcasts a notification to all registered observers. Note that this |
| 529 | // happens asynchronously, even for observers on the current thread, even in |
| 530 | // tests. |
| 531 | static void NotifyObserversOfIPAddressChange(); |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 532 | static void NotifyObserversOfConnectionTypeChange(); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 533 | static void NotifyObserversOfDNSChange(); |
pauljensen | 101ed37 | 2015-04-17 00:11:42 | [diff] [blame] | 534 | static void NotifyObserversOfInitialDNSConfigRead(); |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 535 | static void NotifyObserversOfNetworkChange(ConnectionType type); |
jkarlin | bce49186 | 2015-09-18 15:14:07 | [diff] [blame] | 536 | static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps, |
| 537 | ConnectionType type); |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 538 | static void NotifyObserversOfSpecificNetworkChange(NetworkChangeType type, |
| 539 | NetworkHandle network); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 540 | |
John Abd-El-Malek | 1842b8c | 2018-05-16 14:53:22 | [diff] [blame] | 541 | // Stores |config| in NetworkState and notifies observers. The first |
| 542 | // notification will be OnInitialDNSConfigRead, and after that OnDNSChanged. |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 543 | static void SetDnsConfig(const DnsConfig& config); |
John Abd-El-Malek | 1842b8c | 2018-05-16 14:53:22 | [diff] [blame] | 544 | |
| 545 | // Clears previous DnsConfig, if any, to simulate the first one being set. |
| 546 | static void ClearDnsConfigForTesting(); |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 547 | |
jkarlin | 013bc2a06 | 2017-05-09 19:05:05 | [diff] [blame] | 548 | // Infer connection type from |GetNetworkList|. If all network interfaces |
| 549 | // have the same type, return it, otherwise return CONNECTION_UNKNOWN. |
| 550 | static ConnectionType ConnectionTypeFromInterfaces(); |
| 551 | |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 552 | private: |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 553 | friend class HostResolverImplDnsTest; |
[email protected] | ab3309da | 2012-09-20 02:27:14 | [diff] [blame] | 554 | friend class NetworkChangeNotifierAndroidTest; |
[email protected] | ae66a48d | 2011-11-16 22:28:06 | [diff] [blame] | 555 | friend class NetworkChangeNotifierLinuxTest; |
[email protected] | aab6693 | 2011-10-05 17:08:13 | [diff] [blame] | 556 | friend class NetworkChangeNotifierWinTest; |
| 557 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 558 | class NetworkState; |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 559 | class NetworkChangeCalculator; |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 560 | |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 561 | void NotifyObserversOfIPAddressChangeImpl(); |
| 562 | void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); |
| 563 | void NotifyObserversOfDNSChangeImpl(); |
pauljensen | 101ed37 | 2015-04-17 00:11:42 | [diff] [blame] | 564 | void NotifyObserversOfInitialDNSConfigReadImpl(); |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 565 | void NotifyObserversOfNetworkChangeImpl(ConnectionType type); |
jkarlin | bce49186 | 2015-09-18 15:14:07 | [diff] [blame] | 566 | void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps, |
| 567 | ConnectionType type); |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 568 | void NotifyObserversOfSpecificNetworkChangeImpl(NetworkChangeType type, |
| 569 | NetworkHandle network); |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 570 | |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 571 | const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 572 | ip_address_observer_list_; |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 573 | const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 574 | connection_type_observer_list_; |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 575 | const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> |
[email protected] | 46018c9d | 2011-09-06 03:42:34 | [diff] [blame] | 576 | resolver_state_observer_list_; |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 577 | const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 578 | network_change_observer_list_; |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 579 | const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> |
jkarlin | 7b25e6c | 2014-12-16 19:59:47 | [diff] [blame] | 580 | max_bandwidth_observer_list_; |
pauljensen | be5bc323 | 2015-10-05 20:39:27 | [diff] [blame] | 581 | const scoped_refptr<base::ObserverListThreadSafe<NetworkObserver>> |
| 582 | network_observer_list_; |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 583 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 584 | // The current network state. Hosts DnsConfig, exposed via GetDnsConfig. |
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 585 | std::unique_ptr<NetworkState> network_state_; |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 586 | |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 587 | // Computes NetworkChange signal from IPAddress and ConnectionType signals. |
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 588 | std::unique_ptr<NetworkChangeCalculator> network_change_calculator_; |
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 589 | |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 590 | // Set true to disable non-test notifications (to prevent flakes in tests). |
jkarlin | e160f6b | 2015-07-31 17:04:08 | [diff] [blame] | 591 | static bool test_notifications_only_; |
[email protected] | 404f174 | 2014-06-23 13:30:11 | [diff] [blame] | 592 | |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 593 | DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
| 594 | }; |
| 595 | |
| 596 | } // namespace net |
| 597 | |
| 598 | #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |