Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/components/tether/wifi_hotspot_connector.h" | 5 #include "chromeos/components/tether/wifi_hotspot_connector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chromeos/network/network_connect.h" | 10 #include "chromeos/network/network_connect.h" |
| 11 #include "chromeos/network/network_handler.h" | 11 #include "chromeos/network/network_handler.h" |
| 12 #include "chromeos/network/network_state.h" | 12 #include "chromeos/network/network_state.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
| 14 #include "chromeos/network/shill_property_util.h" | 14 #include "chromeos/network/shill_property_util.h" |
| 15 #include "components/proximity_auth/logging/logging.h" | 15 #include "components/proximity_auth/logging/logging.h" |
| 16 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 16 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 namespace tether { | 20 namespace tether { |
| 21 | 21 |
| 22 WifiHotspotConnector::WifiHotspotConnector( | 22 WifiHotspotConnector::WifiHotspotConnector( |
| 23 NetworkStateHandler* network_state_handler, | 23 NetworkStateHandler* network_state_handler, |
| 24 NetworkConnect* network_connect) | 24 NetworkConnect* network_connect, |
| 25 ActiveHost* active_host) | |
| 25 : network_state_handler_(network_state_handler), | 26 : network_state_handler_(network_state_handler), |
| 26 network_connect_(network_connect), | 27 network_connect_(network_connect), |
| 28 active_host_(active_host), | |
| 27 timer_(base::MakeUnique<base::OneShotTimer>()), | 29 timer_(base::MakeUnique<base::OneShotTimer>()), |
| 28 weak_ptr_factory_(this) { | 30 weak_ptr_factory_(this) { |
| 29 network_state_handler_->AddObserver(this, FROM_HERE); | 31 network_state_handler_->AddObserver(this, FROM_HERE); |
| 30 } | 32 } |
| 31 | 33 |
| 32 WifiHotspotConnector::~WifiHotspotConnector() { | 34 WifiHotspotConnector::~WifiHotspotConnector() { |
| 33 network_state_handler_->RemoveObserver(this, FROM_HERE); | 35 network_state_handler_->RemoveObserver(this, FROM_HERE); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void WifiHotspotConnector::ConnectToWifiHotspot( | 38 void WifiHotspotConnector::ConnectToWifiHotspot( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 | 75 |
| 74 if (network->IsConnectedState()) { | 76 if (network->IsConnectedState()) { |
| 75 // If a connection occurred, notify observers and exit early. | 77 // If a connection occurred, notify observers and exit early. |
| 76 InvokeWifiConnectionCallback(wifi_guid_); | 78 InvokeWifiConnectionCallback(wifi_guid_); |
| 77 return; | 79 return; |
| 78 } | 80 } |
| 79 | 81 |
| 80 if (network->connectable()) { | 82 if (network->connectable()) { |
| 81 // If the network is now connectable, initiate a connection to it. | 83 // If the network is now connectable, initiate a connection to it. |
|
Kyle Horimoto
2017/04/27 01:28:07
Move this comment to before the ConnectToNetworkId
lesliewatkins
2017/04/28 21:30:43
Done.
| |
| 84 std::string tether_guid = active_host_->GetTetherNetworkGuid(); | |
|
Kyle Horimoto
2017/04/27 01:28:07
I apologize for not noticing this earlier, but thi
lesliewatkins
2017/04/28 21:30:43
Done.
| |
| 85 bool successful_association = | |
| 86 network_state_handler_->AssociateTetherNetworkStateWithWifiNetwork( | |
| 87 tether_guid, wifi_guid_); | |
| 88 if (successful_association) { | |
| 89 PA_LOG(INFO) << "Wifi network with ID " << wifi_guid_ | |
| 90 << " is connectable. Tether network ID: \"" << tether_guid | |
| 91 << "\", Wi-Fi network ID: \"" << wifi_guid_ << "\""; | |
| 92 } else { | |
| 93 PA_LOG(INFO) << "Wifi network with ID " << wifi_guid_ | |
| 94 << " is connectable, but failed to associate tether network " | |
| 95 "with ID \"" | |
| 96 << tether_guid << "\" to Wi-Fi network with ID: \"" | |
| 97 << wifi_guid_ << "\""; | |
| 98 } | |
| 99 | |
| 82 network_connect_->ConnectToNetworkId(wifi_guid_); | 100 network_connect_->ConnectToNetworkId(wifi_guid_); |
| 83 } | 101 } |
| 84 } | 102 } |
| 85 | 103 |
| 86 void WifiHotspotConnector::InvokeWifiConnectionCallback( | 104 void WifiHotspotConnector::InvokeWifiConnectionCallback( |
| 87 const std::string& wifi_guid) { | 105 const std::string& wifi_guid) { |
| 88 DCHECK(!callback_.is_null()); | 106 DCHECK(!callback_.is_null()); |
| 89 | 107 |
| 90 // |wifi_guid| may be a reference to |wifi_guid_|, so make a copy of it first | 108 // |wifi_guid| may be a reference to |wifi_guid_|, so make a copy of it first |
| 91 // before clearing it below. | 109 // before clearing it below. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 InvokeWifiConnectionCallback(std::string()); | 154 InvokeWifiConnectionCallback(std::string()); |
| 137 } | 155 } |
| 138 | 156 |
| 139 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) { | 157 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) { |
| 140 timer_ = std::move(timer); | 158 timer_ = std::move(timer); |
| 141 } | 159 } |
| 142 | 160 |
| 143 } // namespace tether | 161 } // namespace tether |
| 144 | 162 |
| 145 } // namespace chromeos | 163 } // namespace chromeos |
| OLD | NEW |