Chromium Code Reviews| Index: chromeos/components/tether/initializer.cc |
| diff --git a/chromeos/components/tether/initializer.cc b/chromeos/components/tether/initializer.cc |
| index cc2d49cfac0046987bd682fc914417da6e87027a..91801775deb2280ef3acf5de4c7da38e631d701c 100644 |
| --- a/chromeos/components/tether/initializer.cc |
| +++ b/chromeos/components/tether/initializer.cc |
| @@ -4,6 +4,26 @@ |
| #include "chromeos/components/tether/initializer.h" |
| +#include "base/bind.h" |
| +#include "chromeos/components/tether/active_host.h" |
| +#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_scan_device_prioritizer.h" |
| +#include "chromeos/components/tether/host_scan_scheduler.h" |
| +#include "chromeos/components/tether/host_scanner.h" |
| +#include "chromeos/components/tether/local_device_data_provider.h" |
| +#include "chromeos/components/tether/notification_presenter.h" |
| +#include "chromeos/components/tether/tether_connector.h" |
| +#include "chromeos/components/tether/tether_host_fetcher.h" |
| +#include "chromeos/components/tether/wifi_hotspot_connector.h" |
| +#include "components/cryptauth/bluetooth_throttler_impl.h" |
| +#include "components/cryptauth/cryptauth_service.h" |
| +#include "components/cryptauth/remote_beacon_seed_fetcher.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_adapter_factory.h" |
| + |
| namespace chromeos { |
| namespace tether { |
| @@ -11,20 +31,73 @@ namespace tether { |
| // static |
| Initializer* Initializer::instance_ = nullptr; |
| -void Initializer::Initialize(cryptauth::CryptAuthService* cryptauth_service) { |
| +void Initializer::Initialize( |
| + cryptauth::CryptAuthService* cryptauth_service, |
| + std::unique_ptr<NotificationPresenter> notification_presenter, |
| + PrefService* pref_service) { |
| + if (!device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
| + // The tether feature requires BLE hardware support. |
| + return; |
| + } |
| + |
| if (instance_) { |
| - // TODO(khorimoto): Determine if a new instance should be created. |
| - instance_->cryptauth_service_ = cryptauth_service; |
| - } else { |
| - instance_ = new Initializer(cryptauth_service); |
| + delete instance_; |
| } |
| + |
| + instance_ = new Initializer(cryptauth_service, |
| + std::move(notification_presenter), pref_service); |
| } |
| -Initializer::Initializer(cryptauth::CryptAuthService* cryptauth_service) |
| - : cryptauth_service_(cryptauth_service) {} |
| +Initializer::Initializer( |
| + cryptauth::CryptAuthService* cryptauth_service, |
| + std::unique_ptr<NotificationPresenter> notification_presenter, |
| + PrefService* pref_service) |
| + : cryptauth_service_(cryptauth_service), |
| + notification_presenter_(std::move(notification_presenter)), |
| + pref_service_(pref_service), |
| + weak_ptr_factory_(this) { |
| + device::BluetoothAdapterFactory::GetAdapter(base::Bind( |
|
Ryan Hansberry
2017/04/07 18:53:40
We unfortunately need one more callback here :) :/
Kyle Horimoto
2017/04/07 23:33:10
Done.
|
| + &Initializer::OnBluetoothAdapterFetched, weak_ptr_factory_.GetWeakPtr())); |
| +} |
| Initializer::~Initializer() {} |
| +void Initializer::OnBluetoothAdapterFetched( |
| + scoped_refptr<device::BluetoothAdapter> adapter) { |
| + tether_host_fetcher_ = |
| + base::MakeUnique<TetherHostFetcher>(cryptauth_service_); |
| + local_device_data_provider_ = |
| + base::MakeUnique<LocalDeviceDataProvider>(cryptauth_service_); |
| + remote_beacon_seed_fetcher_ = |
| + base::MakeUnique<cryptauth::RemoteBeaconSeedFetcher>( |
| + cryptauth_service_->GetCryptAuthDeviceManager()); |
| + ble_connection_manager_ = base::MakeUnique<BleConnectionManager>( |
| + cryptauth_service_, adapter, local_device_data_provider_.get(), |
| + remote_beacon_seed_fetcher_.get(), |
| + cryptauth::BluetoothThrottlerImpl::GetInstance()); |
| + host_scan_device_prioritizer_ = |
| + base::MakeUnique<HostScanDevicePrioritizer>(pref_service_); |
| + wifi_hotspot_connector_ = base::MakeUnique<WifiHotspotConnector>(); |
| + active_host_ = |
| + base::MakeUnique<ActiveHost>(tether_host_fetcher_.get(), pref_service_); |
| + active_host_network_state_updater_ = |
| + base::MakeUnique<ActiveHostNetworkStateUpdater>(active_host_.get()); |
| + device_id_tether_network_guid_map_ = |
| + base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); |
| + tether_connector_ = base::MakeUnique<TetherConnector>( |
| + wifi_hotspot_connector_.get(), active_host_.get(), |
| + tether_host_fetcher_.get(), ble_connection_manager_.get(), |
| + host_scan_device_prioritizer_.get(), |
| + device_id_tether_network_guid_map_.get()); |
| + host_scanner_ = base::MakeUnique<HostScanner>( |
| + tether_host_fetcher_.get(), ble_connection_manager_.get(), |
| + host_scan_device_prioritizer_.get(), notification_presenter_.get()); |
| + |
| + // TODO(khorimoto): Hook up HostScanScheduler. Currently, we simply start a |
| + // new scan once the user logs in. |
| + host_scanner_->StartScan(); |
| +} |
| + |
| } // namespace tether |
| } // namespace chromeos |