| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/initializer.h" | 5 #include "chromeos/components/tether/initializer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chromeos/components/tether/active_host.h" | 8 #include "chromeos/components/tether/active_host.h" |
| 9 #include "chromeos/components/tether/active_host_network_state_updater.h" | 9 #include "chromeos/components/tether/active_host_network_state_updater.h" |
| 10 #include "chromeos/components/tether/ble_connection_manager.h" | 10 #include "chromeos/components/tether/ble_connection_manager.h" |
| 11 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" | 11 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
| 12 #include "chromeos/components/tether/host_scan_device_prioritizer.h" | 12 #include "chromeos/components/tether/host_scan_device_prioritizer.h" |
| 13 #include "chromeos/components/tether/host_scan_scheduler.h" | 13 #include "chromeos/components/tether/host_scan_scheduler.h" |
| 14 #include "chromeos/components/tether/host_scanner.h" | 14 #include "chromeos/components/tether/host_scanner.h" |
| 15 #include "chromeos/components/tether/local_device_data_provider.h" | 15 #include "chromeos/components/tether/local_device_data_provider.h" |
| 16 #include "chromeos/components/tether/network_configuration_remover.h" |
| 16 #include "chromeos/components/tether/notification_presenter.h" | 17 #include "chromeos/components/tether/notification_presenter.h" |
| 17 #include "chromeos/components/tether/tether_connector.h" | 18 #include "chromeos/components/tether/tether_connector.h" |
| 18 #include "chromeos/components/tether/tether_device_state_manager.h" | 19 #include "chromeos/components/tether/tether_device_state_manager.h" |
| 19 #include "chromeos/components/tether/tether_host_fetcher.h" | 20 #include "chromeos/components/tether/tether_host_fetcher.h" |
| 21 #include "chromeos/components/tether/tether_network_disconnection_handler.h" |
| 20 #include "chromeos/components/tether/wifi_hotspot_connector.h" | 22 #include "chromeos/components/tether/wifi_hotspot_connector.h" |
| 23 #include "chromeos/network/managed_network_configuration_handler.h" |
| 21 #include "chromeos/network/network_connect.h" | 24 #include "chromeos/network/network_connect.h" |
| 22 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 23 #include "components/cryptauth/bluetooth_throttler_impl.h" | 26 #include "components/cryptauth/bluetooth_throttler_impl.h" |
| 24 #include "components/cryptauth/cryptauth_service.h" | 27 #include "components/cryptauth/cryptauth_service.h" |
| 25 #include "components/cryptauth/remote_beacon_seed_fetcher.h" | 28 #include "components/cryptauth/remote_beacon_seed_fetcher.h" |
| 26 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
| 27 #include "components/proximity_auth/logging/logging.h" | 30 #include "components/proximity_auth/logging/logging.h" |
| 28 #include "device/bluetooth/bluetooth_adapter.h" | 31 #include "device/bluetooth/bluetooth_adapter.h" |
| 29 #include "device/bluetooth/bluetooth_adapter_factory.h" | 32 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 30 | 33 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 // static | 47 // static |
| 45 Initializer* Initializer::instance_ = nullptr; | 48 Initializer* Initializer::instance_ = nullptr; |
| 46 | 49 |
| 47 // static | 50 // static |
| 48 void Initializer::Init( | 51 void Initializer::Init( |
| 49 cryptauth::CryptAuthService* cryptauth_service, | 52 cryptauth::CryptAuthService* cryptauth_service, |
| 50 std::unique_ptr<NotificationPresenter> notification_presenter, | 53 std::unique_ptr<NotificationPresenter> notification_presenter, |
| 51 PrefService* pref_service, | 54 PrefService* pref_service, |
| 52 ProfileOAuth2TokenService* token_service, | 55 ProfileOAuth2TokenService* token_service, |
| 53 NetworkStateHandler* network_state_handler, | 56 NetworkStateHandler* network_state_handler, |
| 57 ManagedNetworkConfigurationHandler* managed_network_configuration_handler, |
| 54 NetworkConnect* network_connect) { | 58 NetworkConnect* network_connect) { |
| 55 if (!device::BluetoothAdapterFactory::IsBluetoothSupported()) { | 59 if (!device::BluetoothAdapterFactory::IsBluetoothSupported()) { |
| 56 PA_LOG(WARNING) << "Bluetooth is not supported on this device; cannot " | 60 PA_LOG(WARNING) << "Bluetooth is not supported on this device; cannot " |
| 57 << "initialize tether feature."; | 61 << "initialize tether feature."; |
| 58 return; | 62 return; |
| 59 } | 63 } |
| 60 | 64 |
| 61 if (instance_) { | 65 if (instance_) { |
| 62 PA_LOG(WARNING) << "Tether initialization was triggered when the feature " | 66 PA_LOG(WARNING) << "Tether initialization was triggered when the feature " |
| 63 << "had already been initialized; exiting initialization " | 67 << "had already been initialized; exiting initialization " |
| 64 << "early."; | 68 << "early."; |
| 65 return; | 69 return; |
| 66 } | 70 } |
| 67 | 71 |
| 68 instance_ = new Initializer( | 72 instance_ = |
| 69 cryptauth_service, std::move(notification_presenter), pref_service, | 73 new Initializer(cryptauth_service, std::move(notification_presenter), |
| 70 token_service, network_state_handler, network_connect); | 74 pref_service, token_service, network_state_handler, |
| 75 managed_network_configuration_handler, network_connect); |
| 71 } | 76 } |
| 72 | 77 |
| 73 // static | 78 // static |
| 74 void Initializer::Shutdown() { | 79 void Initializer::Shutdown() { |
| 75 if (instance_) { | 80 if (instance_) { |
| 76 PA_LOG(INFO) << "Shutting down tether feature."; | 81 PA_LOG(INFO) << "Shutting down tether feature."; |
| 77 delete instance_; | 82 delete instance_; |
| 78 instance_ = nullptr; | 83 instance_ = nullptr; |
| 79 } | 84 } |
| 80 } | 85 } |
| 81 | 86 |
| 82 // static | 87 // static |
| 83 void Initializer::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 88 void Initializer::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| 84 ActiveHost::RegisterPrefs(registry); | 89 ActiveHost::RegisterPrefs(registry); |
| 85 HostScanDevicePrioritizer::RegisterPrefs(registry); | 90 HostScanDevicePrioritizer::RegisterPrefs(registry); |
| 86 } | 91 } |
| 87 | 92 |
| 88 Initializer::Initializer( | 93 Initializer::Initializer( |
| 89 cryptauth::CryptAuthService* cryptauth_service, | 94 cryptauth::CryptAuthService* cryptauth_service, |
| 90 std::unique_ptr<NotificationPresenter> notification_presenter, | 95 std::unique_ptr<NotificationPresenter> notification_presenter, |
| 91 PrefService* pref_service, | 96 PrefService* pref_service, |
| 92 ProfileOAuth2TokenService* token_service, | 97 ProfileOAuth2TokenService* token_service, |
| 93 NetworkStateHandler* network_state_handler, | 98 NetworkStateHandler* network_state_handler, |
| 99 ManagedNetworkConfigurationHandler* managed_network_configuration_handler, |
| 94 NetworkConnect* network_connect) | 100 NetworkConnect* network_connect) |
| 95 : cryptauth_service_(cryptauth_service), | 101 : cryptauth_service_(cryptauth_service), |
| 96 notification_presenter_(std::move(notification_presenter)), | 102 notification_presenter_(std::move(notification_presenter)), |
| 97 pref_service_(pref_service), | 103 pref_service_(pref_service), |
| 98 token_service_(token_service), | 104 token_service_(token_service), |
| 99 network_state_handler_(network_state_handler), | 105 network_state_handler_(network_state_handler), |
| 106 managed_network_configuration_handler_( |
| 107 managed_network_configuration_handler), |
| 100 network_connect_(network_connect), | 108 network_connect_(network_connect), |
| 101 weak_ptr_factory_(this) { | 109 weak_ptr_factory_(this) { |
| 102 if (!token_service_->RefreshTokenIsAvailable( | 110 if (!token_service_->RefreshTokenIsAvailable( |
| 103 cryptauth_service_->GetAccountId())) { | 111 cryptauth_service_->GetAccountId())) { |
| 104 PA_LOG(INFO) << "Refresh token not yet available; " | 112 PA_LOG(INFO) << "Refresh token not yet available; " |
| 105 << "waiting for valid token to initializing tether feature."; | 113 << "waiting for valid token to initializing tether feature."; |
| 106 token_service_->AddObserver(this); | 114 token_service_->AddObserver(this); |
| 107 return; | 115 return; |
| 108 } | 116 } |
| 109 | 117 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 active_host_network_state_updater_ = | 183 active_host_network_state_updater_ = |
| 176 base::MakeUnique<ActiveHostNetworkStateUpdater>(active_host_.get(), | 184 base::MakeUnique<ActiveHostNetworkStateUpdater>(active_host_.get(), |
| 177 network_state_handler_); | 185 network_state_handler_); |
| 178 device_id_tether_network_guid_map_ = | 186 device_id_tether_network_guid_map_ = |
| 179 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); | 187 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); |
| 180 tether_connector_ = base::MakeUnique<TetherConnector>( | 188 tether_connector_ = base::MakeUnique<TetherConnector>( |
| 181 network_connect_, network_state_handler_, wifi_hotspot_connector_.get(), | 189 network_connect_, network_state_handler_, wifi_hotspot_connector_.get(), |
| 182 active_host_.get(), tether_host_fetcher_.get(), | 190 active_host_.get(), tether_host_fetcher_.get(), |
| 183 ble_connection_manager_.get(), host_scan_device_prioritizer_.get(), | 191 ble_connection_manager_.get(), host_scan_device_prioritizer_.get(), |
| 184 device_id_tether_network_guid_map_.get()); | 192 device_id_tether_network_guid_map_.get()); |
| 193 network_configuration_remover_ = |
| 194 base::MakeUnique<NetworkConfigurationRemover>( |
| 195 network_state_handler_, managed_network_configuration_handler_); |
| 196 tether_network_disconnection_handler_ = |
| 197 base::MakeUnique<TetherNetworkDisconnectionHandler>( |
| 198 active_host_.get(), network_state_handler_, |
| 199 network_configuration_remover_.get()); |
| 185 host_scanner_ = base::MakeUnique<HostScanner>( | 200 host_scanner_ = base::MakeUnique<HostScanner>( |
| 186 tether_host_fetcher_.get(), ble_connection_manager_.get(), | 201 tether_host_fetcher_.get(), ble_connection_manager_.get(), |
| 187 host_scan_device_prioritizer_.get(), network_state_handler_, | 202 host_scan_device_prioritizer_.get(), network_state_handler_, |
| 188 notification_presenter_.get(), device_id_tether_network_guid_map_.get()); | 203 notification_presenter_.get(), device_id_tether_network_guid_map_.get()); |
| 189 | 204 |
| 190 // TODO(khorimoto): Hook up HostScanScheduler. Currently, we simply start a | 205 // TODO(khorimoto): Hook up HostScanScheduler. Currently, we simply start a |
| 191 // new scan once the user logs in. | 206 // new scan once the user logs in. |
| 192 host_scanner_->StartScan(); | 207 host_scanner_->StartScan(); |
| 193 } | 208 } |
| 194 | 209 |
| 195 void Initializer::OnBluetoothAdapterAdvertisingIntervalError( | 210 void Initializer::OnBluetoothAdapterAdvertisingIntervalError( |
| 196 device::BluetoothAdvertisement::ErrorCode status) { | 211 device::BluetoothAdvertisement::ErrorCode status) { |
| 197 PA_LOG(ERROR) << "Failed to set Bluetooth advertisement interval; " | 212 PA_LOG(ERROR) << "Failed to set Bluetooth advertisement interval; " |
| 198 << "cannot use tether feature. Error code: " << status; | 213 << "cannot use tether feature. Error code: " << status; |
| 199 } | 214 } |
| 200 | 215 |
| 201 } // namespace tether | 216 } // namespace tether |
| 202 | 217 |
| 203 } // namespace chromeos | 218 } // namespace chromeos |
| OLD | NEW |