summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc34
-rw-r--r--chrome/browser/chromeos/net/network_change_notifier_chromeos.cc11
-rw-r--r--chrome/browser/chromeos/net/network_change_notifier_chromeos.h3
-rw-r--r--chrome/browser/chromeos/offline/offline_load_page.cc12
-rw-r--r--chrome/browser/chromeos/offline/offline_load_page.h10
-rw-r--r--chrome/browser/chromeos/web_socket_proxy_controller.cc11
-rw-r--r--chrome/browser/sessions/session_restore.cc16
-rw-r--r--content/browser/net/browser_online_state_observer.cc12
-rw-r--r--content/browser/net/browser_online_state_observer.h9
-rw-r--r--content/browser/ppapi_plugin_process_host.cc16
-rw-r--r--net/android/network_change_notifier_android.cc12
-rw-r--r--net/android/network_change_notifier_android.h3
-rw-r--r--net/base/network_change_notifier.cc38
-rw-r--r--net/base/network_change_notifier.h56
-rw-r--r--net/base/network_change_notifier_linux.cc26
-rw-r--r--net/base/network_change_notifier_linux.h2
-rw-r--r--net/base/network_change_notifier_linux_unittest.cc54
-rw-r--r--net/base/network_change_notifier_mac.cc49
-rw-r--r--net/base/network_change_notifier_mac.h22
-rw-r--r--net/base/network_change_notifier_win.cc25
-rw-r--r--net/base/network_change_notifier_win.h6
-rw-r--r--net/base/network_change_notifier_win_unittest.cc7
-rw-r--r--net/url_request/url_request_throttler_manager.cc9
-rw-r--r--net/url_request/url_request_throttler_manager.h7
-rw-r--r--net/url_request/url_request_throttler_unittest.cc6
-rw-r--r--remoting/host/signaling_connector.cc9
-rw-r--r--remoting/host/signaling_connector.h9
27 files changed, 280 insertions, 194 deletions
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 61f9b28..52ffb3c 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -535,11 +535,12 @@ class JobRestartRequest
base::OneShotTimer<JobRestartRequest> timer_;
};
-class LoginUtilsImpl : public LoginUtils,
- public GaiaOAuthConsumer,
- public OAuthLoginVerifier::Delegate,
- public net::NetworkChangeNotifier::OnlineStateObserver,
- public base::SupportsWeakPtr<LoginUtilsImpl> {
+class LoginUtilsImpl
+ : public LoginUtils,
+ public GaiaOAuthConsumer,
+ public OAuthLoginVerifier::Delegate,
+ public net::NetworkChangeNotifier::ConnectionTypeObserver,
+ public base::SupportsWeakPtr<LoginUtilsImpl> {
public:
LoginUtilsImpl()
: pending_requests_(false),
@@ -548,11 +549,11 @@ class LoginUtilsImpl : public LoginUtils,
delegate_(NULL),
job_restart_request_(NULL),
should_restore_auth_session_(false) {
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
}
virtual ~LoginUtilsImpl() {
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
}
// LoginUtils implementation:
@@ -599,8 +600,9 @@ class LoginUtilsImpl : public LoginUtils,
const std::string& auth) OVERRIDE;
virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE;
- // net::NetworkChangeNotifier::OnlineStateObserver overrides.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE;
+ // net::NetworkChangeNotifier::ConnectionTypeObserver overrides.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
// Given the authenticated credentials from the cookie jar, try to exchange
// fetch OAuth request, v1 and v2 tokens.
@@ -1230,10 +1232,10 @@ void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) {
should_restore_auth_session_ = false;
KickStartAuthentication(user_profile);
} else {
- // Even if we're online we should wait till initial OnOnlineStateChanged()
- // call. Otherwise starting fetchers too early may end up cancelling
- // all request when initial network state is processed.
- // See http://crbug.com/121643.
+ // Even if we're online we should wait till initial
+ // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may
+ // end up cancelling all request when initial network connection type is
+ // processed. See http://crbug.com/121643.
should_restore_auth_session_ = true;
}
}
@@ -1421,8 +1423,10 @@ void LoginUtilsImpl::OnOAuthVerificationSucceeded(
}
-void LoginUtilsImpl::OnOnlineStateChanged(bool online) {
- if (online && UserManager::Get()->IsUserLoggedIn()) {
+void LoginUtilsImpl::OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) {
+ if (type != net::NetworkChangeNotifier::CONNECTION_NONE &&
+ UserManager::Get()->IsUserLoggedIn()) {
if (oauth_login_verifier_.get() &&
!oauth_login_verifier_->is_done()) {
// If we come online for the first time after successful offline login,
diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
index 1f93afd..53786a7 100644
--- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
+++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
@@ -83,8 +83,12 @@ void NetworkChangeNotifierChromeos::OnNetworkManagerChanged(
UpdateNetworkState(cros);
}
-bool NetworkChangeNotifierChromeos::IsCurrentlyOffline() const {
- return !IsOnline(connection_state_);
+net::NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierChromeos::GetCurrentConnectionType() const {
+ // TODO(droger): Return something more detailed than CONNECTION_UNKNOWN.
+ return IsOnline(connection_state_) ?
+ net::NetworkChangeNotifier::CONNECTION_UNKNOWN :
+ net::NetworkChangeNotifier::CONNECTION_NONE;
}
void NetworkChangeNotifierChromeos::OnNetworkChanged(
@@ -205,7 +209,8 @@ void NetworkChangeNotifierChromeos::ReportOnlineStateChangeOnUIThread() {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
- &NetworkChangeNotifierChromeos::NotifyObserversOfOnlineStateChange));
+ &NetworkChangeNotifierChromeos::
+ NotifyObserversOfConnectionTypeChange));
}
// static
diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.h b/chrome/browser/chromeos/net/network_change_notifier_chromeos.h
index b63de8c..8f070df 100644
--- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.h
+++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.h
@@ -43,7 +43,8 @@ class NetworkChangeNotifierChromeos
virtual void SystemResumed() OVERRIDE;
// NetworkChangeNotifier overrides.
- virtual bool IsCurrentlyOffline() const OVERRIDE;
+ virtual net::NetworkChangeNotifier::ConnectionType
+ GetCurrentConnectionType() const OVERRIDE;
// NetworkManagerObserver overrides:
virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj) OVERRIDE;
diff --git a/chrome/browser/chromeos/offline/offline_load_page.cc b/chrome/browser/chromeos/offline/offline_load_page.cc
index 230526b..59bcf8e 100644
--- a/chrome/browser/chromeos/offline/offline_load_page.cc
+++ b/chrome/browser/chromeos/offline/offline_load_page.cc
@@ -60,13 +60,13 @@ OfflineLoadPage::OfflineLoadPage(WebContents* web_contents,
proceeded_(false),
web_contents_(web_contents),
url_(url) {
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
interstitial_page_ = InterstitialPage::Create(web_contents, true, url, this);
}
OfflineLoadPage::~OfflineLoadPage() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
}
void OfflineLoadPage::Show() {
@@ -200,12 +200,14 @@ void OfflineLoadPage::NotifyBlockingPageComplete(bool proceed) {
BrowserThread::IO, FROM_HERE, base::Bind(callback_, proceed));
}
-void OfflineLoadPage::OnOnlineStateChanged(bool online) {
+void OfflineLoadPage::OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DVLOG(1) << "OnlineStateObserver notification received: state="
+ const bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE;
+ DVLOG(1) << "ConnectionTypeObserver notification received: state="
<< (online ? "online" : "offline");
if (online) {
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
interstitial_page_->Proceed();
}
}
diff --git a/chrome/browser/chromeos/offline/offline_load_page.h b/chrome/browser/chromeos/offline/offline_load_page.h
index 52fab74..0551287 100644
--- a/chrome/browser/chromeos/offline/offline_load_page.h
+++ b/chrome/browser/chromeos/offline/offline_load_page.h
@@ -33,8 +33,9 @@ namespace chromeos {
// when no network is available and hides when some network (either
// one of wifi, 3g or ethernet) becomes available.
// It deletes itself when the interstitial page is closed.
-class OfflineLoadPage : public content::InterstitialPageDelegate,
- public net::NetworkChangeNotifier::OnlineStateObserver {
+class OfflineLoadPage
+ : public content::InterstitialPageDelegate,
+ public net::NetworkChangeNotifier::ConnectionTypeObserver {
public:
// Passed a boolean indicating whether or not it is OK to proceed with the
// page load.
@@ -64,8 +65,9 @@ class OfflineLoadPage : public content::InterstitialPageDelegate,
virtual void OnProceed() OVERRIDE;
virtual void OnDontProceed() OVERRIDE;
- // net::NetworkChangeNotifier::OnlineStateObserver overrides.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE;
+ // net::NetworkChangeNotifier::ConnectionTypeObserver overrides.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
// Retrieves template strings of the offline page for app and
// normal site.
diff --git a/chrome/browser/chromeos/web_socket_proxy_controller.cc b/chrome/browser/chromeos/web_socket_proxy_controller.cc
index d356ff9..3e67336 100644
--- a/chrome/browser/chromeos/web_socket_proxy_controller.cc
+++ b/chrome/browser/chromeos/web_socket_proxy_controller.cc
@@ -33,7 +33,7 @@
namespace {
class ProxyLifetime
- : public net::NetworkChangeNotifier::OnlineStateObserver,
+ : public net::NetworkChangeNotifier::ConnectionTypeObserver,
public content::NotificationObserver {
public:
ProxyLifetime()
@@ -47,14 +47,14 @@ class ProxyLifetime
web_socket_proxy_thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&ProxyLifetime::ProxyCallback, base::Unretained(this)));
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
registrar_.Add(
this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED,
content::NotificationService::AllSources());
}
virtual ~ProxyLifetime() {
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
}
virtual void Observe(int type, const content::NotificationSource& source,
@@ -69,8 +69,9 @@ class ProxyLifetime
}
private:
- // net::NetworkChangeNotifier::OnlineStateObserver implementation.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE {
+ // net::NetworkChangeNotifier::ConnectionTypeObserver implementation.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
DCHECK(chromeos::WebSocketProxyController::IsInitiated());
base::AutoLock alk(lock_);
if (server_)
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc
index ffea378..bb6cbbe 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -80,7 +80,7 @@ static const int kInitialDelayTimerMS = 100;
// This is not part of SessionRestoreImpl so that synchronous destruction
// of SessionRestoreImpl doesn't have timing problems.
class TabLoader : public content::NotificationObserver,
- public net::NetworkChangeNotifier::OnlineStateObserver,
+ public net::NetworkChangeNotifier::ConnectionTypeObserver,
public base::RefCounted<TabLoader> {
public:
// Retrieves a pointer to the TabLoader instance shared between profiles, or
@@ -120,8 +120,9 @@ class TabLoader : public content::NotificationObserver,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // net::NetworkChangeNotifier::OnlineStateObserver overrides.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE;
+ // net::NetworkChangeNotifier::ConnectionTypeObserver overrides.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
// Removes the listeners from the specified tab and removes the tab from
// the set of tabs to load and list of tabs we're waiting to get a load
@@ -226,7 +227,7 @@ void TabLoader::StartLoading() {
loading_ = true;
LoadNextTab();
} else {
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
}
#else
loading_ = true;
@@ -246,7 +247,7 @@ TabLoader::TabLoader(base::TimeTicks restore_started)
TabLoader::~TabLoader() {
DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) &&
tabs_loading_.empty() && tabs_to_load_.empty());
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
shared_tab_loader = NULL;
}
@@ -369,8 +370,9 @@ void TabLoader::Observe(int type,
this_retainer_ = NULL;
}
-void TabLoader::OnOnlineStateChanged(bool online) {
- if (online) {
+void TabLoader::OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) {
+ if (type != net::NetworkChangeNotifier::CONNECTION_NONE) {
if (!loading_) {
loading_ = true;
LoadNextTab();
diff --git a/content/browser/net/browser_online_state_observer.cc b/content/browser/net/browser_online_state_observer.cc
index 57f3d15..b6ce8ef 100644
--- a/content/browser/net/browser_online_state_observer.cc
+++ b/content/browser/net/browser_online_state_observer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,17 +8,19 @@
#include "content/browser/renderer_host/render_process_host_impl.h"
BrowserOnlineStateObserver::BrowserOnlineStateObserver() {
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
}
BrowserOnlineStateObserver::~BrowserOnlineStateObserver() {
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
}
-void BrowserOnlineStateObserver::OnOnlineStateChanged(bool online) {
+void BrowserOnlineStateObserver::OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) {
for (content::RenderProcessHost::iterator it(
content::RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
- it.GetCurrentValue()->Send(new ViewMsg_NetworkStateChanged(online));
+ it.GetCurrentValue()->Send(new ViewMsg_NetworkStateChanged(
+ type != net::NetworkChangeNotifier::CONNECTION_NONE));
}
}
diff --git a/content/browser/net/browser_online_state_observer.h b/content/browser/net/browser_online_state_observer.h
index 776d11d..5bf9b98 100644
--- a/content/browser/net/browser_online_state_observer.h
+++ b/content/browser/net/browser_online_state_observer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,13 +12,14 @@
// Listens for changes to the online state and manages sending
// updates to each RenderProcess via RenderProcessHost IPC.
class BrowserOnlineStateObserver
- : public net::NetworkChangeNotifier::OnlineStateObserver {
+ : public net::NetworkChangeNotifier::ConnectionTypeObserver {
public:
BrowserOnlineStateObserver();
virtual ~BrowserOnlineStateObserver();
- // OnlineStateObserver implementation.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE;
+ // ConnectionTypeObserver implementation.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserOnlineStateObserver);
diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc
index d774718..3bffd15 100644
--- a/content/browser/ppapi_plugin_process_host.cc
+++ b/content/browser/ppapi_plugin_process_host.cc
@@ -29,16 +29,16 @@ using content::ChildProcessHostImpl;
class PpapiPluginProcessHost::PluginNetworkObserver
: public net::NetworkChangeNotifier::IPAddressObserver,
- public net::NetworkChangeNotifier::OnlineStateObserver {
+ public net::NetworkChangeNotifier::ConnectionTypeObserver {
public:
explicit PluginNetworkObserver(PpapiPluginProcessHost* process_host)
: process_host_(process_host) {
net::NetworkChangeNotifier::AddIPAddressObserver(this);
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
}
~PluginNetworkObserver() {
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
@@ -49,13 +49,15 @@ class PpapiPluginProcessHost::PluginNetworkObserver
// when I unplug and replug my network cable. Sending this notification when
// "something" changes seems to make Flash reasonably happy, but seems
// wrong. We should really be able to provide the real online state in
- // OnOnlineStateChanged().
+ // OnConnectionTypeChanged().
process_host_->Send(new PpapiMsg_SetNetworkState(true));
}
- // OnlineStateObserver implementation.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE {
- process_host_->Send(new PpapiMsg_SetNetworkState(online));
+ // ConnectionTypeObserver implementation.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) {
+ process_host_->Send(new PpapiMsg_SetNetworkState(
+ type != net::NetworkChangeNotifier::CONNECTION_NONE));
}
private:
diff --git a/net/android/network_change_notifier_android.cc b/net/android/network_change_notifier_android.cc
index e1cea06..d810a33 100644
--- a/net/android/network_change_notifier_android.cc
+++ b/net/android/network_change_notifier_android.cc
@@ -31,13 +31,17 @@ void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) {
}
void NetworkChangeNotifier::NotifyObservers(JNIEnv* env, jobject obj) {
- NotifyObserversOfOnlineStateChange();
+ NotifyObserversOfConnectionTypeChange();
}
-bool NetworkChangeNotifier::IsCurrentlyOffline() const {
+net::NetworkChangeNotifier::ConnectionType
+ NetworkChangeNotifier::GetCurrentConnectionType() const {
JNIEnv* env = base::android::AttachCurrentThread();
- return !Java_NetworkChangeNotifier_isConnected(
- env, java_network_change_notifier_.obj());
+ // TODO(droger): Return something more detailed than CONNECTION_UNKNOWN.
+ return Java_NetworkChangeNotifier_isConnected(
+ env, java_network_change_notifier_.obj()) ?
+ net::NetworkChangeNotifier::CONNECTION_UNKNOWN :
+ net::NetworkChangeNotifier::CONNECTION_NONE;
}
// static
diff --git a/net/android/network_change_notifier_android.h b/net/android/network_change_notifier_android.h
index f73168a..c16a7ff 100644
--- a/net/android/network_change_notifier_android.h
+++ b/net/android/network_change_notifier_android.h
@@ -27,7 +27,8 @@ class NetworkChangeNotifier : public net::NetworkChangeNotifier {
void CreateJavaObject(JNIEnv* env);
// NetworkChangeNotifier:
- virtual bool IsCurrentlyOffline() const OVERRIDE;
+ virtual net::NetworkChangeNotifier::ConnectionType
+ GetCurrentConnectionType() const OVERRIDE;
base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_;
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc
index 7a14d0e..7f5d901 100644
--- a/net/base/network_change_notifier.cc
+++ b/net/base/network_change_notifier.cc
@@ -28,7 +28,9 @@ NetworkChangeNotifierFactory* g_network_change_notifier_factory = NULL;
class MockNetworkChangeNotifier : public NetworkChangeNotifier {
public:
- virtual bool IsCurrentlyOffline() const { return false; }
+ virtual ConnectionType GetCurrentConnectionType() const {
+ return CONNECTION_UNKNOWN;
+ }
};
} // namespace
@@ -75,9 +77,11 @@ NetworkChangeNotifier* NetworkChangeNotifier::Create() {
}
// static
-bool NetworkChangeNotifier::IsOffline() {
- return g_network_change_notifier &&
- g_network_change_notifier->IsCurrentlyOffline();
+NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifier::GetConnectionType() {
+ return g_network_change_notifier ?
+ g_network_change_notifier->GetCurrentConnectionType() :
+ CONNECTION_UNKNOWN;
}
// static
@@ -98,10 +102,10 @@ void NetworkChangeNotifier::AddIPAddressObserver(IPAddressObserver* observer) {
g_network_change_notifier->ip_address_observer_list_->AddObserver(observer);
}
-void NetworkChangeNotifier::AddOnlineStateObserver(
- OnlineStateObserver* observer) {
+void NetworkChangeNotifier::AddConnectionTypeObserver(
+ ConnectionTypeObserver* observer) {
if (g_network_change_notifier) {
- g_network_change_notifier->online_state_observer_list_->AddObserver(
+ g_network_change_notifier->connection_type_observer_list_->AddObserver(
observer);
}
}
@@ -121,10 +125,10 @@ void NetworkChangeNotifier::RemoveIPAddressObserver(
}
}
-void NetworkChangeNotifier::RemoveOnlineStateObserver(
- OnlineStateObserver* observer) {
+void NetworkChangeNotifier::RemoveConnectionTypeObserver(
+ ConnectionTypeObserver* observer) {
if (g_network_change_notifier) {
- g_network_change_notifier->online_state_observer_list_->RemoveObserver(
+ g_network_change_notifier->connection_type_observer_list_->RemoveObserver(
observer);
}
}
@@ -140,9 +144,9 @@ NetworkChangeNotifier::NetworkChangeNotifier()
: ip_address_observer_list_(
new ObserverListThreadSafe<IPAddressObserver>(
ObserverListBase<IPAddressObserver>::NOTIFY_EXISTING_ONLY)),
- online_state_observer_list_(
- new ObserverListThreadSafe<OnlineStateObserver>(
- ObserverListBase<OnlineStateObserver>::NOTIFY_EXISTING_ONLY)),
+ connection_type_observer_list_(
+ new ObserverListThreadSafe<ConnectionTypeObserver>(
+ ObserverListBase<ConnectionTypeObserver>::NOTIFY_EXISTING_ONLY)),
resolver_state_observer_list_(
new ObserverListThreadSafe<DNSObserver>(
ObserverListBase<DNSObserver>::NOTIFY_EXISTING_ONLY)),
@@ -180,11 +184,11 @@ void NetworkChangeNotifier::NotifyObserversOfDNSChange(unsigned detail) {
}
}
-// static
-void NetworkChangeNotifier::NotifyObserversOfOnlineStateChange() {
+void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() {
if (g_network_change_notifier) {
- g_network_change_notifier->online_state_observer_list_->Notify(
- &OnlineStateObserver::OnOnlineStateChanged, !IsOffline());
+ g_network_change_notifier->connection_type_observer_list_->Notify(
+ &ConnectionTypeObserver::OnConnectionTypeChanged,
+ GetConnectionType());
}
}
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index 477d1f7..20ee6eb 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_;
diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc
index 679593e..b7acd46 100644
--- a/net/base/network_change_notifier_linux.cc
+++ b/net/base/network_change_notifier_linux.cc
@@ -83,9 +83,9 @@ class NetworkManagerApi {
// Must be called by the helper thread's CleanUp() method.
void CleanUp();
- // Implementation of NetworkChangeNotifierLinux::IsCurrentlyOffline().
+ // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType().
// Safe to call from any thread, but will block until Init() has completed.
- bool IsCurrentlyOffline();
+ NetworkChangeNotifier::ConnectionType GetCurrentConnectionType();
private:
// Callbacks for D-Bus API.
@@ -232,12 +232,15 @@ bool NetworkManagerApi::StateIsOffline(uint32 state) {
}
}
-bool NetworkManagerApi::IsCurrentlyOffline() {
+NetworkChangeNotifier::ConnectionType
+NetworkManagerApi::GetCurrentConnectionType() {
// http://crbug.com/125097
base::ThreadRestrictions::ScopedAllowWait allow_wait;
offline_state_initialized_.Wait();
base::AutoLock lock(is_offline_lock_);
- return is_offline_;
+ // TODO(droger): Return something more detailed than CONNECTION_UNKNOWN.
+ return is_offline_ ? NetworkChangeNotifier::CONNECTION_NONE :
+ NetworkChangeNotifier::CONNECTION_UNKNOWN;
}
class NetworkChangeNotifierLinux::Thread
@@ -250,10 +253,10 @@ class NetworkChangeNotifierLinux::Thread
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
- // Plumbing for NetworkChangeNotifier::IsCurrentlyOffline.
+ // Plumbing for NetworkChangeNotifier::GetCurrentConnectionType.
// Safe to call from any thread.
- bool IsCurrentlyOffline() {
- return network_manager_api_.IsCurrentlyOffline();
+ NetworkChangeNotifier::ConnectionType GetCurrentConnectionType() {
+ return network_manager_api_.GetCurrentConnectionType();
}
protected:
@@ -287,8 +290,8 @@ NetworkChangeNotifierLinux::Thread::Thread(dbus::Bus* bus)
: base::Thread("NetworkChangeNotifier"),
netlink_fd_(kInvalidSocket),
network_manager_api_(
- base::Bind(&NetworkChangeNotifier
- ::NotifyObserversOfOnlineStateChange),
+ base::Bind(&NetworkChangeNotifier::
+ NotifyObserversOfConnectionTypeChange),
bus) {
}
@@ -392,8 +395,9 @@ NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() {
notifier_thread_->Stop();
}
-bool NetworkChangeNotifierLinux::IsCurrentlyOffline() const {
- return notifier_thread_->IsCurrentlyOffline();
+NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierLinux::GetCurrentConnectionType() const {
+ return notifier_thread_->GetCurrentConnectionType();
}
} // namespace net
diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h
index e9426d0..cc5ceff 100644
--- a/net/base/network_change_notifier_linux.h
+++ b/net/base/network_change_notifier_linux.h
@@ -33,7 +33,7 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierLinux
virtual ~NetworkChangeNotifierLinux();
// NetworkChangeNotifier:
- virtual bool IsCurrentlyOffline() const OVERRIDE;
+ virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
// The thread used to listen for notifications. This relays the notification
// to the registered observers without posting back to the thread the object
diff --git a/net/base/network_change_notifier_linux_unittest.cc b/net/base/network_change_notifier_linux_unittest.cc
index d8513ce..10dda96 100644
--- a/net/base/network_change_notifier_linux_unittest.cc
+++ b/net/base/network_change_notifier_linux_unittest.cc
@@ -119,21 +119,22 @@ class NetworkChangeNotifierLinuxTest : public testing::Test {
namespace {
-class OfflineObserver : public NetworkChangeNotifier::OnlineStateObserver {
+class OfflineObserver : public NetworkChangeNotifier::ConnectionTypeObserver {
public:
OfflineObserver()
: notification_count(0),
last_online_value(true) {
- NetworkChangeNotifier::AddOnlineStateObserver(this);
+ NetworkChangeNotifier::AddConnectionTypeObserver(this);
}
~OfflineObserver() {
- NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
}
- virtual void OnOnlineStateChanged(bool online) OVERRIDE {
+ virtual void OnConnectionTypeChanged(
+ NetworkChangeNotifier::ConnectionType type) OVERRIDE {
notification_count++;
- last_online_value = online;
+ last_online_value = type != NetworkChangeNotifier::CONNECTION_NONE;
}
int notification_count;
@@ -142,23 +143,26 @@ class OfflineObserver : public NetworkChangeNotifier::OnlineStateObserver {
TEST_F(NetworkChangeNotifierLinuxTest, Offline) {
SendResponse(NM_STATE_DISCONNECTED);
- EXPECT_TRUE(NetworkChangeNotifier::IsOffline());
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
}
TEST_F(NetworkChangeNotifierLinuxTest, Online) {
SendResponse(NM_STATE_CONNECTED_GLOBAL);
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
-}
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());}
TEST_F(NetworkChangeNotifierLinuxTest, OfflineThenOnline) {
OfflineObserver observer;
SendResponse(NM_STATE_DISCONNECTED);
- EXPECT_TRUE(NetworkChangeNotifier::IsOffline());
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(0, observer.notification_count);
SendSignal(NM_STATE_CONNECTED_GLOBAL);
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(1, observer.notification_count);
EXPECT_TRUE(observer.last_online_value);
}
@@ -167,16 +171,19 @@ TEST_F(NetworkChangeNotifierLinuxTest, MultipleStateChanges) {
OfflineObserver observer;
SendResponse(NM_STATE_CONNECTED_GLOBAL);
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(0, observer.notification_count);
SendSignal(NM_STATE_DISCONNECTED);
- EXPECT_TRUE(NetworkChangeNotifier::IsOffline());
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(1, observer.notification_count);
EXPECT_FALSE(observer.last_online_value);
SendSignal(NM_STATE_CONNECTED_GLOBAL);
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(2, observer.notification_count);
EXPECT_TRUE(observer.last_online_value);
}
@@ -185,11 +192,13 @@ TEST_F(NetworkChangeNotifierLinuxTest, IgnoreContinuedOnlineState) {
OfflineObserver observer;
SendResponse(NM_STATE_CONNECTED_SITE);
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(0, observer.notification_count);
SendSignal(NM_STATE_CONNECTED_GLOBAL);
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(0, observer.notification_count);
}
@@ -197,24 +206,28 @@ TEST_F(NetworkChangeNotifierLinuxTest, IgnoreContinuedOfflineState) {
OfflineObserver observer;
SendResponse(NM_STATE_DISCONNECTING);
- EXPECT_TRUE(NetworkChangeNotifier::IsOffline());
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(0, observer.notification_count);
SendSignal(NM_STATE_DISCONNECTED);
- EXPECT_TRUE(NetworkChangeNotifier::IsOffline());
+ EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
EXPECT_EQ(0, observer.notification_count);
}
TEST_F(NetworkChangeNotifierLinuxTest, NullResponse) {
RunOnNotifierThread(base::Bind(
response_callback_, static_cast<dbus::Response*>(NULL)));
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
}
TEST_F(NetworkChangeNotifierLinuxTest, EmptyResponse) {
scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
RunOnNotifierThread(base::Bind(response_callback_, response.get()));
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
}
TEST_F(NetworkChangeNotifierLinuxTest, InvalidResponse) {
@@ -222,7 +235,8 @@ TEST_F(NetworkChangeNotifierLinuxTest, InvalidResponse) {
dbus::MessageWriter writer(response.get());
writer.AppendUint16(20); // Uint16 instead of the expected Uint32
RunOnNotifierThread(base::Bind(response_callback_, response.get()));
- EXPECT_FALSE(NetworkChangeNotifier::IsOffline());
+ EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE,
+ NetworkChangeNotifier::GetConnectionType());
}
} // namespace
diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc
index 0265ef1..85e95a2 100644
--- a/net/base/network_change_notifier_mac.cc
+++ b/net/base/network_change_notifier_mac.cc
@@ -46,12 +46,13 @@ class NetworkChangeNotifierMac::DnsWatcherThread : public base::Thread {
};
NetworkChangeNotifierMac::NetworkChangeNotifierMac()
- : online_state_(UNINITIALIZED),
- initial_state_cv_(&online_state_lock_),
+ : connection_type_(CONNECTION_UNKNOWN),
+ connection_type_initialized_(false),
+ initial_connection_type_cv_(&connection_type_lock_),
forwarder_(this),
dns_watcher_thread_(new DnsWatcherThread()) {
// Must be initialized after the rest of this object, as it may call back into
- // SetInitialState().
+ // SetInitialConnectionType().
config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_));
dns_watcher_thread_->StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0));
@@ -71,16 +72,17 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
}
}
-bool NetworkChangeNotifierMac::IsCurrentlyOffline() const {
- base::AutoLock lock(online_state_lock_);
- // Make sure the initial state is set before returning.
- while (online_state_ == UNINITIALIZED) {
- initial_state_cv_.Wait();
+NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierMac::GetCurrentConnectionType() const {
+ base::AutoLock lock(connection_type_lock_);
+ // Make sure the initial connection type is set before returning.
+ while (!connection_type_initialized_) {
+ initial_connection_type_cv_.Wait();
}
- return online_state_ == OFFLINE;
+ return connection_type_;
}
-void NetworkChangeNotifierMac::SetInitialState() {
+void NetworkChangeNotifierMac::SetInitialConnectionType() {
// Called on notifier thread.
// Try to reach 0.0.0.0. This is the approach taken by Firefox:
@@ -100,11 +102,14 @@ void NetworkChangeNotifierMac::SetInitialState() {
if (SCNetworkReachabilityGetFlags(reachability_, &flags))
reachable = CalculateReachability(flags);
else
- LOG(ERROR) << "Could not get initial network state, assuming online.";
+ LOG(ERROR) << "Could not get initial network connection type,"
+ << "assuming online.";
{
- base::AutoLock lock(online_state_lock_);
- online_state_ = reachable ? ONLINE : OFFLINE;
- initial_state_cv_.Signal();
+ base::AutoLock lock(connection_type_lock_);
+ // TODO(droger): Get something more detailed than CONNECTION_UNKNOWN.
+ connection_type_ = reachable ? CONNECTION_UNKNOWN : CONNECTION_NONE;
+ connection_type_initialized_ = true;
+ initial_connection_type_cv_.Signal();
}
}
@@ -187,15 +192,17 @@ void NetworkChangeNotifierMac::ReachabilityCallback(
DCHECK_EQ(notifier_mac->run_loop_.get(), CFRunLoopGetCurrent());
- OnlineState new_state = CalculateReachability(flags) ? ONLINE : OFFLINE;
- OnlineState old_state;
+ // TODO(droger): Get something more detailed than CONNECTION_UNKNOWN.
+ ConnectionType new_type = CalculateReachability(flags) ? CONNECTION_UNKNOWN
+ : CONNECTION_NONE;
+ ConnectionType old_type;
{
- base::AutoLock lock(notifier_mac->online_state_lock_);
- old_state = notifier_mac->online_state_;
- notifier_mac->online_state_ = new_state;
+ base::AutoLock lock(notifier_mac->connection_type_lock_);
+ old_type = notifier_mac->connection_type_;
+ notifier_mac->connection_type_ = new_type;
}
- if (old_state != new_state)
- NotifyObserversOfOnlineStateChange();
+ if (old_type != new_type)
+ NotifyObserversOfConnectionTypeChange();
}
} // namespace net
diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h
index c95e952..43d02fb 100644
--- a/net/base/network_change_notifier_mac.h
+++ b/net/base/network_change_notifier_mac.h
@@ -24,15 +24,8 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
NetworkChangeNotifierMac();
virtual ~NetworkChangeNotifierMac();
- // NetworkChangeNotifier:
- virtual bool IsCurrentlyOffline() const OVERRIDE;
-
- private:
- enum OnlineState {
- UNINITIALIZED = -1,
- OFFLINE = 0,
- ONLINE = 1
- };
+ // NetworkChangeNotifier implementation:
+ virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
class DnsWatcherThread;
@@ -45,7 +38,7 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
// NetworkConfigWatcherMac::Delegate implementation:
virtual void Init() OVERRIDE {
- net_config_watcher_->SetInitialState();
+ net_config_watcher_->SetInitialConnectionType();
}
virtual void StartReachabilityNotifications() OVERRIDE {
net_config_watcher_->StartReachabilityNotifications();
@@ -68,7 +61,7 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
void OnNetworkConfigChange(CFArrayRef changed_keys);
- void SetInitialState();
+ void SetInitialConnectionType();
static void ReachabilityCallback(SCNetworkReachabilityRef target,
SCNetworkConnectionFlags flags,
@@ -76,9 +69,10 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
// These must be constructed before config_watcher_ to ensure
// the lock is in a valid state when Forwarder::Init is called.
- OnlineState online_state_;
- mutable base::Lock online_state_lock_;
- mutable base::ConditionVariable initial_state_cv_;
+ ConnectionType connection_type_;
+ bool connection_type_initialized_;
+ mutable base::Lock connection_type_lock_;
+ mutable base::ConditionVariable initial_connection_type_cv_;
base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_;
base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_;
diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc
index 928a688..ccb033b 100644
--- a/net/base/network_change_notifier_win.cc
+++ b/net/base/network_change_notifier_win.cc
@@ -69,9 +69,11 @@ NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {
WSACloseEvent(addr_overlapped_.hEvent);
}
-// Conceptually we would like to tell whether the user is "online" verus
-// "offline". This is challenging since the only thing we can test with
-// certainty is whether a *particular* host is reachable.
+// This implementation does not return the actual connection type but merely
+// determines if the user is "online" (in which case it returns
+// CONNECTION_UNKNOWN) or "offline" (and then it returns CONNECTION_NONE).
+// This is challenging since the only thing we can test with certainty is
+// whether a *particular* host is reachable.
//
// While we can't conclusively determine when a user is "online", we can at
// least reliably recognize some of the situtations when they are clearly
@@ -115,7 +117,8 @@ NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {
// experiments I ran... However none of them correctly returned "offline" when
// executing 'ipconfig /release'.
//
-bool NetworkChangeNotifierWin::IsCurrentlyOffline() const {
+NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierWin::GetCurrentConnectionType() const {
// TODO(eroman): We could cache this value, and only re-calculate it on
// network changes. For now we recompute it each time asked,
@@ -138,7 +141,7 @@ bool NetworkChangeNotifierWin::IsCurrentlyOffline() const {
if (0 != WSALookupServiceBegin(&query_set, LUP_RETURN_ALL,
&ws_handle)) {
LOG(ERROR) << "WSALookupServiceBegin failed with: " << WSAGetLastError();
- return false;
+ return NetworkChangeNotifier::CONNECTION_UNKNOWN;
}
bool found_connection = false;
@@ -183,7 +186,9 @@ bool NetworkChangeNotifierWin::IsCurrentlyOffline() const {
LOG_IF(ERROR, result != 0)
<< "WSALookupServiceEnd() failed with: " << result;
- return !found_connection;
+ // TODO(droger): Return something more detailed than CONNECTION_UNKNOWN.
+ return found_connection ? NetworkChangeNotifier::CONNECTION_UNKNOWN :
+ NetworkChangeNotifier::CONNECTION_NONE;
}
void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) {
@@ -201,14 +206,14 @@ void NetworkChangeNotifierWin::NotifyObservers() {
DCHECK(CalledOnValidThread());
NotifyObserversOfIPAddressChange();
- // Calling IsOffline() at this very moment is likely to give
+ // Calling GetConnectionType() at this very moment is likely to give
// the wrong result, so we delay that until a little bit later.
//
// The one second delay chosen here was determined experimentally
// by adamk on Windows 7.
timer_.Stop(); // cancel any already waiting notification
timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this,
- &NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange);
+ &NetworkChangeNotifierWin::NotifyParentOfConnectionTypeChange);
}
void NetworkChangeNotifierWin::WatchForAddressChange() {
@@ -264,8 +269,8 @@ bool NetworkChangeNotifierWin::WatchForAddressChangeInternal() {
return true;
}
-void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() {
- NotifyObserversOfOnlineStateChange();
+void NetworkChangeNotifierWin::NotifyParentOfConnectionTypeChange() {
+ NotifyObserversOfConnectionTypeChange();
}
} // namespace net
diff --git a/net/base/network_change_notifier_win.h b/net/base/network_change_notifier_win.h
index d8c9a45..d37cb8f 100644
--- a/net/base/network_change_notifier_win.h
+++ b/net/base/network_change_notifier_win.h
@@ -52,7 +52,7 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin
friend class NetworkChangeNotifierWinTest;
// NetworkChangeNotifier methods:
- virtual bool IsCurrentlyOffline() const OVERRIDE;
+ virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
// ObjectWatcher::Delegate methods:
// Must only be called on the thread |this| was created on.
@@ -63,8 +63,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin
// thread |this| was created on.
void NotifyObservers();
- // Forwards online state notifications to parent class.
- void NotifyParentOfOnlineStateChange();
+ // Forwards connection type notifications to parent class.
+ void NotifyParentOfConnectionTypeChange();
// Tries to start listening for a single subsequent address change. Returns
// false on failure. The caller is responsible for updating |is_watching_|.
diff --git a/net/base/network_change_notifier_win_unittest.cc b/net/base/network_change_notifier_win_unittest.cc
index 170755a..4ade0e0 100644
--- a/net/base/network_change_notifier_win_unittest.cc
+++ b/net/base/network_change_notifier_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -31,8 +31,9 @@ class TestNetworkChangeNotifierWin : public NetworkChangeNotifierWin {
}
// From NetworkChangeNotifier.
- virtual bool IsCurrentlyOffline() const OVERRIDE {
- return false;
+ virtual NetworkChangeNotifier::ConnectionType
+ GetCurrentConnectionType() const OVERRIDE {
+ return NetworkChangeNotifier::CONNECTION_UNKNOWN;
}
// From NetworkChangeNotifierWin.
diff --git a/net/url_request/url_request_throttler_manager.cc b/net/url_request/url_request_throttler_manager.cc
index c2fa430..5c50558 100644
--- a/net/url_request/url_request_throttler_manager.cc
+++ b/net/url_request/url_request_throttler_manager.cc
@@ -28,12 +28,12 @@ URLRequestThrottlerManager::URLRequestThrottlerManager()
url_id_replacements_.ClearRef();
NetworkChangeNotifier::AddIPAddressObserver(this);
- NetworkChangeNotifier::AddOnlineStateObserver(this);
+ NetworkChangeNotifier::AddConnectionTypeObserver(this);
}
URLRequestThrottlerManager::~URLRequestThrottlerManager() {
NetworkChangeNotifier::RemoveIPAddressObserver(this);
- NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
// Since, for now, the manager object might conceivably go away before
// the entries, detach the entries' back-pointer to the manager.
@@ -166,7 +166,8 @@ void URLRequestThrottlerManager::OnIPAddressChanged() {
OnNetworkChange();
}
-void URLRequestThrottlerManager::OnOnlineStateChanged(bool online) {
+void URLRequestThrottlerManager::OnConnectionTypeChanged(
+ NetworkChangeNotifier::ConnectionType type) {
OnNetworkChange();
}
@@ -207,7 +208,7 @@ void URLRequestThrottlerManager::OnNetworkChange() {
// Remove all entries. Any entries that in-flight requests have a reference
// to will live until those requests end, and these entries may be
// inconsistent with new entries for the same URLs, but since what we
- // want is a clean slate for the new connection state, this is OK.
+ // want is a clean slate for the new connection type, this is OK.
url_entries_.clear();
requests_since_last_gc_ = 0;
}
diff --git a/net/url_request/url_request_throttler_manager.h b/net/url_request/url_request_throttler_manager.h
index 97016a5..427b42e 100644
--- a/net/url_request/url_request_throttler_manager.h
+++ b/net/url_request/url_request_throttler_manager.h
@@ -36,7 +36,7 @@ class NetLog;
class NET_EXPORT URLRequestThrottlerManager
: NON_EXPORTED_BASE(public base::NonThreadSafe),
public NetworkChangeNotifier::IPAddressObserver,
- public NetworkChangeNotifier::OnlineStateObserver {
+ public NetworkChangeNotifier::ConnectionTypeObserver {
public:
URLRequestThrottlerManager();
virtual ~URLRequestThrottlerManager();
@@ -81,8 +81,9 @@ class NET_EXPORT URLRequestThrottlerManager
// IPAddressObserver interface.
virtual void OnIPAddressChanged() OVERRIDE;
- // OnlineStateObserver interface.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE;
+ // ConnectionTypeObserver interface.
+ virtual void OnConnectionTypeChanged(
+ NetworkChangeNotifier::ConnectionType type) OVERRIDE;
// Method that allows us to transform a URL into an ID that can be used in our
// map. Resulting IDs will be lowercase and consist of the scheme, host, port
diff --git a/net/url_request/url_request_throttler_unittest.cc b/net/url_request/url_request_throttler_unittest.cc
index 11a1f76..0d018cd 100644
--- a/net/url_request/url_request_throttler_unittest.cc
+++ b/net/url_request/url_request_throttler_unittest.cc
@@ -511,10 +511,12 @@ TEST(URLRequestThrottlerManager, ClearOnNetworkChange) {
manager.OnIPAddressChanged();
break;
case 1:
- manager.OnOnlineStateChanged(true);
+ manager.OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::CONNECTION_UNKNOWN);
break;
case 2:
- manager.OnOnlineStateChanged(false);
+ manager.OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::CONNECTION_NONE);
break;
default:
FAIL();
diff --git a/remoting/host/signaling_connector.cc b/remoting/host/signaling_connector.cc
index a9bef15..e93c398 100644
--- a/remoting/host/signaling_connector.cc
+++ b/remoting/host/signaling_connector.cc
@@ -39,7 +39,7 @@ SignalingConnector::SignalingConnector(
reconnect_attempts_(0),
refreshing_oauth_token_(false) {
DCHECK(!auth_failed_callback_.is_null());
- net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
net::NetworkChangeNotifier::AddIPAddressObserver(this);
signal_strategy_->AddListener(this);
ScheduleTryReconnect();
@@ -47,7 +47,7 @@ SignalingConnector::SignalingConnector(
SignalingConnector::~SignalingConnector() {
signal_strategy_->RemoveListener(this);
- net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
+ net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
@@ -86,9 +86,10 @@ void SignalingConnector::OnIPAddressChanged() {
ResetAndTryReconnect();
}
-void SignalingConnector::OnOnlineStateChanged(bool online) {
+void SignalingConnector::OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) {
DCHECK(CalledOnValidThread());
- if (online) {
+ if (type != net::NetworkChangeNotifier::CONNECTION_NONE) {
LOG(INFO) << "Network state changed to online.";
ResetAndTryReconnect();
}
diff --git a/remoting/host/signaling_connector.h b/remoting/host/signaling_connector.h
index 4b432f3..582b4ae 100644
--- a/remoting/host/signaling_connector.h
+++ b/remoting/host/signaling_connector.h
@@ -24,12 +24,12 @@ namespace remoting {
// not connected it keeps trying to reconnect it until it is
// connected. It limits connection attempt rate using exponential
// backoff. It also monitors network state and reconnects signalling
-// whenever online state changes or IP address changes.
+// whenever connection type changes or IP address changes.
class SignalingConnector
: public base::SupportsWeakPtr<SignalingConnector>,
public base::NonThreadSafe,
public SignalStrategy::Listener,
- public net::NetworkChangeNotifier::OnlineStateObserver,
+ public net::NetworkChangeNotifier::ConnectionTypeObserver,
public net::NetworkChangeNotifier::IPAddressObserver,
public GaiaOAuthClient::Delegate {
public:
@@ -67,8 +67,9 @@ class SignalingConnector
// NetworkChangeNotifier::IPAddressObserver interface.
virtual void OnIPAddressChanged() OVERRIDE;
- // NetworkChangeNotifier::OnlineStateObserver interface.
- virtual void OnOnlineStateChanged(bool online) OVERRIDE;
+ // NetworkChangeNotifier::ConnectionTypeObserver interface.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
// GaiaOAuthClient::Delegate interface.
virtual void OnRefreshTokenResponse(const std::string& user_email,