diff options
Diffstat (limited to 'chrome/browser/chromeos/net')
-rw-r--r-- | chrome/browser/chromeos/net/network_change_notifier_chromeos.cc | 36 | ||||
-rw-r--r-- | chrome/browser/chromeos/net/network_change_notifier_chromeos.h | 4 |
2 files changed, 15 insertions, 25 deletions
diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc index 2007857..dd1c6f0 100644 --- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc +++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc @@ -30,7 +30,6 @@ NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() : has_active_network_(false), connection_state_(chromeos::STATE_UNKNOWN), connection_type_(CONNECTION_NONE), - is_online_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { BrowserThread::PostDelayedTask( BrowserThread::UI, FROM_HERE, @@ -152,10 +151,7 @@ void NetworkChangeNotifierChromeos::UpdateConnectivityState( } // We don't care about all transitions of ConnectionState. OnlineStateChange - // notification should trigger if - // a) we were online and went offline - // b) we were offline and went online - // c) switched to/from captive portal + // notification should trigger if ConnectionType is changed. chromeos::ConnectionState new_connection_state = network ? network->connection_state() : chromeos::STATE_UNKNOWN; @@ -174,33 +170,29 @@ void NetworkChangeNotifierChromeos::UpdateConnectivityState( << ", was_portal = " << was_portal; connection_state_ = new_connection_state; connection_type_ = new_connection_type; - if (is_online != was_online || is_portal != was_portal || - new_connection_type != prev_connection_type) { - ReportConnectionChange(IsOnline(connection_state_)); + if (new_connection_type != prev_connection_type) { + VLOG(1) << "UpdateConnectivityState3: " + << "prev_connection_type = " << prev_connection_type + << ", new_connection_type = " << new_connection_type; + ReportConnectionChange(); } - VLOG(2) << " UpdateConnectivityState3: " + VLOG(2) << " UpdateConnectivityState4: " << "new_cs = " << new_connection_state << ", end_cs_ = " << connection_state_ << "prev_type = " << prev_connection_type << ", new_type_ = " << new_connection_type; } -void NetworkChangeNotifierChromeos::ReportConnectionChange(bool is_online) { - VLOG(1) << "ReportConnectionChange: " << (is_online ? "online" : "offline"); +void NetworkChangeNotifierChromeos::ReportConnectionChange() { if (weak_factory_.HasWeakPtrs()) { + // If we have a pending task, cancel it. DVLOG(1) << "ReportConnectionChange: has pending task"; - // If we are trying to report the same state, just continue as planned. - // If the online state had changed since we queued the reporting task, - // then cancel it. This should help us avoid transient edge reporting - // while switching between connection types (i.e. wifi->ethernet). - if (is_online != is_online_) { - weak_factory_.InvalidateWeakPtrs(); - DVLOG(1) << "ReportConnectionChange: canceled pending task"; - } - return; + weak_factory_.InvalidateWeakPtrs(); + DVLOG(1) << "ReportConnectionChange: canceled pending task"; } - - is_online_ = is_online; + // Posting task with delay allows us to cancel it when connection type is + // changed frequently. This should help us avoid transient edge reporting + // while switching between connection types (e.g. ethernet->wifi). BrowserThread::PostDelayedTask( BrowserThread::UI, FROM_HERE, base::Bind( diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.h b/chrome/browser/chromeos/net/network_change_notifier_chromeos.h index 071102e..a632456 100644 --- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.h +++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.h @@ -53,7 +53,7 @@ class NetworkChangeNotifierChromeos const chromeos::Network* network) OVERRIDE; // Initiate online status change reporting. - void ReportConnectionChange(bool is_online); + void ReportConnectionChange(); void ReportConnectionChangeOnUIThread(); // Callback from online_notification_task_ when online state notification // is actually scheduled. @@ -84,8 +84,6 @@ class NetworkChangeNotifierChromeos // Current active network's IP address. std::string ip_address_; - // The last reported online state. - bool is_online_; base::WeakPtrFactory<NetworkChangeNotifierChromeos> weak_factory_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos); |