Commit 78efc726 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

Tether: Ensure that WiFi is enabled before attempting a host connection.

Bug: 738540
Change-Id: If0782f8983263d500285de3c986de180c268f2b3
Reviewed-on: https://chromium-review.googlesource.com/575762Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487973}
parent d9402e22
...@@ -74,9 +74,41 @@ void WifiHotspotConnector::ConnectToWifiHotspot( ...@@ -74,9 +74,41 @@ void WifiHotspotConnector::ConnectToWifiHotspot(
base::Bind(&WifiHotspotConnector::OnConnectionTimeout, base::Bind(&WifiHotspotConnector::OnConnectionTimeout,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
base::DictionaryValue properties = // If Wi-Fi is enabled, continue with creating the configuration of the
CreateWifiPropertyDictionary(ssid, password); // hotspot. Otherwise, request that Wi-Fi be enabled and wait; see
network_connect_->CreateConfiguration(&properties, false /* shared */); // DeviceListChanged().
if (network_state_handler_->IsTechnologyEnabled(NetworkTypePattern::WiFi())) {
// Ensure that a possible previous pending callback to DeviceListChanged()
// won't result in a second call to CreateWifiConfiguration().
is_waiting_for_wifi_to_enable_ = false;
CreateWifiConfiguration();
} else if (!is_waiting_for_wifi_to_enable_) {
is_waiting_for_wifi_to_enable_ = true;
// Once Wi-Fi is enabled, DeviceListChanged() will be called.
network_state_handler_->SetTechnologyEnabled(
NetworkTypePattern::WiFi(), true /*enabled */,
base::Bind(&WifiHotspotConnector::OnEnableWifiError,
weak_ptr_factory_.GetWeakPtr()));
}
}
void WifiHotspotConnector::OnEnableWifiError(
const std::string& error_name,
std::unique_ptr<base::DictionaryValue> error_data) {
is_waiting_for_wifi_to_enable_ = false;
PA_LOG(ERROR) << "Failed to enable Wi-Fi: " << error_name;
}
void WifiHotspotConnector::DeviceListChanged() {
if (is_waiting_for_wifi_to_enable_ &&
network_state_handler_->IsTechnologyEnabled(NetworkTypePattern::WiFi())) {
is_waiting_for_wifi_to_enable_ = false;
if (!ssid_.empty())
CreateWifiConfiguration();
}
} }
void WifiHotspotConnector::NetworkPropertiesUpdated( void WifiHotspotConnector::NetworkPropertiesUpdated(
...@@ -135,6 +167,7 @@ void WifiHotspotConnector::InvokeWifiConnectionCallback( ...@@ -135,6 +167,7 @@ void WifiHotspotConnector::InvokeWifiConnectionCallback(
password_.clear(); password_.clear();
wifi_network_guid_.clear(); wifi_network_guid_.clear();
has_initiated_connection_to_current_network_ = false; has_initiated_connection_to_current_network_ = false;
is_waiting_for_wifi_to_enable_ = false;
timer_->Stop(); timer_->Stop();
...@@ -142,6 +175,15 @@ void WifiHotspotConnector::InvokeWifiConnectionCallback( ...@@ -142,6 +175,15 @@ void WifiHotspotConnector::InvokeWifiConnectionCallback(
callback_.Reset(); callback_.Reset();
} }
void WifiHotspotConnector::CreateWifiConfiguration() {
base::DictionaryValue properties =
CreateWifiPropertyDictionary(ssid_, password_);
// This newly configured network will eventually be passed as an argument to
// NetworkPropertiesUpdated().
network_connect_->CreateConfiguration(&properties, false /* shared */);
}
base::DictionaryValue WifiHotspotConnector::CreateWifiPropertyDictionary( base::DictionaryValue WifiHotspotConnector::CreateWifiPropertyDictionary(
const std::string& ssid, const std::string& ssid,
const std::string& password) { const std::string& password) {
......
...@@ -43,7 +43,11 @@ class WifiHotspotConnector : public NetworkStateHandlerObserver { ...@@ -43,7 +43,11 @@ class WifiHotspotConnector : public NetworkStateHandlerObserver {
const std::string& tether_network_guid, const std::string& tether_network_guid,
const WifiConnectionCallback& callback); const WifiConnectionCallback& callback);
void OnEnableWifiError(const std::string& error_name,
std::unique_ptr<base::DictionaryValue> error_data);
// NetworkStateHandlerObserver: // NetworkStateHandlerObserver:
void DeviceListChanged() override;
void NetworkPropertiesUpdated(const NetworkState* network) override; void NetworkPropertiesUpdated(const NetworkState* network) override;
private: private:
...@@ -54,6 +58,7 @@ class WifiHotspotConnector : public NetworkStateHandlerObserver { ...@@ -54,6 +58,7 @@ class WifiHotspotConnector : public NetworkStateHandlerObserver {
// Passes an empty string as |wifi_guid| to signal that the connection did not // Passes an empty string as |wifi_guid| to signal that the connection did not
// succeed. // succeed.
void InvokeWifiConnectionCallback(const std::string& wifi_guid); void InvokeWifiConnectionCallback(const std::string& wifi_guid);
void CreateWifiConfiguration();
base::DictionaryValue CreateWifiPropertyDictionary( base::DictionaryValue CreateWifiPropertyDictionary(
const std::string& ssid, const std::string& ssid,
const std::string& password); const std::string& password);
...@@ -70,6 +75,7 @@ class WifiHotspotConnector : public NetworkStateHandlerObserver { ...@@ -70,6 +75,7 @@ class WifiHotspotConnector : public NetworkStateHandlerObserver {
std::string tether_network_guid_; std::string tether_network_guid_;
std::string wifi_network_guid_; std::string wifi_network_guid_;
WifiConnectionCallback callback_; WifiConnectionCallback callback_;
bool is_waiting_for_wifi_to_enable_ = false;
bool has_initiated_connection_to_current_network_ = false; bool has_initiated_connection_to_current_network_ = false;
base::WeakPtrFactory<WifiHotspotConnector> weak_ptr_factory_; base::WeakPtrFactory<WifiHotspotConnector> weak_ptr_factory_;
......
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