[CrOS Network] Update quick settings UI when Wi-Fi is turned on.

Previously, we would only update the settings UI immediately when Wi-Fi
is turned off; in all other cases, we would batch updates and wait up to
1 second before showing the update in the UI. This led to a confusing UI
in which settings would display the update immediately but quick
settings would not.

This CL fixes this issue by also updating the UI immediately when Wi-Fi
is turned on as well as off. Additionally, because this UI contains a
toggle for Mobile data as well, this CL updates the UI immediately for
changes in Cellular/Tether status.

Bug: 917325
Change-Id: I6228909c99de08774bfc9599c07b87ecd6dd20bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1534153
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643156}
diff --git a/ash/system/network/tray_network_state_observer.cc b/ash/system/network/tray_network_state_observer.cc
index f0763d3..bf4b19b 100644
--- a/ash/system/network/tray_network_state_observer.cc
+++ b/ash/system/network/tray_network_state_observer.cc
@@ -25,6 +25,12 @@
       chromeos::NetworkTypePattern::WiFi());
 }
 
+bool IsMobileEnabled() {
+  return NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
+      chromeos::NetworkTypePattern::Cellular() |
+      chromeos::NetworkTypePattern::Tether());
+}
+
 }  // namespace
 
 namespace ash {
@@ -78,11 +84,17 @@
 }
 
 void TrayNetworkStateObserver::SignalUpdate(bool notify_a11y) {
-  bool old_state = wifi_enabled_;
+  bool old_wifi_state = wifi_enabled_;
   wifi_enabled_ = IsWifiEnabled();
 
-  // Update immediately when wifi network changed from enabled->disabled.
-  if (old_state && !wifi_enabled_) {
+  bool old_mobile_state = mobile_enabled_;
+  mobile_enabled_ = IsMobileEnabled();
+
+  // Update immediately when Wi-Fi and/or Mobile have been turned on or off.
+  // This ensures that the UI for settings and quick settings stays in sync; see
+  // https://crbug.com/917325.
+  if (old_wifi_state != wifi_enabled_ || old_mobile_state != mobile_enabled_) {
+    timer_.Stop();
     SendNetworkStateChanged(notify_a11y);
     return;
   }
diff --git a/ash/system/network/tray_network_state_observer.h b/ash/system/network/tray_network_state_observer.h
index 2e91a3d..bbead09 100644
--- a/ash/system/network/tray_network_state_observer.h
+++ b/ash/system/network/tray_network_state_observer.h
@@ -52,9 +52,12 @@
   // Timer used to limit the frequency of NetworkStateChanged updates.
   base::OneShotTimer timer_;
 
-  // The previous state of the wifi network, used to immediately send
-  // NetworkStateChanged update when wifi changed from enabled->disabled.
+  // The cached states of whether Wi-Fi and Mobile are enabled. The tray
+  // includes expanding network lists of these types, so these cached values
+  // are used to determine when to prioritize updating the tray when they
+  // change.
   bool wifi_enabled_ = false;
+  bool mobile_enabled_ = false;
 
   DISALLOW_COPY_AND_ASSIGN(TrayNetworkStateObserver);
 };