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/components/tether/host_connection_metrics_logger.h" |
10 #include "chromeos/network/network_connect.h" | 11 #include "chromeos/network/network_connect.h" |
11 #include "chromeos/network/network_handler.h" | 12 #include "chromeos/network/network_handler.h" |
12 #include "chromeos/network/network_state.h" | 13 #include "chromeos/network/network_state.h" |
13 #include "chromeos/network/network_state_handler.h" | 14 #include "chromeos/network/network_state_handler.h" |
14 #include "chromeos/network/shill_property_util.h" | 15 #include "chromeos/network/shill_property_util.h" |
15 #include "components/proximity_auth/logging/logging.h" | 16 #include "components/proximity_auth/logging/logging.h" |
16 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 17 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 namespace tether { | 21 namespace tether { |
21 | 22 |
22 WifiHotspotConnector::WifiHotspotConnector( | 23 WifiHotspotConnector::WifiHotspotConnector( |
23 NetworkStateHandler* network_state_handler, | 24 NetworkStateHandler* network_state_handler, |
24 NetworkConnect* network_connect) | 25 NetworkConnect* network_connect, |
| 26 HostConnectionMetricsLogger* host_connection_metrics_logger) |
25 : network_state_handler_(network_state_handler), | 27 : network_state_handler_(network_state_handler), |
26 network_connect_(network_connect), | 28 network_connect_(network_connect), |
| 29 host_connection_metrics_logger_(host_connection_metrics_logger), |
27 timer_(base::MakeUnique<base::OneShotTimer>()), | 30 timer_(base::MakeUnique<base::OneShotTimer>()), |
28 weak_ptr_factory_(this) { | 31 weak_ptr_factory_(this) { |
29 network_state_handler_->AddObserver(this, FROM_HERE); | 32 network_state_handler_->AddObserver(this, FROM_HERE); |
30 } | 33 } |
31 | 34 |
32 WifiHotspotConnector::~WifiHotspotConnector() { | 35 WifiHotspotConnector::~WifiHotspotConnector() { |
33 network_state_handler_->RemoveObserver(this, FROM_HERE); | 36 network_state_handler_->RemoveObserver(this, FROM_HERE); |
34 } | 37 } |
35 | 38 |
36 void WifiHotspotConnector::ConnectToWifiHotspot( | 39 void WifiHotspotConnector::ConnectToWifiHotspot( |
(...skipping 18 matching lines...) Expand all Loading... |
55 PA_LOG(INFO) << "Wi-Fi network (ID \"" << wifi_network_guid_ << "\") " | 58 PA_LOG(INFO) << "Wi-Fi network (ID \"" << wifi_network_guid_ << "\") " |
56 << "successfully disassociated from Tether network (ID " | 59 << "successfully disassociated from Tether network (ID " |
57 << "\"" << tether_network_guid_ << "\")."; | 60 << "\"" << tether_network_guid_ << "\")."; |
58 } else { | 61 } else { |
59 PA_LOG(INFO) << "Wi-Fi network (ID \"" << wifi_network_guid_ << "\") " | 62 PA_LOG(INFO) << "Wi-Fi network (ID \"" << wifi_network_guid_ << "\") " |
60 << "failed to disassociate from Tether network ID (\"" | 63 << "failed to disassociate from Tether network ID (\"" |
61 << tether_network_guid_ << "\")."; | 64 << tether_network_guid_ << "\")."; |
62 } | 65 } |
63 | 66 |
64 InvokeWifiConnectionCallback(std::string()); | 67 InvokeWifiConnectionCallback(std::string()); |
| 68 |
| 69 host_connection_metrics_logger_->RecordConnectionToHostResult( |
| 70 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 71 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_NEW_ATTEMPT)
; |
65 } | 72 } |
66 | 73 |
67 ssid_ = ssid; | 74 ssid_ = ssid; |
68 password_ = password; | 75 password_ = password; |
69 tether_network_guid_ = tether_network_guid; | 76 tether_network_guid_ = tether_network_guid; |
70 wifi_network_guid_ = base::GenerateGUID(); | 77 wifi_network_guid_ = base::GenerateGUID(); |
71 callback_ = callback; | 78 callback_ = callback; |
72 timer_->Start(FROM_HERE, | 79 timer_->Start(FROM_HERE, |
73 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds), | 80 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds), |
74 base::Bind(&WifiHotspotConnector::OnConnectionTimeout, | 81 base::Bind(&WifiHotspotConnector::OnConnectionTimeout, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 shill::kSecurityPsk); | 176 shill::kSecurityPsk); |
170 properties.SetStringWithoutPathExpansion(shill::kPassphraseProperty, | 177 properties.SetStringWithoutPathExpansion(shill::kPassphraseProperty, |
171 password); | 178 password); |
172 } | 179 } |
173 | 180 |
174 return properties; | 181 return properties; |
175 } | 182 } |
176 | 183 |
177 void WifiHotspotConnector::OnConnectionTimeout() { | 184 void WifiHotspotConnector::OnConnectionTimeout() { |
178 InvokeWifiConnectionCallback(std::string()); | 185 InvokeWifiConnectionCallback(std::string()); |
| 186 |
| 187 host_connection_metrics_logger_->RecordConnectionToHostResult( |
| 188 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 189 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT); |
179 } | 190 } |
180 | 191 |
181 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) { | 192 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) { |
182 timer_ = std::move(timer); | 193 timer_ = std::move(timer); |
183 } | 194 } |
184 | 195 |
185 } // namespace tether | 196 } // namespace tether |
186 | 197 |
187 } // namespace chromeos | 198 } // namespace chromeos |
OLD | NEW |