Commit c1f7f028 authored by Tony de Luna's avatar Tony de Luna Committed by Commit Bot

QS, stop WiFi scanning when WiFi disabled.

Only do periodic WiFi scanning when WiFi is enabled.

Hide scanning progress bar as soon as user disables WiFi, even if a
scan is still in progress.

BUG=891947

Change-Id: Ica6cc4116f88743b24fb081b89886501ecd1d2d3
Reviewed-on: https://chromium-review.googlesource.com/c/1356027Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Tony De Luna <tonydeluna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613175}
parent ecf39527
......@@ -58,6 +58,11 @@ bool IsSecondaryUser() {
!session_controller->IsUserPrimary();
}
bool IsWifiEnabled() {
return NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
chromeos::NetworkTypePattern::WiFi());
}
} // namespace
// A bubble which displays network info.
......@@ -194,6 +199,7 @@ NetworkStateListDetailedView::~NetworkStateListDetailedView() {
void NetworkStateListDetailedView::Update() {
UpdateNetworkList();
UpdateHeaderButtons();
UpdateScanningBar();
Layout();
}
......@@ -209,8 +215,8 @@ void NetworkStateListDetailedView::Init() {
Update();
if (list_type_ == LIST_TYPE_NETWORK)
CallRequestScan();
if (list_type_ == LIST_TYPE_NETWORK && IsWifiEnabled())
ScanAndStartTimer();
}
void NetworkStateListDetailedView::HandleButtonPressed(views::Button* sender,
......@@ -298,13 +304,25 @@ void NetworkStateListDetailedView::UpdateHeaderButtons() {
Shell::Get()->session_controller()->ShouldEnableSettings());
}
}
if (list_type_ == LIST_TYPE_NETWORK) {
NetworkStateHandler* network_state_handler =
NetworkHandler::Get()->network_state_handler();
const bool scanning = network_state_handler->GetScanningByType(
NetworkTypePattern::WiFi() | NetworkTypePattern::Tether());
ShowProgress(-1, scanning);
}
}
void NetworkStateListDetailedView::UpdateScanningBar() {
if (list_type_ != LIST_TYPE_NETWORK)
return;
bool is_wifi_enabled = IsWifiEnabled();
if (is_wifi_enabled && !network_scan_repeating_timer_.IsRunning())
ScanAndStartTimer();
if (!is_wifi_enabled && network_scan_repeating_timer_.IsRunning())
network_scan_repeating_timer_.Stop();
const bool scanning_bar_visible =
is_wifi_enabled &&
NetworkHandler::Get()->network_state_handler()->GetScanningByType(
NetworkTypePattern::WiFi() | NetworkTypePattern::Tether());
ShowProgress(-1, scanning_bar_visible);
}
void NetworkStateListDetailedView::ToggleInfoBubble() {
......@@ -380,15 +398,20 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() {
return label;
}
void NetworkStateListDetailedView::ScanAndStartTimer() {
CallRequestScan();
network_scan_repeating_timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(kRequestScanDelaySeconds), this,
&NetworkStateListDetailedView::CallRequestScan);
}
void NetworkStateListDetailedView::CallRequestScan() {
if (!IsWifiEnabled())
return;
VLOG(1) << "Requesting Network Scan.";
NetworkHandler::Get()->network_state_handler()->RequestScan(
NetworkTypePattern::WiFi() | NetworkTypePattern::Tether());
// Periodically request a scan while this UI is open.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&NetworkStateListDetailedView::CallRequestScan, AsWeakPtr()),
base::TimeDelta::FromSeconds(kRequestScanDelaySeconds));
}
} // namespace tray
......
......@@ -11,6 +11,7 @@
#include "ash/system/tray/tray_detailed_view.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
namespace views {
class Button;
......@@ -62,16 +63,22 @@ class ASH_EXPORT NetworkStateListDetailedView
// Launches the WebUI settings in a browser and closes the system menu.
void ShowSettings();
// Update UI components.
// Update info and settings buttons in header.
void UpdateHeaderButtons();
// Update scanning progress bar.
void UpdateScanningBar();
// Create and manage the network info bubble.
void ToggleInfoBubble();
bool ResetInfoBubble();
void OnInfoBubbleDestroyed();
views::View* CreateNetworkInfoView();
// Periodically request a network scan.
// Scan and start timer to periodically request a network scan.
void ScanAndStartTimer();
// Request a network scan.
void CallRequestScan();
// Type of list (all networks or vpn)
......@@ -86,6 +93,9 @@ class ASH_EXPORT NetworkStateListDetailedView
// A small bubble for displaying network info.
InfoBubble* info_bubble_;
// Timer for starting and stopping network scans.
base::RepeatingTimer network_scan_repeating_timer_;
DISALLOW_COPY_AND_ASSIGN(NetworkStateListDetailedView);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment