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

Instant Tethering: Remove kMultiDeviceApi flagging from TetherHostFetcherImpl.

R=hansberry@chromium.org

Bug: 903991
Test: none
Change-Id: I20d5d297c7fdaff8360935818740c483a720ee1a
Reviewed-on: https://chromium-review.googlesource.com/c/1334187
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607806}
parent b03cd9b0
......@@ -29,7 +29,6 @@
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/cryptauth_service.h"
#include "components/cryptauth/remote_device_provider_impl.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
......@@ -147,17 +146,8 @@ TetherService::TetherService(
gms_core_notifications_state_tracker_(
std::make_unique<
chromeos::tether::GmsCoreNotificationsStateTrackerImpl>()),
remote_device_provider_(
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? nullptr
: cryptauth::RemoteDeviceProviderImpl::Factory::NewInstance(
cryptauth_service->GetCryptAuthDeviceManager(),
cryptauth_service->GetAccountId(),
cryptauth_service->GetCryptAuthEnrollmentManager()
->GetUserPrivateKey())),
tether_host_fetcher_(
chromeos::tether::TetherHostFetcherImpl::Factory::NewInstance(
remote_device_provider_.get(),
device_sync_client_,
multidevice_setup_client_)),
timer_(std::make_unique<base::OneShotTimer>()),
......@@ -330,7 +320,6 @@ void TetherService::Shutdown() {
tether_component_.reset();
tether_host_fetcher_.reset();
remote_device_provider_.reset();
notification_presenter_.reset();
}
......
......@@ -39,7 +39,6 @@ class NotificationPresenter;
namespace cryptauth {
class CryptAuthService;
class RemoteDeviceProvider;
} // namespace cryptauth
namespace session_manager {
......@@ -313,7 +312,6 @@ class TetherService
notification_presenter_;
std::unique_ptr<chromeos::tether::GmsCoreNotificationsStateTrackerImpl>
gms_core_notifications_state_tracker_;
std::unique_ptr<cryptauth::RemoteDeviceProvider> remote_device_provider_;
std::unique_ptr<chromeos::tether::TetherHostFetcher> tether_host_fetcher_;
std::unique_ptr<chromeos::tether::TetherComponent> tether_component_;
......
......@@ -247,7 +247,6 @@ class FakeTetherHostFetcherFactory
// chromeos::tether::TetherHostFetcherImpl::Factory :
std::unique_ptr<chromeos::tether::TetherHostFetcher> BuildInstance(
cryptauth::RemoteDeviceProvider* remote_device_provider,
chromeos::device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client) override {
......
......@@ -9,7 +9,6 @@
#include "base/memory/ptr_util.h"
#include "chromeos/chromeos_features.h"
#include "components/cryptauth/remote_device.h"
#include "components/cryptauth/remote_device_provider.h"
namespace chromeos {
......@@ -21,15 +20,14 @@ TetherHostFetcherImpl::Factory*
// static
std::unique_ptr<TetherHostFetcher> TetherHostFetcherImpl::Factory::NewInstance(
cryptauth::RemoteDeviceProvider* remote_device_provider,
device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client) {
if (!factory_instance_) {
factory_instance_ = new Factory();
}
return factory_instance_->BuildInstance(
remote_device_provider, device_sync_client, multidevice_setup_client);
return factory_instance_->BuildInstance(device_sync_client,
multidevice_setup_client);
}
// static
......@@ -39,54 +37,29 @@ void TetherHostFetcherImpl::Factory::SetInstanceForTesting(Factory* factory) {
std::unique_ptr<TetherHostFetcher>
TetherHostFetcherImpl::Factory::BuildInstance(
cryptauth::RemoteDeviceProvider* remote_device_provider,
device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client) {
return base::WrapUnique(new TetherHostFetcherImpl(
remote_device_provider, device_sync_client, multidevice_setup_client));
return base::WrapUnique(
new TetherHostFetcherImpl(device_sync_client, multidevice_setup_client));
}
TetherHostFetcherImpl::TetherHostFetcherImpl(
cryptauth::RemoteDeviceProvider* remote_device_provider,
device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client)
: remote_device_provider_(remote_device_provider),
device_sync_client_(device_sync_client),
: device_sync_client_(device_sync_client),
multidevice_setup_client_(multidevice_setup_client),
weak_ptr_factory_(this) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi))
device_sync_client_->AddObserver(this);
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
multidevice_setup_client_->AddObserver(this);
}
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
!base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
remote_device_provider_->AddObserver(this);
}
device_sync_client_->AddObserver(this);
multidevice_setup_client_->AddObserver(this);
CacheCurrentTetherHosts();
}
TetherHostFetcherImpl::~TetherHostFetcherImpl() {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi))
device_sync_client_->RemoveObserver(this);
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
multidevice_setup_client_->RemoveObserver(this);
}
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
!base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
remote_device_provider_->RemoveObserver(this);
}
device_sync_client_->RemoveObserver(this);
multidevice_setup_client_->RemoveObserver(this);
}
bool TetherHostFetcherImpl::HasSyncedTetherHosts() {
......@@ -105,10 +78,6 @@ void TetherHostFetcherImpl::FetchTetherHost(
callback);
}
void TetherHostFetcherImpl::OnSyncDeviceListChanged() {
CacheCurrentTetherHosts();
}
void TetherHostFetcherImpl::OnNewDevicesSynced() {
CacheCurrentTetherHosts();
}
......@@ -141,7 +110,9 @@ void TetherHostFetcherImpl::CacheCurrentTetherHosts() {
cryptauth::RemoteDeviceRefList TetherHostFetcherImpl::GenerateHostDeviceList() {
cryptauth::RemoteDeviceRefList host_list;
TetherHostSource tether_host_source = GetTetherHostSourceBasedOnFlags();
TetherHostSource tether_host_source =
IsInLegacyHostMode() ? TetherHostSource::DEVICE_SYNC_CLIENT
: TetherHostSource::MULTIDEVICE_SETUP_CLIENT;
if (tether_host_source == TetherHostSource::MULTIDEVICE_SETUP_CLIENT) {
multidevice_setup::MultiDeviceSetupClient::HostStatusWithDevice
......@@ -169,32 +140,13 @@ cryptauth::RemoteDeviceRefList TetherHostFetcherImpl::GenerateHostDeviceList() {
return host_list;
}
if (tether_host_source == TetherHostSource::REMOTE_DEVICE_PROVIDER) {
for (const cryptauth::RemoteDevice& remote_device :
remote_device_provider_->GetSyncedDevices()) {
if (base::ContainsKey(remote_device.software_features,
cryptauth::SoftwareFeature::MAGIC_TETHER_HOST) &&
(remote_device.software_features.at(
cryptauth::SoftwareFeature::MAGIC_TETHER_HOST) ==
cryptauth::SoftwareFeatureState::kSupported ||
remote_device.software_features.at(
cryptauth::SoftwareFeature::MAGIC_TETHER_HOST) ==
cryptauth::SoftwareFeatureState::kEnabled)) {
host_list.push_back(cryptauth::RemoteDeviceRef(
std::make_shared<cryptauth::RemoteDevice>(remote_device)));
}
}
return host_list;
}
NOTREACHED();
return host_list;
}
bool TetherHostFetcherImpl::IsInLegacyHostMode() {
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) ||
!device_sync_client_->is_ready()) {
if (!device_sync_client_->is_ready())
return false;
}
bool has_supported_tether_host = false;
for (const cryptauth::RemoteDeviceRef& remote_device_ref :
......@@ -223,30 +175,6 @@ bool TetherHostFetcherImpl::IsInLegacyHostMode() {
return has_supported_tether_host;
}
TetherHostFetcherImpl::TetherHostSource
TetherHostFetcherImpl::GetTetherHostSourceBasedOnFlags() {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
!base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
return TetherHostSource::DEVICE_SYNC_CLIENT;
}
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
!base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
return TetherHostSource::REMOTE_DEVICE_PROVIDER;
}
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
return IsInLegacyHostMode() ? TetherHostSource::DEVICE_SYNC_CLIENT
: TetherHostSource::MULTIDEVICE_SETUP_CLIENT;
}
NOTREACHED() << "TetherHostFetcherImpl: Unexpected feature flag state of "
<< "kMultiDeviceApi disabled and kEnableUnifiedMultiDeviceSetup "
<< "enabled.";
return TetherHostSource::UNKNOWN;
}
} // namespace tether
} // namespace chromeos
......@@ -13,13 +13,8 @@
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
#include "components/cryptauth/remote_device_provider.h"
#include "components/cryptauth/remote_device_ref.h"
namespace cryptauth {
class RemoteDeviceProvider;
} // namespace cryptauth
namespace chromeos {
namespace tether {
......@@ -28,23 +23,18 @@ namespace tether {
// prototypes, callbacks are invoked synchronously.
//
// Note: TetherHostFetcherImpl, and the Tether feature as a whole, is currently
// in the middle of a migration from using RemoteDeviceProvider to
// DeviceSyncClient and eventually to MultiDeviceSetupClient. Its constructor
// accepts all three objects, but some may be null. (This is controlled at a
// higher level by features::kMultiDeviceApi and
// features::kEnableUnifiedMultiDeviceSetup.). Once Tether has been fully
// migrated, RemoteDeviceProvider and eventually DeviceSyncClient will be ripped
// in the middle of a migration from using DeviceSyncClient and eventually to
// MultiDeviceSetupClient. Its constructor accepts both objects, but either may
// be null. Once Tether has been fully migrated, DeviceSyncClient will be ripped
// out of this class. See https://crbug.com/848956.
class TetherHostFetcherImpl
: public TetherHostFetcher,
public cryptauth::RemoteDeviceProvider::Observer,
public device_sync::DeviceSyncClient::Observer,
public multidevice_setup::MultiDeviceSetupClient::Observer {
public:
class Factory {
public:
static std::unique_ptr<TetherHostFetcher> NewInstance(
cryptauth::RemoteDeviceProvider* remote_device_provider,
device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client);
......@@ -53,7 +43,6 @@ class TetherHostFetcherImpl
protected:
virtual std::unique_ptr<TetherHostFetcher> BuildInstance(
cryptauth::RemoteDeviceProvider* remote_device_provider,
device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client);
......@@ -70,9 +59,6 @@ class TetherHostFetcherImpl
void FetchTetherHost(const std::string& device_id,
const TetherHostCallback& callback) override;
// cryptauth::RemoteDeviceProvider::Observer:
void OnSyncDeviceListChanged() override;
// device_sync::DeviceSyncClient::Observer:
void OnNewDevicesSynced() override;
void OnReady() override;
......@@ -86,10 +72,7 @@ class TetherHostFetcherImpl
feature_states_map) override;
protected:
// TODO(crbug.com/848956): Remove RemoteDeviceProvider once all clients have
// migrated to the DeviceSync Mojo API.
TetherHostFetcherImpl(cryptauth::RemoteDeviceProvider* remote_device_provider,
device_sync::DeviceSyncClient* device_sync_client,
TetherHostFetcherImpl(device_sync::DeviceSyncClient* device_sync_client,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client_);
......@@ -103,7 +86,7 @@ class TetherHostFetcherImpl
void CacheCurrentTetherHosts();
cryptauth::RemoteDeviceRefList GenerateHostDeviceList();
TetherHostSource GetTetherHostSourceBasedOnFlags();
// This returns true if there is no BETTER_TOGETHER_HOST supported or enabled,
// but there *are* MAGIC_TETHER_HOSTs supported or enabled. This can only
// happen if the user's phone has not yet fully updated to the new multidevice
......@@ -111,7 +94,6 @@ class TetherHostFetcherImpl
// TODO(crbug.com/894585): Remove this legacy special case after M71.
bool IsInLegacyHostMode();
cryptauth::RemoteDeviceProvider* remote_device_provider_;
device_sync::DeviceSyncClient* device_sync_client_;
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client_;
......
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