Commit eacb27f8 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Instant Tethering: Remove kMultiDeviceApi flagging from ConnectionPreserverImpl.

R=hansberry@chromium.org

Bug: 903991
Test: none
Change-Id: I37428a83f128c03d95d4eb16d6b36fc8c9a272a5
Reviewed-on: https://chromium-review.googlesource.com/c/1333110
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607488}
parent 262e5e79
......@@ -5,9 +5,7 @@
#include "chromeos/components/tether/connection_preserver_impl.h"
#include "base/timer/timer.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/tether/ble_connection_manager.h"
#include "chromeos/components/tether/tether_host_response_recorder.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
......@@ -27,17 +25,14 @@ const char kTetherFeature[] = "magic_tether";
ConnectionPreserverImpl::ConnectionPreserverImpl(
device_sync::DeviceSyncClient* device_sync_client,
secure_channel::SecureChannelClient* secure_channel_client,
BleConnectionManager* ble_connection_manager,
NetworkStateHandler* network_state_handler,
ActiveHost* active_host,
TetherHostResponseRecorder* tether_host_response_recorder)
: device_sync_client_(device_sync_client),
secure_channel_client_(secure_channel_client),
ble_connection_manager_(ble_connection_manager),
network_state_handler_(network_state_handler),
active_host_(active_host),
tether_host_response_recorder_(tether_host_response_recorder),
request_id_(base::UnguessableToken::Create()),
preserved_connection_timer_(std::make_unique<base::OneShotTimer>()),
weak_ptr_factory_(this) {
active_host_->AddObserver(this);
......@@ -84,7 +79,6 @@ void ConnectionPreserverImpl::HandleSuccessfulTetherAvailabilityResponse(
void ConnectionPreserverImpl::OnConnectionAttemptFailure(
secure_channel::mojom::ConnectionAttemptFailureReason reason) {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
PA_LOG(WARNING) << "Failed to connect to device "
<< cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(
preserved_connection_device_id_)
......@@ -94,7 +88,6 @@ void ConnectionPreserverImpl::OnConnectionAttemptFailure(
void ConnectionPreserverImpl::OnConnection(
std::unique_ptr<secure_channel::ClientChannel> channel) {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
PA_LOG(VERBOSE) << "Successfully preserved connection for device: "
<< cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(
preserved_connection_device_id_);
......@@ -105,7 +98,6 @@ void ConnectionPreserverImpl::OnConnection(
}
void ConnectionPreserverImpl::OnDisconnected() {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
PA_LOG(VERBOSE) << "Remote device disconnected from this device: "
<< cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(
preserved_connection_device_id_);
......@@ -171,27 +163,21 @@ void ConnectionPreserverImpl::SetPreservedConnection(
preserved_connection_device_id_ = device_id;
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
base::Optional<cryptauth::RemoteDeviceRef> remote_device =
GetRemoteDevice(preserved_connection_device_id_);
if (!remote_device) {
PA_LOG(ERROR) << "Given invalid remote device ID: "
<< cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(
preserved_connection_device_id_);
RemovePreservedConnectionIfPresent();
return;
}
connection_attempt_ = secure_channel_client_->ListenForConnectionFromDevice(
*remote_device, *device_sync_client_->GetLocalDeviceMetadata(),
kTetherFeature, secure_channel::ConnectionPriority::kLow);
connection_attempt_->SetDelegate(this);
} else {
ble_connection_manager_->RegisterRemoteDevice(
preserved_connection_device_id_, request_id_,
secure_channel::ConnectionPriority::kLow);
base::Optional<cryptauth::RemoteDeviceRef> remote_device =
GetRemoteDevice(preserved_connection_device_id_);
if (!remote_device) {
PA_LOG(ERROR) << "Given invalid remote device ID: "
<< cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(
preserved_connection_device_id_);
RemovePreservedConnectionIfPresent();
return;
}
connection_attempt_ = secure_channel_client_->ListenForConnectionFromDevice(
*remote_device, *device_sync_client_->GetLocalDeviceMetadata(),
kTetherFeature, secure_channel::ConnectionPriority::kLow);
connection_attempt_->SetDelegate(this);
preserved_connection_timer_->Start(
FROM_HERE, base::TimeDelta::FromSeconds(kTimeoutSeconds),
base::Bind(&ConnectionPreserverImpl::RemovePreservedConnectionIfPresent,
......@@ -207,13 +193,8 @@ void ConnectionPreserverImpl::RemovePreservedConnectionIfPresent() {
preserved_connection_device_id_)
<< ".";
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
connection_attempt_.reset();
client_channel_.reset();
} else {
ble_connection_manager_->UnregisterRemoteDevice(
preserved_connection_device_id_, request_id_);
}
connection_attempt_.reset();
client_channel_.reset();
preserved_connection_device_id_.clear();
preserved_connection_timer_->Stop();
......@@ -221,7 +202,6 @@ void ConnectionPreserverImpl::RemovePreservedConnectionIfPresent() {
base::Optional<cryptauth::RemoteDeviceRef>
ConnectionPreserverImpl::GetRemoteDevice(const std::string device_id) {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
for (const auto& remote_device : device_sync_client_->GetSyncedDevices()) {
if (remote_device.GetDeviceId() == device_id)
return remote_device;
......
......@@ -24,7 +24,6 @@ class NetworkStateHandler;
namespace tether {
class BleConnectionManager;
class SecureChannelClient;
class TetherHostResponseRecorder;
......@@ -44,7 +43,6 @@ class ConnectionPreserverImpl
ConnectionPreserverImpl(
device_sync::DeviceSyncClient* device_sync_client,
secure_channel::SecureChannelClient* secure_channel_client,
BleConnectionManager* ble_connection_manager,
NetworkStateHandler* network_state_handler,
ActiveHost* active_host,
TetherHostResponseRecorder* tether_host_response_recorder);
......@@ -86,11 +84,9 @@ class ConnectionPreserverImpl
device_sync::DeviceSyncClient* device_sync_client_;
secure_channel::SecureChannelClient* secure_channel_client_;
BleConnectionManager* ble_connection_manager_;
NetworkStateHandler* network_state_handler_;
ActiveHost* active_host_;
TetherHostResponseRecorder* tether_host_response_recorder_;
const base::UnguessableToken request_id_;
std::unique_ptr<base::OneShotTimer> preserved_connection_timer_;
......
......@@ -154,7 +154,6 @@ SynchronousShutdownObjectContainerImpl::SynchronousShutdownObjectContainerImpl(
connection_preserver_(std::make_unique<ConnectionPreserverImpl>(
device_sync_client,
secure_channel_client,
asychronous_container->ble_connection_manager(),
network_state_handler_,
active_host_.get(),
tether_host_response_recorder_.get())),
......
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