summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorjkarlin <jkarlin@chromium.org>2015-09-18 08:14:07 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-18 15:14:46 +0000
commitbce491860ced584a398c76dca134ed350e879259 (patch)
tree6bb790ce0e6a72a77c9577eb043cc7fd2ffaafc5 /net
parent57388833dcb6bf4f472ff94bd2c224abe0529140 (diff)
downloadchromium_src-bce491860ced584a398c76dca134ed350e879259.zip
chromium_src-bce491860ced584a398c76dca134ed350e879259.tar.gz
chromium_src-bce491860ced584a398c76dca134ed350e879259.tar.bz2
This CL adds ConnectionType to the MaxBandwidthObserver notification as a convenience for its only client (in the downstream CL), NetInfo.
This CL also ensures that MaxBandwidthObserver is called on every platform when the network type changes. Upstream of https://codereview.chromium.org/1306423004/ BUG=412741 Review URL: https://codereview.chromium.org/1306653003 Cr-Commit-Position: refs/heads/master@{#349673}
Diffstat (limited to 'net')
-rw-r--r--net/android/network_change_notifier_android.cc14
-rw-r--r--net/android/network_change_notifier_android.h7
-rw-r--r--net/android/network_change_notifier_android_unittest.cc22
-rw-r--r--net/android/network_change_notifier_delegate_android.cc12
-rw-r--r--net/android/network_change_notifier_delegate_android.h7
-rw-r--r--net/base/network_change_notifier.cc47
-rw-r--r--net/base/network_change_notifier.h48
-rw-r--r--net/base/network_change_notifier_linux.cc5
-rw-r--r--net/base/network_change_notifier_mac.cc7
-rw-r--r--net/base/network_change_notifier_unittest.cc6
-rw-r--r--net/base/network_change_notifier_win.cc5
11 files changed, 126 insertions, 54 deletions
diff --git a/net/android/network_change_notifier_android.cc b/net/android/network_change_notifier_android.cc
index 9829235..a967b85 100644
--- a/net/android/network_change_notifier_android.cc
+++ b/net/android/network_change_notifier_android.cc
@@ -144,8 +144,11 @@ NetworkChangeNotifierAndroid::GetCurrentConnectionType() const {
return delegate_->GetCurrentConnectionType();
}
-double NetworkChangeNotifierAndroid::GetCurrentMaxBandwidth() const {
- return delegate_->GetCurrentMaxBandwidth();
+void NetworkChangeNotifierAndroid::GetCurrentMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) const {
+ delegate_->GetCurrentMaxBandwidthAndConnectionType(max_bandwidth_mbps,
+ connection_type);
}
void NetworkChangeNotifierAndroid::OnConnectionTypeChanged() {
@@ -153,9 +156,10 @@ void NetworkChangeNotifierAndroid::OnConnectionTypeChanged() {
}
void NetworkChangeNotifierAndroid::OnMaxBandwidthChanged(
- double max_bandwidth_mbps) {
- NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
- max_bandwidth_mbps);
+ double max_bandwidth_mbps,
+ ConnectionType type) {
+ NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(max_bandwidth_mbps,
+ type);
}
// static
diff --git a/net/android/network_change_notifier_android.h b/net/android/network_change_notifier_android.h
index 1acb840..61bec53 100644
--- a/net/android/network_change_notifier_android.h
+++ b/net/android/network_change_notifier_android.h
@@ -49,11 +49,14 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierAndroid
ConnectionType GetCurrentConnectionType() const override;
// Requires ACCESS_WIFI_STATE permission in order to provide precise WiFi link
// speed.
- double GetCurrentMaxBandwidth() const override;
+ void GetCurrentMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) const override;
// NetworkChangeNotifierDelegateAndroid::Observer:
void OnConnectionTypeChanged() override;
- void OnMaxBandwidthChanged(double max_bandwidth_mbps) override;
+ void OnMaxBandwidthChanged(double max_bandwidth_mbps,
+ ConnectionType type) override;
static bool Register(JNIEnv* env);
diff --git a/net/android/network_change_notifier_android_unittest.cc b/net/android/network_change_notifier_android_unittest.cc
index 933e0a3..d3fe04d 100644
--- a/net/android/network_change_notifier_android_unittest.cc
+++ b/net/android/network_change_notifier_android_unittest.cc
@@ -28,7 +28,9 @@ class NetworkChangeNotifierDelegateAndroidObserver
// NetworkChangeNotifierDelegateAndroid::Observer:
void OnConnectionTypeChanged() override { type_notifications_count_++; }
- void OnMaxBandwidthChanged(double max_bandwidth_mbps) override {
+ void OnMaxBandwidthChanged(
+ double max_bandwidth_mbps,
+ net::NetworkChangeNotifier::ConnectionType type) override {
max_bandwidth_notifications_count_++;
}
@@ -248,14 +250,18 @@ TEST_F(NetworkChangeNotifierAndroidTest,
TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) {
SetOnline();
- EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN,
- notifier_->GetConnectionType());
- EXPECT_EQ(std::numeric_limits<double>::infinity(),
- notifier_->GetMaxBandwidth());
+ double max_bandwidth_mbps = 0.0;
+ NetworkChangeNotifier::ConnectionType connection_type =
+ NetworkChangeNotifier::CONNECTION_NONE;
+ notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps,
+ &connection_type);
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, connection_type);
+ EXPECT_EQ(std::numeric_limits<double>::infinity(), max_bandwidth_mbps);
SetOffline();
- EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
- notifier_->GetConnectionType());
- EXPECT_EQ(0.0, notifier_->GetMaxBandwidth());
+ notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps,
+ &connection_type);
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, connection_type);
+ EXPECT_EQ(0.0, max_bandwidth_mbps);
}
TEST_F(NetworkChangeNotifierDelegateAndroidTest,
diff --git a/net/android/network_change_notifier_delegate_android.cc b/net/android/network_change_notifier_delegate_android.cc
index ec8a729..be4c6b1 100644
--- a/net/android/network_change_notifier_delegate_android.cc
+++ b/net/android/network_change_notifier_delegate_android.cc
@@ -84,9 +84,13 @@ NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType() const {
return connection_type_;
}
-double NetworkChangeNotifierDelegateAndroid::GetCurrentMaxBandwidth() const {
+void NetworkChangeNotifierDelegateAndroid::
+ GetCurrentMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) const {
base::AutoLock auto_lock(connection_lock_);
- return connection_max_bandwidth_;
+ *connection_type = connection_type_;
+ *max_bandwidth_mbps = connection_max_bandwidth_;
}
void NetworkChangeNotifierDelegateAndroid::NotifyConnectionTypeChanged(
@@ -111,10 +115,10 @@ void NetworkChangeNotifierDelegateAndroid::NotifyMaxBandwidthChanged(
jobject obj,
jdouble new_max_bandwidth) {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(new_max_bandwidth != GetCurrentMaxBandwidth());
+
SetCurrentMaxBandwidth(new_max_bandwidth);
observers_->Notify(FROM_HERE, &Observer::OnMaxBandwidthChanged,
- new_max_bandwidth);
+ new_max_bandwidth, GetCurrentConnectionType());
}
void NetworkChangeNotifierDelegateAndroid::AddObserver(
diff --git a/net/android/network_change_notifier_delegate_android.h b/net/android/network_change_notifier_delegate_android.h
index 93133f3..e1f874a 100644
--- a/net/android/network_change_notifier_delegate_android.h
+++ b/net/android/network_change_notifier_delegate_android.h
@@ -35,7 +35,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid {
virtual void OnConnectionTypeChanged() = 0;
// Updates the current max bandwidth.
- virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0;
+ virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps,
+ ConnectionType connection_type) = 0;
};
NetworkChangeNotifierDelegateAndroid();
@@ -67,7 +68,9 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid {
ConnectionType GetCurrentConnectionType() const;
// Can be called from any thread.
- double GetCurrentMaxBandwidth() const;
+ void GetCurrentMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) const;
// Initializes JNI bindings.
static bool Register(JNIEnv* env);
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc
index 03502f6..2c9737b 100644
--- a/net/base/network_change_notifier.cc
+++ b/net/base/network_change_notifier.cc
@@ -542,10 +542,17 @@ NetworkChangeNotifier::GetConnectionType() {
}
// static
-double NetworkChangeNotifier::GetMaxBandwidth() {
- return g_network_change_notifier ?
- g_network_change_notifier->GetCurrentMaxBandwidth() :
- std::numeric_limits<double>::infinity();
+void NetworkChangeNotifier::GetMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) {
+ if (!g_network_change_notifier) {
+ *connection_type = CONNECTION_UNKNOWN;
+ *max_bandwidth_mbps = GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN);
+ return;
+ }
+
+ g_network_change_notifier->GetCurrentMaxBandwidthAndConnectionType(
+ max_bandwidth_mbps, connection_type);
}
// static
@@ -792,6 +799,16 @@ void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() {
}
// static
+void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeForTests(
+ double max_bandwidth_mbps,
+ ConnectionType type) {
+ if (g_network_change_notifier) {
+ g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl(
+ max_bandwidth_mbps, type);
+ }
+}
+
+// static
void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) {
DCHECK(!g_network_change_notifier);
NetworkChangeNotifier::test_notifications_only_ = test_only;
@@ -830,13 +847,17 @@ NetworkChangeNotifier::GetAddressTrackerInternal() const {
}
#endif
-double NetworkChangeNotifier::GetCurrentMaxBandwidth() const {
+void NetworkChangeNotifier::GetCurrentMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) const {
// This default implementation conforms to the NetInfo V3 specification but
// should be overridden to provide specific bandwidth data based on the
// platform.
- if (GetCurrentConnectionType() == CONNECTION_NONE)
- return 0.0;
- return std::numeric_limits<double>::infinity();
+ *connection_type = GetCurrentConnectionType();
+ *max_bandwidth_mbps =
+ *connection_type == CONNECTION_NONE
+ ? GetMaxBandwidthForConnectionSubtype(SUBTYPE_NONE)
+ : GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN);
}
// static
@@ -942,11 +963,12 @@ void NetworkChangeNotifier::NotifyObserversOfNetworkChange(
// static
void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
- double max_bandwidth_mbps) {
+ double max_bandwidth_mbps,
+ ConnectionType type) {
if (g_network_change_notifier &&
!NetworkChangeNotifier::test_notifications_only_) {
g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl(
- max_bandwidth_mbps);
+ max_bandwidth_mbps, type);
}
}
@@ -1015,10 +1037,11 @@ void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() {
}
void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl(
- double max_bandwidth_mbps) {
+ double max_bandwidth_mbps,
+ ConnectionType type) {
max_bandwidth_observer_list_->Notify(
FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged,
- max_bandwidth_mbps);
+ max_bandwidth_mbps, type);
}
NetworkChangeNotifier::DisableForTest::DisableForTest()
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index abced48..873cd12 100644
--- a/net/base/network_change_notifier.h
+++ b/net/base/network_change_notifier.h
@@ -186,14 +186,13 @@ class NET_EXPORT NetworkChangeNotifier {
class NET_EXPORT MaxBandwidthObserver {
public:
- // Will be called when a change occurs to the network's maximum bandwidth as
- // defined in http://w3c.github.io/netinfo/. Generally this will only be
- // called on bandwidth changing network connection/disconnection events.
- // Some platforms may call it more frequently, such as when WiFi signal
- // strength changes.
- // TODO(jkarlin): This is currently only implemented for Android. Implement
- // on every platform.
- virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0;
+ // Called when a change occurs to the network's maximum bandwidth as
+ // defined in http://w3c.github.io/netinfo/. Also called on type change,
+ // even if the maximum bandwidth doesn't change. See the documentation of
+ // GetMaxBanwidthAndConnectionType for what to expect for the values of
+ // |max_bandwidth_mbps|.
+ virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps,
+ ConnectionType type) = 0;
protected:
MaxBandwidthObserver() {}
@@ -234,13 +233,19 @@ class NET_EXPORT NetworkChangeNotifier {
// the internet, the connection type is CONNECTION_WIFI.
static ConnectionType GetConnectionType();
- // Returns a theoretical upper limit on download bandwidth, potentially based
- // on underlying connection type, signal strength, or some other signal. The
- // default mapping of connection type to maximum bandwidth is provided in the
- // NetInfo spec: http://w3c.github.io/netinfo/. Host-specific application
- // permissions may be required, please see host-specific declaration for more
- // information.
- static double GetMaxBandwidth();
+ // Sets |max_bandwidth_mbps| to a theoretical upper limit on download
+ // bandwidth, potentially based on underlying connection type, signal
+ // strength, or some other signal. If the network subtype is unknown then
+ // |max_bandwidth_mbps| is set to +Infinity and if there is no network
+ // connection then it is set to 0.0. The circumstances in which a more
+ // specific value is given are: when an Android device is connected to a
+ // cellular or WiFi network, and when a ChromeOS device is connected to a
+ // cellular network. See the NetInfo spec for the mapping of
+ // specific subtypes to bandwidth values: http://w3c.github.io/netinfo/.
+ // |connection_type| is set to the current active default network's connection
+ // type.
+ static void GetMaxBandwidthAndConnectionType(double* max_bandwidth_mbps,
+ ConnectionType* connection_type);
// Retrieve the last read DnsConfig. This could be expensive if the system has
// a large HOSTS file.
@@ -309,6 +314,9 @@ class NET_EXPORT NetworkChangeNotifier {
ConnectionType type);
static void NotifyObserversOfNetworkChangeForTests(ConnectionType type);
static void NotifyObserversOfInitialDNSConfigReadForTests();
+ static void NotifyObserversOfMaxBandwidthChangeForTests(
+ double max_bandwidth_mbps,
+ ConnectionType type);
// Enable or disable notifications from the host. After setting to true, be
// sure to pump the RunLoop until idle to finish any preexisting
@@ -392,7 +400,9 @@ class NET_EXPORT NetworkChangeNotifier {
// See the description of NetworkChangeNotifier::GetMaxBandwidth().
// Implementations must be thread-safe. Implementations must also be
// cheap as it is called often.
- virtual double GetCurrentMaxBandwidth() const;
+ virtual void GetCurrentMaxBandwidthAndConnectionType(
+ double* max_bandwidth_mbps,
+ ConnectionType* connection_type) const;
// Returns a theoretical upper limit on download bandwidth given a connection
// subtype. The mapping of connection type to maximum bandwidth is provided in
@@ -407,7 +417,8 @@ class NET_EXPORT NetworkChangeNotifier {
static void NotifyObserversOfDNSChange();
static void NotifyObserversOfInitialDNSConfigRead();
static void NotifyObserversOfNetworkChange(ConnectionType type);
- static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps);
+ static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps,
+ ConnectionType type);
// Stores |config| in NetworkState and notifies OnDNSChanged observers.
static void SetDnsConfig(const DnsConfig& config);
@@ -429,7 +440,8 @@ class NET_EXPORT NetworkChangeNotifier {
void NotifyObserversOfDNSChangeImpl();
void NotifyObserversOfInitialDNSConfigReadImpl();
void NotifyObserversOfNetworkChangeImpl(ConnectionType type);
- void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps);
+ void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps,
+ ConnectionType type);
const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>>
ip_address_observer_list_;
diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc
index 7e47172..4009967 100644
--- a/net/base/network_change_notifier_linux.cc
+++ b/net/base/network_change_notifier_linux.cc
@@ -82,6 +82,11 @@ void NetworkChangeNotifierLinux::Thread::OnLinkChanged() {
if (last_type_ != GetCurrentConnectionType()) {
NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange();
last_type_ = GetCurrentConnectionType();
+ double max_bandwidth_mbps =
+ NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype(
+ last_type_ == CONNECTION_NONE ? SUBTYPE_NONE : SUBTYPE_UNKNOWN);
+ NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
+ max_bandwidth_mbps, last_type_);
}
}
diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc
index f8caee8..4468c0b 100644
--- a/net/base/network_change_notifier_mac.cc
+++ b/net/base/network_change_notifier_mac.cc
@@ -257,8 +257,13 @@ void NetworkChangeNotifierMac::ReachabilityCallback(
old_type = notifier_mac->connection_type_;
notifier_mac->connection_type_ = new_type;
}
- if (old_type != new_type)
+ if (old_type != new_type) {
NotifyObserversOfConnectionTypeChange();
+ double max_bandwidth_mbps =
+ NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype(
+ new_type == CONNECTION_NONE ? SUBTYPE_NONE : SUBTYPE_UNKNOWN);
+ NotifyObserversOfMaxBandwidthChange(max_bandwidth_mbps, new_type);
+ }
#if defined(OS_IOS)
// On iOS, the SCDynamicStore API does not exist, and we use the reachability
diff --git a/net/base/network_change_notifier_unittest.cc b/net/base/network_change_notifier_unittest.cc
index 7bc2ba6..67426078 100644
--- a/net/base/network_change_notifier_unittest.cc
+++ b/net/base/network_change_notifier_unittest.cc
@@ -14,8 +14,10 @@ namespace net {
// alter the ranges of these tests.
TEST(NetworkChangeNotifierTest, NetMaxBandwidthRange) {
NetworkChangeNotifier::ConnectionType connection_type =
- NetworkChangeNotifier::GetConnectionType();
- double max_bandwidth = NetworkChangeNotifier::GetMaxBandwidth();
+ NetworkChangeNotifier::CONNECTION_NONE;
+ double max_bandwidth = 0.0;
+ NetworkChangeNotifier::GetMaxBandwidthAndConnectionType(&max_bandwidth,
+ &connection_type);
// Always accept infinity as it's the default value if the bandwidth is
// unknown.
diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc
index e893329..27f230f 100644
--- a/net/base/network_change_notifier_win.cc
+++ b/net/base/network_change_notifier_win.cc
@@ -318,6 +318,11 @@ void NetworkChangeNotifierWin::NotifyParentOfConnectionTypeChange() {
last_announced_offline_ = current_offline;
NotifyObserversOfConnectionTypeChange();
+ double max_bandwidth_mbps = 0.0;
+ ConnectionType connection_type = CONNECTION_NONE;
+ GetCurrentMaxBandwidthAndConnectionType(&max_bandwidth_mbps,
+ &connection_type);
+ NotifyObserversOfMaxBandwidthChange(max_bandwidth_mbps, connection_type);
}
} // namespace net