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

Side by Side Diff: ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.cc

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

Powered by Google App Engine
This is Rietveld 408576698