OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/ui/ash/tray_bluetooth_helper.h" | 5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.h" |
6 | 6 |
7 #include "ash/common/system/tray/system_tray_delegate.h" | 7 #include "ash/common/system/tray/system_tray_controller.h" |
| 8 #include "ash/common/system/tray/system_tray_delegate.h" // BluetoothDeviceInfo |
8 #include "ash/common/system/tray/system_tray_notifier.h" | 9 #include "ash/common/system/tray/system_tray_notifier.h" |
9 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
13 #include "chrome/browser/ui/ash/system_tray_client.h" | |
14 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 15 #include "device/bluetooth/bluetooth_adapter_factory.h" |
16 #include "device/bluetooth/bluetooth_device.h" | 16 #include "device/bluetooth/bluetooth_device.h" |
17 #include "device/bluetooth/bluetooth_discovery_session.h" | 17 #include "device/bluetooth/bluetooth_discovery_session.h" |
18 | 18 |
| 19 namespace ash { |
19 namespace { | 20 namespace { |
20 | 21 |
21 void BluetoothSetDiscoveringError() { | 22 void BluetoothSetDiscoveringError() { |
22 LOG(ERROR) << "BluetoothSetDiscovering failed."; | 23 LOG(ERROR) << "BluetoothSetDiscovering failed."; |
23 } | 24 } |
24 | 25 |
25 void BluetoothDeviceConnectError( | 26 void BluetoothDeviceConnectError( |
26 device::BluetoothDevice::ConnectErrorCode error_code) {} | 27 device::BluetoothDevice::ConnectErrorCode error_code) {} |
27 | 28 |
28 ash::SystemTrayNotifier* GetSystemTrayNotifier() { | 29 ash::SystemTrayNotifier* GetSystemTrayNotifier() { |
29 return ash::WmShell::Get()->system_tray_notifier(); | 30 return WmShell::Get()->system_tray_notifier(); |
30 } | 31 } |
31 | 32 |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 TrayBluetoothHelper::TrayBluetoothHelper() : weak_ptr_factory_(this) {} | 35 TrayBluetoothHelper::TrayBluetoothHelper() : weak_ptr_factory_(this) {} |
35 | 36 |
36 TrayBluetoothHelper::~TrayBluetoothHelper() { | 37 TrayBluetoothHelper::~TrayBluetoothHelper() { |
37 if (adapter_) | 38 if (adapter_) |
38 adapter_->RemoveObserver(this); | 39 adapter_->RemoveObserver(this); |
39 } | 40 } |
40 | 41 |
41 void TrayBluetoothHelper::Initialize() { | 42 void TrayBluetoothHelper::Initialize() { |
42 device::BluetoothAdapterFactory::GetAdapter( | 43 device::BluetoothAdapterFactory::GetAdapter( |
43 base::Bind(&TrayBluetoothHelper::InitializeOnAdapterReady, | 44 base::Bind(&TrayBluetoothHelper::InitializeOnAdapterReady, |
44 weak_ptr_factory_.GetWeakPtr())); | 45 weak_ptr_factory_.GetWeakPtr())); |
45 } | 46 } |
46 | 47 |
47 void TrayBluetoothHelper::InitializeOnAdapterReady( | 48 void TrayBluetoothHelper::InitializeOnAdapterReady( |
48 scoped_refptr<device::BluetoothAdapter> adapter) { | 49 scoped_refptr<device::BluetoothAdapter> adapter) { |
49 adapter_ = adapter; | 50 adapter_ = adapter; |
50 CHECK(adapter_); | 51 CHECK(adapter_); |
51 adapter_->AddObserver(this); | 52 adapter_->AddObserver(this); |
52 } | 53 } |
53 | 54 |
54 void TrayBluetoothHelper::GetAvailableDevices( | 55 void TrayBluetoothHelper::GetAvailableDevices( |
55 std::vector<ash::BluetoothDeviceInfo>* list) { | 56 std::vector<BluetoothDeviceInfo>* list) { |
56 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 57 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
57 for (device::BluetoothDevice* device : devices) { | 58 for (device::BluetoothDevice* device : devices) { |
58 ash::BluetoothDeviceInfo info; | 59 BluetoothDeviceInfo info; |
59 info.address = device->GetAddress(); | 60 info.address = device->GetAddress(); |
60 info.display_name = device->GetNameForDisplay(); | 61 info.display_name = device->GetNameForDisplay(); |
61 info.connected = device->IsConnected(); | 62 info.connected = device->IsConnected(); |
62 info.connecting = device->IsConnecting(); | 63 info.connecting = device->IsConnecting(); |
63 info.paired = device->IsPaired(); | 64 info.paired = device->IsPaired(); |
64 info.device_type = device->GetDeviceType(); | 65 info.device_type = device->GetDeviceType(); |
65 list->push_back(info); | 66 list->push_back(info); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
(...skipping 30 matching lines...) Expand all Loading... |
99 if (device->IsPaired() && !device->IsConnectable()) | 100 if (device->IsPaired() && !device->IsConnectable()) |
100 return; | 101 return; |
101 if (device->IsPaired() || !device->IsPairable()) { | 102 if (device->IsPaired() || !device->IsPairable()) { |
102 base::RecordAction( | 103 base::RecordAction( |
103 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known")); | 104 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known")); |
104 device->Connect(NULL, base::Bind(&base::DoNothing), | 105 device->Connect(NULL, base::Bind(&base::DoNothing), |
105 base::Bind(&BluetoothDeviceConnectError)); | 106 base::Bind(&BluetoothDeviceConnectError)); |
106 return; | 107 return; |
107 } | 108 } |
108 // Show pairing dialog for the unpaired device. | 109 // Show pairing dialog for the unpaired device. |
109 SystemTrayClient::Get()->ShowBluetoothPairingDialog( | 110 WmShell::Get()->system_tray_controller()->ShowBluetoothPairingDialog( |
110 device->GetAddress(), device->GetNameForDisplay(), device->IsPaired(), | 111 device->GetAddress(), device->GetNameForDisplay(), device->IsPaired(), |
111 device->IsConnected()); | 112 device->IsConnected()); |
112 } | 113 } |
113 | 114 |
114 bool TrayBluetoothHelper::IsDiscovering() const { | 115 bool TrayBluetoothHelper::IsDiscovering() const { |
115 return adapter_ && adapter_->IsDiscovering(); | 116 return adapter_ && adapter_->IsDiscovering(); |
116 } | 117 } |
117 | 118 |
118 void TrayBluetoothHelper::ToggleEnabled() { | 119 void TrayBluetoothHelper::ToggleEnabled() { |
119 adapter_->SetPowered(!adapter_->IsPowered(), base::Bind(&base::DoNothing), | 120 adapter_->SetPowered(!adapter_->IsPowered(), base::Bind(&base::DoNothing), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { | 173 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { |
173 // If the discovery session was returned after a request to stop discovery | 174 // If the discovery session was returned after a request to stop discovery |
174 // (e.g. the user dismissed the Bluetooth detailed view before the call | 175 // (e.g. the user dismissed the Bluetooth detailed view before the call |
175 // returned), don't claim the discovery session and let it clean up. | 176 // returned), don't claim the discovery session and let it clean up. |
176 if (!should_run_discovery_) | 177 if (!should_run_discovery_) |
177 return; | 178 return; |
178 VLOG(1) << "Claiming new Bluetooth device discovery session."; | 179 VLOG(1) << "Claiming new Bluetooth device discovery session."; |
179 discovery_session_ = std::move(discovery_session); | 180 discovery_session_ = std::move(discovery_session); |
180 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged(); | 181 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged(); |
181 } | 182 } |
| 183 |
| 184 } // namespace ash |
OLD | NEW |