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

Side by Side Diff: chrome/browser/ui/ash/tray_bluetooth_helper.cc

Issue 2754143006: cros: Convert SystemTrayDelegate::ManageBluetoothDevices to mojo for mash (Closed)
Patch Set: rebase 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 "chrome/browser/ui/ash/tray_bluetooth_helper.h"
6 6
7 #include "ash/common/system/tray/system_tray_delegate.h" 7 #include "ash/common/system/tray/system_tray_delegate.h"
8 #include "ash/common/system/tray/system_tray_notifier.h" 8 #include "ash/common/system/tray/system_tray_notifier.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
13 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
14 #include "chrome/browser/ui/ash/system_tray_client.h" 13 #include "chrome/browser/ui/ash/system_tray_client.h"
15 #include "device/bluetooth/bluetooth_adapter.h" 14 #include "device/bluetooth/bluetooth_adapter.h"
16 #include "device/bluetooth/bluetooth_adapter_factory.h" 15 #include "device/bluetooth/bluetooth_adapter_factory.h"
17 #include "device/bluetooth/bluetooth_device.h" 16 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_discovery_session.h" 17 #include "device/bluetooth/bluetooth_discovery_session.h"
19 18
20 using chromeos::BluetoothPairingDialog;
21
22 namespace { 19 namespace {
23 20
24 void BluetoothSetDiscoveringError() { 21 void BluetoothSetDiscoveringError() {
25 LOG(ERROR) << "BluetoothSetDiscovering failed."; 22 LOG(ERROR) << "BluetoothSetDiscovering failed.";
26 } 23 }
27 24
28 void BluetoothDeviceConnectError( 25 void BluetoothDeviceConnectError(
29 device::BluetoothDevice::ConnectErrorCode error_code) {} 26 device::BluetoothDevice::ConnectErrorCode error_code) {}
30 27
31 ash::SystemTrayNotifier* GetSystemTrayNotifier() { 28 ash::SystemTrayNotifier* GetSystemTrayNotifier() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (device->IsPaired() && !device->IsConnectable()) 99 if (device->IsPaired() && !device->IsConnectable())
103 return; 100 return;
104 if (device->IsPaired() || !device->IsPairable()) { 101 if (device->IsPaired() || !device->IsPairable()) {
105 base::RecordAction( 102 base::RecordAction(
106 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known")); 103 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
107 device->Connect(NULL, base::Bind(&base::DoNothing), 104 device->Connect(NULL, base::Bind(&base::DoNothing),
108 base::Bind(&BluetoothDeviceConnectError)); 105 base::Bind(&BluetoothDeviceConnectError));
109 return; 106 return;
110 } 107 }
111 // Show pairing dialog for the unpaired device. 108 // Show pairing dialog for the unpaired device.
112 // TODO(jamescook): Move into SystemTrayClient and wire up with mojo. 109 SystemTrayClient::Get()->ShowBluetoothPairingDialog(
113 base::RecordAction( 110 device->GetAddress(), device->GetNameForDisplay(), device->IsPaired(),
114 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown")); 111 device->IsConnected());
115 BluetoothPairingDialog* dialog = new BluetoothPairingDialog(device);
116 // The dialog deletes itself on close.
117 dialog->ShowInContainer(SystemTrayClient::GetDialogParentContainerId());
118 } 112 }
119 113
120 bool TrayBluetoothHelper::IsDiscovering() const { 114 bool TrayBluetoothHelper::IsDiscovering() const {
121 return adapter_ && adapter_->IsDiscovering(); 115 return adapter_ && adapter_->IsDiscovering();
122 } 116 }
123 117
124 void TrayBluetoothHelper::ToggleEnabled() { 118 void TrayBluetoothHelper::ToggleEnabled() {
125 adapter_->SetPowered(!adapter_->IsPowered(), base::Bind(&base::DoNothing), 119 adapter_->SetPowered(!adapter_->IsPowered(), base::Bind(&base::DoNothing),
126 base::Bind(&base::DoNothing)); 120 base::Bind(&base::DoNothing));
127 } 121 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { 172 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) {
179 // If the discovery session was returned after a request to stop discovery 173 // If the discovery session was returned after a request to stop discovery
180 // (e.g. the user dismissed the Bluetooth detailed view before the call 174 // (e.g. the user dismissed the Bluetooth detailed view before the call
181 // returned), don't claim the discovery session and let it clean up. 175 // returned), don't claim the discovery session and let it clean up.
182 if (!should_run_discovery_) 176 if (!should_run_discovery_)
183 return; 177 return;
184 VLOG(1) << "Claiming new Bluetooth device discovery session."; 178 VLOG(1) << "Claiming new Bluetooth device discovery session.";
185 discovery_session_ = std::move(discovery_session); 179 discovery_session_ = std::move(discovery_session);
186 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged(); 180 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
187 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698