Commit 82f5bf70 authored by hansberry's avatar hansberry Committed by Commit Bot

Tether: record each type of host connection result.

BUG=672263

Review-Url: https://codereview.chromium.org/2949343002
Cr-Commit-Position: refs/heads/master@{#486209}
parent 5ec33f23
......@@ -115,6 +115,8 @@ static_library("test_support") {
"fake_tether_host_fetcher.h",
"fake_wifi_hotspot_connector.cc",
"fake_wifi_hotspot_connector.h",
"mock_host_connection_metrics_logger.cc",
"mock_host_connection_metrics_logger.h",
"mock_tether_host_response_recorder.cc",
"mock_tether_host_response_recorder.h",
"proto_test_util.cc",
......
......@@ -9,6 +9,7 @@
#include "chromeos/components/tether/active_host_network_state_updater.h"
#include "chromeos/components/tether/ble_connection_manager.h"
#include "chromeos/components/tether/device_id_tether_network_guid_map.h"
#include "chromeos/components/tether/host_connection_metrics_logger.h"
#include "chromeos/components/tether/host_scan_device_prioritizer_impl.h"
#include "chromeos/components/tether/host_scan_scheduler.h"
#include "chromeos/components/tether/host_scanner.h"
......@@ -214,12 +215,14 @@ void Initializer::OnBluetoothAdapterAdvertisingIntervalSet(
host_scan_cache_.get(), clock_.get());
host_scan_scheduler_ = base::MakeUnique<HostScanScheduler>(
network_state_handler_, host_scanner_.get());
host_connection_metrics_logger_ =
base::MakeUnique<HostConnectionMetricsLogger>();
tether_connector_ = base::MakeUnique<TetherConnector>(
network_state_handler_, wifi_hotspot_connector_.get(), active_host_.get(),
tether_host_fetcher_.get(), ble_connection_manager_.get(),
tether_host_response_recorder_.get(),
device_id_tether_network_guid_map_.get(), host_scan_cache_.get(),
notification_presenter_.get());
notification_presenter_.get(), host_connection_metrics_logger_.get());
network_configuration_remover_ =
base::MakeUnique<NetworkConfigurationRemover>(
network_state_handler_, managed_network_configuration_handler_);
......
......@@ -44,6 +44,7 @@ class HostScanner;
class HostScanScheduler;
class HostScanDevicePrioritizerImpl;
class KeepAliveScheduler;
class HostConnectionMetricsLogger;
class NetworkConfigurationRemover;
class NotificationPresenter;
class TetherConnector;
......@@ -132,6 +133,7 @@ class Initializer : public OAuth2TokenService::Observer {
std::unique_ptr<base::DefaultClock> clock_;
std::unique_ptr<HostScanner> host_scanner_;
std::unique_ptr<HostScanScheduler> host_scan_scheduler_;
std::unique_ptr<HostConnectionMetricsLogger> host_connection_metrics_logger_;
std::unique_ptr<TetherConnector> tether_connector_;
std::unique_ptr<TetherDisconnector> tether_disconnector_;
std::unique_ptr<NetworkConfigurationRemover> network_configuration_remover_;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/tether/mock_host_connection_metrics_logger.h"
namespace chromeos {
namespace tether {
MockHostConnectionMetricsLogger::MockHostConnectionMetricsLogger() {}
MockHostConnectionMetricsLogger::~MockHostConnectionMetricsLogger() {}
} // namespace tether
} // namespace chromeos
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_TETHER_MOCK_HOST_CONNECTION_METRICS_LOGGER_H_
#define CHROMEOS_COMPONENTS_TETHER_MOCK_HOST_CONNECTION_METRICS_LOGGER_H_
#include "chromeos/components/tether/host_connection_metrics_logger.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace chromeos {
namespace tether {
class MockHostConnectionMetricsLogger : public HostConnectionMetricsLogger {
public:
MockHostConnectionMetricsLogger();
~MockHostConnectionMetricsLogger() override;
MOCK_METHOD1(RecordConnectionToHostResult,
void(HostConnectionMetricsLogger::ConnectionToHostResult));
private:
DISALLOW_COPY_AND_ASSIGN(MockHostConnectionMetricsLogger);
};
} // namespace tether
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_TETHER_MOCK_HOST_CONNECTION_METRICS_LOGGER_H_
......@@ -75,7 +75,8 @@ class MockTetherConnector : public TetherConnector {
nullptr /* tether_host_response_recorder */,
nullptr /* device_id_tether_network_guid_map */,
nullptr /* host_scan_cache */,
nullptr /* notification_presenter */) {}
nullptr /* notification_presenter */,
nullptr /* host_connection_metrics_logger */) {}
~MockTetherConnector() override {}
MOCK_METHOD3(
......
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "chromeos/components/tether/active_host.h"
#include "chromeos/components/tether/device_id_tether_network_guid_map.h"
#include "chromeos/components/tether/host_connection_metrics_logger.h"
#include "chromeos/components/tether/host_scan_cache.h"
#include "chromeos/components/tether/notification_presenter.h"
#include "chromeos/components/tether/tether_host_fetcher.h"
......@@ -29,7 +30,8 @@ TetherConnector::TetherConnector(
TetherHostResponseRecorder* tether_host_response_recorder,
DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
HostScanCache* host_scan_cache,
NotificationPresenter* notification_presenter)
NotificationPresenter* notification_presenter,
HostConnectionMetricsLogger* host_connection_metrics_logger)
: network_state_handler_(network_state_handler),
wifi_hotspot_connector_(wifi_hotspot_connector),
active_host_(active_host),
......@@ -39,6 +41,7 @@ TetherConnector::TetherConnector(
device_id_tether_network_guid_map_(device_id_tether_network_guid_map),
host_scan_cache_(host_scan_cache),
notification_presenter_(notification_presenter),
host_connection_metrics_logger_(host_connection_metrics_logger),
weak_ptr_factory_(this) {}
TetherConnector::~TetherConnector() {
......@@ -119,7 +122,10 @@ bool TetherConnector::CancelConnectionAttempt(
connect_tethering_operation_.reset();
}
SetConnectionFailed(NetworkConnectionHandler::kErrorConnectCanceled);
SetConnectionFailed(
NetworkConnectionHandler::kErrorConnectCanceled,
HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER);
return true;
}
......@@ -161,7 +167,8 @@ void TetherConnector::OnSuccessfulConnectTetheringResponse(
void TetherConnector::OnConnectTetheringFailure(
const cryptauth::RemoteDevice& remote_device,
ConnectTetheringResponse_ResponseCode error_code) {
if (device_id_pending_connection_ != remote_device.GetDeviceId()) {
std::string device_id_copy = remote_device.GetDeviceId();
if (device_id_pending_connection_ != device_id_copy) {
// If the failure was part of a previous attempt for a different device,
// ignore it.
PA_LOG(INFO) << "Received failed ConnectTetheringResponse from device with "
......@@ -176,7 +183,9 @@ void TetherConnector::OnConnectTetheringFailure(
connect_tethering_operation_->RemoveObserver(this);
connect_tethering_operation_.reset();
SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed);
SetConnectionFailed(
NetworkConnectionHandler::kErrorConnectFailed,
GetConnectionToHostResultFromErrorCode(device_id_copy, error_code));
}
void TetherConnector::OnTetherHostToConnectFetched(
......@@ -193,13 +202,16 @@ void TetherConnector::OnTetherHostToConnectFetched(
PA_LOG(ERROR) << "Could not fetch tether host with device ID "
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
<< ". Cannot connect.";
SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed);
SetConnectionFailed(
NetworkConnectionHandler::kErrorConnectFailed,
HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR);
return;
}
DCHECK(device_id == tether_host_to_connect->GetDeviceId());
const std::string& tether_network_guid =
const std::string tether_network_guid =
device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
device_id);
connect_tethering_operation_ =
......@@ -211,7 +223,10 @@ void TetherConnector::OnTetherHostToConnectFetched(
connect_tethering_operation_->Initialize();
}
void TetherConnector::SetConnectionFailed(const std::string& error_name) {
void TetherConnector::SetConnectionFailed(
const std::string& error_name,
HostConnectionMetricsLogger::ConnectionToHostResult
connection_to_host_result) {
DCHECK(!device_id_pending_connection_.empty());
DCHECK(!error_callback_.is_null());
......@@ -226,6 +241,9 @@ void TetherConnector::SetConnectionFailed(const std::string& error_name) {
error_callback.Run(error_name);
active_host_->SetActiveHostDisconnected();
host_connection_metrics_logger_->RecordConnectionToHostResult(
connection_to_host_result);
}
void TetherConnector::SetConnectionSucceeded(
......@@ -235,6 +253,10 @@ void TetherConnector::SetConnectionSucceeded(
DCHECK(device_id_pending_connection_ == device_id);
DCHECK(!success_callback_.is_null());
host_connection_metrics_logger_->RecordConnectionToHostResult(
HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_SUCCESS);
notification_presenter_->RemoveSetupRequiredNotification();
// Save a copy of the callback before resetting it below.
......@@ -273,13 +295,46 @@ void TetherConnector::OnWifiConnection(const std::string& device_id,
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
<< ".";
SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed);
SetConnectionFailed(
NetworkConnectionHandler::kErrorConnectFailed,
HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT);
return;
}
SetConnectionSucceeded(device_id, wifi_network_guid);
}
HostConnectionMetricsLogger::ConnectionToHostResult
TetherConnector::GetConnectionToHostResultFromErrorCode(
const std::string& device_id,
ConnectTetheringResponse_ResponseCode error_code) {
if (error_code ==
ConnectTetheringResponse_ResponseCode::
ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED) {
return HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_PROVISIONING_FAILED;
}
if (error_code ==
ConnectTetheringResponse_ResponseCode::
ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT) {
const std::string tether_network_guid =
device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
device_id);
if (host_scan_cache_->DoesHostRequireSetup(tether_network_guid)) {
return HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_REQUIRED;
}
return HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_NOT_REQUIRED;
}
return HostConnectionMetricsLogger::ConnectionToHostResult::
CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR;
}
} // namespace tether
} // namespace chromeos
......@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/components/tether/connect_tethering_operation.h"
#include "chromeos/components/tether/host_connection_metrics_logger.h"
#include "chromeos/network/network_connection_handler.h"
namespace chromeos {
......@@ -41,7 +42,8 @@ class TetherConnector : public ConnectTetheringOperation::Observer {
TetherHostResponseRecorder* tether_host_response_recorder,
DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
HostScanCache* host_scan_cache,
NotificationPresenter* notification_presenter);
NotificationPresenter* notification_presenter,
HostConnectionMetricsLogger* host_connection_metrics_logger);
virtual ~TetherConnector();
virtual void ConnectToNetwork(
......@@ -64,7 +66,9 @@ class TetherConnector : public ConnectTetheringOperation::Observer {
private:
friend class TetherConnectorTest;
void SetConnectionFailed(const std::string& error_name);
void SetConnectionFailed(const std::string& error_name,
HostConnectionMetricsLogger::ConnectionToHostResult
connection_to_host_result);
void SetConnectionSucceeded(const std::string& device_id,
const std::string& wifi_network_guid);
......@@ -73,6 +77,10 @@ class TetherConnector : public ConnectTetheringOperation::Observer {
std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect);
void OnWifiConnection(const std::string& device_id,
const std::string& wifi_network_guid);
HostConnectionMetricsLogger::ConnectionToHostResult
GetConnectionToHostResultFromErrorCode(
const std::string& device_id,
ConnectTetheringResponse_ResponseCode error_code);
NetworkConnectionHandler* network_connection_handler_;
NetworkStateHandler* network_state_handler_;
......@@ -84,6 +92,7 @@ class TetherConnector : public ConnectTetheringOperation::Observer {
DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_;
HostScanCache* host_scan_cache_;
NotificationPresenter* notification_presenter_;
HostConnectionMetricsLogger* host_connection_metrics_logger_;
std::string device_id_pending_connection_;
base::Closure success_callback_;
......
......@@ -110,7 +110,8 @@ class TestTetherConnector : public TetherConnector {
nullptr /* tether_host_response_recorder */,
nullptr /* device_id_tether_network_guid_map */,
nullptr /* host_scan_cache */,
nullptr /* notification_presenter */),
nullptr /* notification_presenter */,
nullptr /* host_connection_metrics_logger */),
should_cancel_successfully_(true) {}
~TestTetherConnector() override {}
......
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