Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1062)

Side by Side Diff: chromeos/components/tether/initializer.cc

Issue 2801353002: [CrOS Tether] Fill out the Initializer class. Tether will now initialize fully once the flag is ena… (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
8 #include "chromeos/components/tether/active_host.h"
9 #include "chromeos/components/tether/active_host_network_state_updater.h"
10 #include "chromeos/components/tether/ble_connection_manager.h"
11 #include "chromeos/components/tether/device_id_tether_network_guid_map.h"
12 #include "chromeos/components/tether/host_scan_device_prioritizer.h"
13 #include "chromeos/components/tether/host_scan_scheduler.h"
14 #include "chromeos/components/tether/host_scanner.h"
15 #include "chromeos/components/tether/local_device_data_provider.h"
16 #include "chromeos/components/tether/notification_presenter.h"
17 #include "chromeos/components/tether/tether_connector.h"
18 #include "chromeos/components/tether/tether_host_fetcher.h"
19 #include "chromeos/components/tether/wifi_hotspot_connector.h"
20 #include "components/cryptauth/bluetooth_throttler_impl.h"
21 #include "components/cryptauth/cryptauth_service.h"
22 #include "components/cryptauth/remote_beacon_seed_fetcher.h"
23 #include "components/prefs/pref_service.h"
24 #include "device/bluetooth/bluetooth_adapter.h"
25 #include "device/bluetooth/bluetooth_adapter_factory.h"
26
7 namespace chromeos { 27 namespace chromeos {
8 28
9 namespace tether { 29 namespace tether {
10 30
11 // static 31 // static
12 Initializer* Initializer::instance_ = nullptr; 32 Initializer* Initializer::instance_ = nullptr;
13 33
14 void Initializer::Initialize(cryptauth::CryptAuthService* cryptauth_service) { 34 void Initializer::Initialize(
35 cryptauth::CryptAuthService* cryptauth_service,
36 std::unique_ptr<NotificationPresenter> notification_presenter,
37 PrefService* pref_service) {
38 if (!device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
39 // The tether feature requires BLE hardware support.
40 return;
41 }
42
15 if (instance_) { 43 if (instance_) {
16 // TODO(khorimoto): Determine if a new instance should be created. 44 delete instance_;
17 instance_->cryptauth_service_ = cryptauth_service;
18 } else {
19 instance_ = new Initializer(cryptauth_service);
20 } 45 }
46
47 instance_ = new Initializer(cryptauth_service,
48 std::move(notification_presenter), pref_service);
21 } 49 }
22 50
23 Initializer::Initializer(cryptauth::CryptAuthService* cryptauth_service) 51 Initializer::Initializer(
24 : cryptauth_service_(cryptauth_service) {} 52 cryptauth::CryptAuthService* cryptauth_service,
53 std::unique_ptr<NotificationPresenter> notification_presenter,
54 PrefService* pref_service)
55 : cryptauth_service_(cryptauth_service),
56 notification_presenter_(std::move(notification_presenter)),
57 pref_service_(pref_service),
58 weak_ptr_factory_(this) {
59 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.
60 &Initializer::OnBluetoothAdapterFetched, weak_ptr_factory_.GetWeakPtr()));
61 }
25 62
26 Initializer::~Initializer() {} 63 Initializer::~Initializer() {}
27 64
65 void Initializer::OnBluetoothAdapterFetched(
66 scoped_refptr<device::BluetoothAdapter> adapter) {
67 tether_host_fetcher_ =
68 base::MakeUnique<TetherHostFetcher>(cryptauth_service_);
69 local_device_data_provider_ =
70 base::MakeUnique<LocalDeviceDataProvider>(cryptauth_service_);
71 remote_beacon_seed_fetcher_ =
72 base::MakeUnique<cryptauth::RemoteBeaconSeedFetcher>(
73 cryptauth_service_->GetCryptAuthDeviceManager());
74 ble_connection_manager_ = base::MakeUnique<BleConnectionManager>(
75 cryptauth_service_, adapter, local_device_data_provider_.get(),
76 remote_beacon_seed_fetcher_.get(),
77 cryptauth::BluetoothThrottlerImpl::GetInstance());
78 host_scan_device_prioritizer_ =
79 base::MakeUnique<HostScanDevicePrioritizer>(pref_service_);
80 wifi_hotspot_connector_ = base::MakeUnique<WifiHotspotConnector>();
81 active_host_ =
82 base::MakeUnique<ActiveHost>(tether_host_fetcher_.get(), pref_service_);
83 active_host_network_state_updater_ =
84 base::MakeUnique<ActiveHostNetworkStateUpdater>(active_host_.get());
85 device_id_tether_network_guid_map_ =
86 base::MakeUnique<DeviceIdTetherNetworkGuidMap>();
87 tether_connector_ = base::MakeUnique<TetherConnector>(
88 wifi_hotspot_connector_.get(), active_host_.get(),
89 tether_host_fetcher_.get(), ble_connection_manager_.get(),
90 host_scan_device_prioritizer_.get(),
91 device_id_tether_network_guid_map_.get());
92 host_scanner_ = base::MakeUnique<HostScanner>(
93 tether_host_fetcher_.get(), ble_connection_manager_.get(),
94 host_scan_device_prioritizer_.get(), notification_presenter_.get());
95
96 // TODO(khorimoto): Hook up HostScanScheduler. Currently, we simply start a
97 // new scan once the user logs in.
98 host_scanner_->StartScan();
99 }
100
28 } // namespace tether 101 } // namespace tether
29 102
30 } // namespace chromeos 103 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698