Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/bluetooth/bluetooth_device.h" | 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 20 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" |
| 21 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" | 21 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" |
| 22 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" | 22 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h" |
| 23 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" | 23 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chromeos/dbus/bluetooth_adapter_client.h" | 25 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 26 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 26 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
| 27 #include "chromeos/dbus/bluetooth_device_client.h" | 27 #include "chromeos/dbus/bluetooth_device_client.h" |
| 28 #include "chromeos/dbus/bluetooth_input_client.h" | 28 #include "chromeos/dbus/bluetooth_input_client.h" |
| 29 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | 29 #include "chromeos/dbus/bluetooth_out_of_band_client.h" |
| 30 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" | |
| 30 #include "chromeos/dbus/dbus_thread_manager.h" | 31 #include "chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "chromeos/dbus/introspectable_client.h" | 32 #include "chromeos/dbus/introspectable_client.h" |
| 32 #include "dbus/bus.h" | 33 #include "dbus/bus.h" |
| 33 #include "dbus/object_path.h" | 34 #include "dbus/object_path.h" |
| 34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 35 #include "third_party/cros_system_api/dbus/service_constants.h" | 36 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 | 38 |
| 38 namespace chromeos { | 39 namespace chromeos { |
| 39 | 40 |
| 40 BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter) | 41 BluetoothDeviceChromeOs::BluetoothDeviceChromeOs( |
| 41 : adapter_(adapter), | 42 BluetoothAdapterChromeOs* adapter) |
| 42 bluetooth_class_(0), | 43 : BluetoothDevice(), |
| 44 adapter_(adapter), | |
| 43 visible_(false), | 45 visible_(false), |
| 44 bonded_(false), | 46 bonded_(false), |
| 45 connected_(false), | 47 connected_(false), |
| 46 pairing_delegate_(NULL), | 48 pairing_delegate_(NULL), |
| 47 connecting_applications_counter_(0), | 49 connecting_applications_counter_(0), |
| 48 weak_ptr_factory_(this) { | 50 weak_ptr_factory_(this) { |
| 49 } | 51 } |
| 50 | 52 |
| 51 BluetoothDevice::~BluetoothDevice() { | 53 BluetoothDeviceChromeOs::~BluetoothDeviceChromeOs() { |
| 52 } | 54 } |
| 53 | 55 |
| 54 const std::string& BluetoothDevice::address() const { return address_; } | 56 const std::string& BluetoothDeviceChromeOs::address() const { return address_; } |
| 55 | 57 |
| 56 string16 BluetoothDevice::GetName() const { | 58 string16 BluetoothDeviceChromeOs::GetName() const { |
| 57 if (!name_.empty()) { | 59 if (!name_.empty()) { |
| 58 return UTF8ToUTF16(name_); | 60 return UTF8ToUTF16(name_); |
| 59 } else { | 61 } else { |
| 60 return GetAddressWithLocalizedDeviceTypeName(); | 62 return GetAddressWithLocalizedDeviceTypeName(); |
| 61 } | 63 } |
| 62 } | 64 } |
|
keybuk
2012/09/17 22:19:43
should move up to BluetoothDevice since it'll be t
youngki
2012/09/18 18:19:56
Done.
| |
| 63 | 65 |
| 64 BluetoothDevice::DeviceType BluetoothDevice::GetDeviceType() const { | 66 string16 |
| 65 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm | 67 BluetoothDeviceChromeOs::GetAddressWithLocalizedDeviceTypeName() const { |
| 66 switch ((bluetooth_class_ & 0x1f00) >> 8) { | |
| 67 case 0x01: | |
| 68 // Computer major device class. | |
| 69 return DEVICE_COMPUTER; | |
| 70 case 0x02: | |
| 71 // Phone major device class. | |
| 72 switch ((bluetooth_class_ & 0xfc) >> 2) { | |
| 73 case 0x01: | |
| 74 case 0x02: | |
| 75 case 0x03: | |
| 76 // Cellular, cordless and smart phones. | |
| 77 return DEVICE_PHONE; | |
| 78 case 0x04: | |
| 79 case 0x05: | |
| 80 // Modems: wired or voice gateway and common ISDN access. | |
| 81 return DEVICE_MODEM; | |
| 82 } | |
| 83 break; | |
| 84 case 0x05: | |
| 85 // Peripheral major device class. | |
| 86 switch ((bluetooth_class_ & 0xc0) >> 6) { | |
| 87 case 0x00: | |
| 88 // "Not a keyboard or pointing device." | |
| 89 switch ((bluetooth_class_ & 0x01e) >> 2) { | |
| 90 case 0x01: | |
| 91 // Joystick. | |
| 92 return DEVICE_JOYSTICK; | |
| 93 case 0x02: | |
| 94 // Gamepad. | |
| 95 return DEVICE_GAMEPAD; | |
| 96 default: | |
| 97 return DEVICE_PERIPHERAL; | |
| 98 } | |
| 99 break; | |
| 100 case 0x01: | |
| 101 // Keyboard. | |
| 102 return DEVICE_KEYBOARD; | |
| 103 case 0x02: | |
| 104 // Pointing device. | |
| 105 switch ((bluetooth_class_ & 0x01e) >> 2) { | |
| 106 case 0x05: | |
| 107 // Digitizer tablet. | |
| 108 return DEVICE_TABLET; | |
| 109 default: | |
| 110 // Mouse. | |
| 111 return DEVICE_MOUSE; | |
| 112 } | |
| 113 break; | |
| 114 case 0x03: | |
| 115 // Combo device. | |
| 116 return DEVICE_KEYBOARD_MOUSE_COMBO; | |
| 117 } | |
| 118 break; | |
| 119 } | |
| 120 | |
| 121 return DEVICE_UNKNOWN; | |
| 122 } | |
| 123 | |
| 124 string16 BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const { | |
| 125 string16 address = UTF8ToUTF16(address_); | 68 string16 address = UTF8ToUTF16(address_); |
| 126 DeviceType device_type = GetDeviceType(); | 69 BluetoothDevice::DeviceType device_type = GetDeviceType(); |
| 127 switch (device_type) { | 70 switch (device_type) { |
| 128 case DEVICE_COMPUTER: | 71 case DEVICE_COMPUTER: |
| 129 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER, | 72 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER, |
| 130 address); | 73 address); |
| 131 case DEVICE_PHONE: | 74 case DEVICE_PHONE: |
| 132 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE, | 75 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE, |
| 133 address); | 76 address); |
| 134 case DEVICE_MODEM: | 77 case DEVICE_MODEM: |
| 135 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM, | 78 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM, |
| 136 address); | 79 address); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 148 address); | 91 address); |
| 149 case DEVICE_TABLET: | 92 case DEVICE_TABLET: |
| 150 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET, | 93 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET, |
| 151 address); | 94 address); |
| 152 case DEVICE_KEYBOARD_MOUSE_COMBO: | 95 case DEVICE_KEYBOARD_MOUSE_COMBO: |
| 153 return l10n_util::GetStringFUTF16( | 96 return l10n_util::GetStringFUTF16( |
| 154 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address); | 97 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address); |
| 155 default: | 98 default: |
| 156 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN, address); | 99 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN, address); |
| 157 } | 100 } |
| 158 } | 101 } |
|
keybuk
2012/09/17 22:19:43
I'm tempted to say that this should move up into B
youngki
2012/09/18 18:19:56
Done.
| |
| 159 | 102 |
| 160 bool BluetoothDevice::IsSupported() const { | 103 bool BluetoothDeviceChromeOs::IsSupported() const { |
| 161 if (CommandLine::ForCurrentProcess()->HasSwitch( | 104 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 162 switches::kEnableUnsupportedBluetoothDevices)) | 105 switches::kEnableUnsupportedBluetoothDevices)) |
| 163 return true; | 106 return true; |
| 164 | 107 |
| 165 DeviceType device_type = GetDeviceType(); | 108 BluetoothDevice::DeviceType device_type = GetDeviceType(); |
| 166 return (device_type == DEVICE_JOYSTICK || | 109 return (device_type == DEVICE_JOYSTICK || |
| 167 device_type == DEVICE_GAMEPAD || | 110 device_type == DEVICE_GAMEPAD || |
| 168 device_type == DEVICE_KEYBOARD || | 111 device_type == DEVICE_KEYBOARD || |
| 169 device_type == DEVICE_MOUSE || | 112 device_type == DEVICE_MOUSE || |
| 170 device_type == DEVICE_TABLET || | 113 device_type == DEVICE_TABLET || |
| 171 device_type == DEVICE_KEYBOARD_MOUSE_COMBO); | 114 device_type == DEVICE_KEYBOARD_MOUSE_COMBO); |
| 172 } | 115 } |
| 173 | 116 |
|
keybuk
2012/09/17 22:19:43
this should stay in BluetoothDeviceChromeOs
youngki
2012/09/18 18:19:56
Yep IsSupported() is already Chrome OS specific.
| |
| 174 bool BluetoothDevice::IsPaired() const { return !object_path_.value().empty(); } | 117 bool BluetoothDeviceChromeOs::IsPaired() const { |
| 118 return !object_path_.value().empty(); | |
| 119 } | |
| 175 | 120 |
| 176 bool BluetoothDevice::IsBonded() const { return bonded_; } | 121 bool BluetoothDeviceChromeOs::IsBonded() const { return bonded_; } |
| 177 | 122 |
| 178 bool BluetoothDevice::IsConnected() const { | 123 bool BluetoothDeviceChromeOs::IsConnected() const { |
| 179 // TODO(keybuk): examine protocol-specific connected state, such as Input | 124 // TODO(keybuk): examine protocol-specific connected state, such as Input |
| 180 return connected_; | 125 return connected_; |
| 181 } | 126 } |
|
keybuk
2012/09/17 22:19:43
Can we not move all these up into BluetoothDevice?
youngki
2012/09/18 18:19:56
Moved IsVisible(), IsBonded(), and IsConnected() t
| |
| 182 | 127 |
| 183 void BluetoothDevice::GetServiceRecords(const ServiceRecordsCallback& callback, | 128 void BluetoothDeviceChromeOs::GetServiceRecords( |
| 184 const ErrorCallback& error_callback) { | 129 const ServiceRecordsCallback& callback, |
| 130 const ErrorCallback& error_callback) { | |
| 185 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 131 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 186 DiscoverServices( | 132 DiscoverServices( |
| 187 object_path_, | 133 object_path_, |
| 188 "", // empty pattern to browse all services | 134 "", // empty pattern to browse all services |
| 189 base::Bind(&BluetoothDevice::CollectServiceRecordsCallback, | 135 base::Bind(&BluetoothDeviceChromeOs::CollectServiceRecordsCallback, |
| 190 weak_ptr_factory_.GetWeakPtr(), | 136 weak_ptr_factory_.GetWeakPtr(), |
| 191 callback, | 137 callback, |
| 192 error_callback)); | 138 error_callback)); |
| 193 } | 139 } |
| 194 | 140 |
| 195 bool BluetoothDevice::ProvidesServiceWithUUID(const std::string& uuid) const { | 141 bool BluetoothDeviceChromeOs::ProvidesServiceWithUUID( |
| 196 const BluetoothDevice::ServiceList& services = GetServices(); | 142 const std::string& uuid) const { |
| 197 for (BluetoothDevice::ServiceList::const_iterator iter = services.begin(); | 143 const BluetoothDeviceChromeOs::ServiceList& services = GetServices(); |
| 198 iter != services.end(); ++iter) { | 144 for (BluetoothDeviceChromeOs::ServiceList::const_iterator iter = |
| 145 services.begin(); | |
| 146 iter != services.end(); ++iter) { | |
| 199 if (bluetooth_utils::CanonicalUuid(*iter) == uuid) | 147 if (bluetooth_utils::CanonicalUuid(*iter) == uuid) |
| 200 return true; | 148 return true; |
| 201 } | 149 } |
| 202 return false; | 150 return false; |
| 203 } | 151 } |
| 204 | 152 |
| 205 void BluetoothDevice::ProvidesServiceWithName(const std::string& name, | 153 void BluetoothDeviceChromeOs::ProvidesServiceWithName( |
| 154 const std::string& name, | |
| 206 const ProvidesServiceCallback& callback) { | 155 const ProvidesServiceCallback& callback) { |
| 207 GetServiceRecords( | 156 GetServiceRecords( |
| 208 base::Bind(&BluetoothDevice::SearchServicesForNameCallback, | 157 base::Bind(&BluetoothDeviceChromeOs::SearchServicesForNameCallback, |
| 209 weak_ptr_factory_.GetWeakPtr(), | 158 weak_ptr_factory_.GetWeakPtr(), |
| 210 name, | 159 name, |
| 211 callback), | 160 callback), |
| 212 base::Bind(&BluetoothDevice::SearchServicesForNameErrorCallback, | 161 base::Bind(&BluetoothDeviceChromeOs::SearchServicesForNameErrorCallback, |
| 213 weak_ptr_factory_.GetWeakPtr(), | 162 weak_ptr_factory_.GetWeakPtr(), |
| 214 callback)); | 163 callback)); |
| 215 } | 164 } |
| 216 | 165 |
| 217 void BluetoothDevice::Connect(PairingDelegate* pairing_delegate, | 166 bool BluetoothDeviceChromeOs::ExpectingPinCode() const { |
| 218 const base::Closure& callback, | 167 return !pincode_callback_.is_null(); |
| 219 const ErrorCallback& error_callback) { | 168 } |
| 169 | |
| 170 bool BluetoothDeviceChromeOs::ExpectingPasskey() const { | |
| 171 return !passkey_callback_.is_null(); | |
| 172 } | |
| 173 | |
| 174 void BluetoothDeviceChromeOs::Connect(PairingDelegate* pairing_delegate, | |
| 175 const base::Closure& callback, | |
| 176 const ErrorCallback& error_callback) { | |
| 220 if (IsPaired() || IsBonded() || IsConnected()) { | 177 if (IsPaired() || IsBonded() || IsConnected()) { |
| 221 // Connection to already paired or connected device. | 178 // Connection to already paired or connected device. |
| 222 ConnectApplications(callback, error_callback); | 179 ConnectApplications(callback, error_callback); |
| 223 | 180 |
| 224 } else if (!pairing_delegate) { | 181 } else if (!pairing_delegate) { |
| 225 // No pairing delegate supplied, initiate low-security connection only. | 182 // No pairing delegate supplied, initiate low-security connection only. |
| 226 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 183 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 227 CreateDevice(adapter_->object_path_, | 184 CreateDevice(adapter_->object_path_, |
| 228 address_, | 185 address_, |
| 229 base::Bind(&BluetoothDevice::ConnectCallback, | 186 base::Bind(&BluetoothDeviceChromeOs::ConnectCallback, |
| 230 weak_ptr_factory_.GetWeakPtr(), | 187 weak_ptr_factory_.GetWeakPtr(), |
| 231 callback, | 188 callback, |
| 232 error_callback), | 189 error_callback), |
| 233 base::Bind(&BluetoothDevice::ConnectErrorCallback, | 190 base::Bind(&BluetoothDeviceChromeOs::ConnectErrorCallback, |
| 234 weak_ptr_factory_.GetWeakPtr(), | 191 weak_ptr_factory_.GetWeakPtr(), |
| 235 error_callback)); | 192 error_callback)); |
| 236 } else { | 193 } else { |
| 237 // Initiate high-security connection with pairing. | 194 // Initiate high-security connection with pairing. |
| 238 DCHECK(!pairing_delegate_); | 195 DCHECK(!pairing_delegate_); |
| 239 pairing_delegate_ = pairing_delegate; | 196 pairing_delegate_ = pairing_delegate; |
| 240 | 197 |
| 241 // The agent path is relatively meaningless, we use the device address | 198 // The agent path is relatively meaningless, we use the device address |
| 242 // to generate it as we only support one pairing attempt at a time for | 199 // to generate it as we only support one pairing attempt at a time for |
| 243 // a given bluetooth device. | 200 // a given bluetooth device. |
| 244 DCHECK(agent_.get() == NULL); | 201 DCHECK(agent_.get() == NULL); |
| 245 | 202 |
| 246 std::string agent_path_basename; | 203 std::string agent_path_basename; |
| 247 ReplaceChars(address_, ":", "_", &agent_path_basename); | 204 ReplaceChars(address_, ":", "_", &agent_path_basename); |
| 248 dbus::ObjectPath agent_path("/org/chromium/bluetooth_agent/" + | 205 dbus::ObjectPath agent_path("/org/chromium/bluetooth_agent/" + |
| 249 agent_path_basename); | 206 agent_path_basename); |
| 250 | 207 |
| 251 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 208 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
| 252 if (system_bus) { | 209 if (system_bus) { |
| 253 agent_.reset(BluetoothAgentServiceProvider::Create(system_bus, | 210 agent_.reset(BluetoothAgentServiceProvider::Create(system_bus, |
| 254 agent_path, | 211 agent_path, |
| 255 this)); | 212 this)); |
| 256 } else { | 213 } else { |
| 257 agent_.reset(NULL); | 214 agent_.reset(NULL); |
| 258 } | 215 } |
| 259 | 216 |
| 260 DVLOG(1) << "Pairing: " << address_; | 217 DVLOG(1) << "Pairing: " << address_; |
| 261 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 218 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 262 CreatePairedDevice(adapter_->object_path_, | 219 CreatePairedDevice( |
| 263 address_, | 220 adapter_->object_path_, |
| 264 agent_path, | 221 address_, |
| 265 bluetooth_agent::kDisplayYesNoCapability, | 222 agent_path, |
| 266 base::Bind(&BluetoothDevice::ConnectCallback, | 223 bluetooth_agent::kDisplayYesNoCapability, |
| 267 weak_ptr_factory_.GetWeakPtr(), | 224 base::Bind(&BluetoothDeviceChromeOs::ConnectCallback, |
| 268 callback, | 225 weak_ptr_factory_.GetWeakPtr(), |
| 269 error_callback), | 226 callback, |
| 270 base::Bind(&BluetoothDevice::ConnectErrorCallback, | 227 error_callback), |
| 271 weak_ptr_factory_.GetWeakPtr(), | 228 base::Bind(&BluetoothDeviceChromeOs::ConnectErrorCallback, |
| 272 error_callback)); | 229 weak_ptr_factory_.GetWeakPtr(), |
| 230 error_callback)); | |
| 273 } | 231 } |
| 274 } | 232 } |
| 275 | 233 |
| 276 void BluetoothDevice::SetPinCode(const std::string& pincode) { | 234 void BluetoothDeviceChromeOs::SetPinCode(const std::string& pincode) { |
| 277 if (!agent_.get() || pincode_callback_.is_null()) | 235 if (!agent_.get() || pincode_callback_.is_null()) |
| 278 return; | 236 return; |
| 279 | 237 |
| 280 pincode_callback_.Run(SUCCESS, pincode); | 238 pincode_callback_.Run(SUCCESS, pincode); |
| 281 pincode_callback_.Reset(); | 239 pincode_callback_.Reset(); |
| 282 } | 240 } |
| 283 | 241 |
| 284 void BluetoothDevice::SetPasskey(uint32 passkey) { | 242 void BluetoothDeviceChromeOs::SetPasskey(uint32 passkey) { |
| 285 if (!agent_.get() || passkey_callback_.is_null()) | 243 if (!agent_.get() || passkey_callback_.is_null()) |
| 286 return; | 244 return; |
| 287 | 245 |
| 288 passkey_callback_.Run(SUCCESS, passkey); | 246 passkey_callback_.Run(SUCCESS, passkey); |
| 289 passkey_callback_.Reset(); | 247 passkey_callback_.Reset(); |
| 290 } | 248 } |
| 291 | 249 |
| 292 void BluetoothDevice::ConfirmPairing() { | 250 void BluetoothDeviceChromeOs::ConfirmPairing() { |
| 293 if (!agent_.get() || confirmation_callback_.is_null()) | 251 if (!agent_.get() || confirmation_callback_.is_null()) |
| 294 return; | 252 return; |
| 295 | 253 |
| 296 confirmation_callback_.Run(SUCCESS); | 254 confirmation_callback_.Run(SUCCESS); |
| 297 confirmation_callback_.Reset(); | 255 confirmation_callback_.Reset(); |
| 298 } | 256 } |
| 299 | 257 |
| 300 void BluetoothDevice::RejectPairing() { | 258 void BluetoothDeviceChromeOs::RejectPairing() { |
| 301 if (!agent_.get()) | 259 if (!agent_.get()) |
| 302 return; | 260 return; |
| 303 | 261 |
| 304 if (!pincode_callback_.is_null()) { | 262 if (!pincode_callback_.is_null()) { |
| 305 pincode_callback_.Run(REJECTED, ""); | 263 pincode_callback_.Run(REJECTED, ""); |
| 306 pincode_callback_.Reset(); | 264 pincode_callback_.Reset(); |
| 307 } | 265 } |
| 308 if (!passkey_callback_.is_null()) { | 266 if (!passkey_callback_.is_null()) { |
| 309 passkey_callback_.Run(REJECTED, 0); | 267 passkey_callback_.Run(REJECTED, 0); |
| 310 passkey_callback_.Reset(); | 268 passkey_callback_.Reset(); |
| 311 } | 269 } |
| 312 if (!confirmation_callback_.is_null()) { | 270 if (!confirmation_callback_.is_null()) { |
| 313 confirmation_callback_.Run(REJECTED); | 271 confirmation_callback_.Run(REJECTED); |
| 314 confirmation_callback_.Reset(); | 272 confirmation_callback_.Reset(); |
| 315 } | 273 } |
| 316 } | 274 } |
| 317 | 275 |
| 318 void BluetoothDevice::CancelPairing() { | 276 void BluetoothDeviceChromeOs::CancelPairing() { |
| 319 if (!agent_.get()) | 277 if (!agent_.get()) |
| 320 return; | 278 return; |
| 321 | 279 |
| 322 if (!pincode_callback_.is_null()) { | 280 if (!pincode_callback_.is_null()) { |
| 323 pincode_callback_.Run(CANCELLED, ""); | 281 pincode_callback_.Run(CANCELLED, ""); |
| 324 pincode_callback_.Reset(); | 282 pincode_callback_.Reset(); |
| 325 } | 283 } |
| 326 if (!passkey_callback_.is_null()) { | 284 if (!passkey_callback_.is_null()) { |
| 327 passkey_callback_.Run(CANCELLED, 0); | 285 passkey_callback_.Run(CANCELLED, 0); |
| 328 passkey_callback_.Reset(); | 286 passkey_callback_.Reset(); |
| 329 } | 287 } |
| 330 if (!confirmation_callback_.is_null()) { | 288 if (!confirmation_callback_.is_null()) { |
| 331 confirmation_callback_.Run(CANCELLED); | 289 confirmation_callback_.Run(CANCELLED); |
| 332 confirmation_callback_.Reset(); | 290 confirmation_callback_.Reset(); |
| 333 } | 291 } |
| 334 } | 292 } |
| 335 | 293 |
| 336 void BluetoothDevice::Disconnect(const base::Closure& callback, | 294 void BluetoothDeviceChromeOs::Disconnect(const base::Closure& callback, |
| 337 const ErrorCallback& error_callback) { | 295 const ErrorCallback& error_callback) { |
| 338 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 296 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 339 Disconnect(object_path_, | 297 Disconnect(object_path_, |
| 340 base::Bind(&BluetoothDevice::DisconnectCallback, | 298 base::Bind(&BluetoothDeviceChromeOs::DisconnectCallback, |
| 341 weak_ptr_factory_.GetWeakPtr(), | 299 weak_ptr_factory_.GetWeakPtr(), |
| 342 callback, | 300 callback, |
| 343 error_callback)); | 301 error_callback)); |
| 344 | 302 |
| 345 } | 303 } |
| 346 | 304 |
| 347 void BluetoothDevice::Forget(const ErrorCallback& error_callback) { | 305 void BluetoothDeviceChromeOs::Forget(const ErrorCallback& error_callback) { |
| 348 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 306 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 349 RemoveDevice(adapter_->object_path_, | 307 RemoveDevice(adapter_->object_path_, |
| 350 object_path_, | 308 object_path_, |
| 351 base::Bind(&BluetoothDevice::ForgetCallback, | 309 base::Bind(&BluetoothDeviceChromeOs::ForgetCallback, |
| 352 weak_ptr_factory_.GetWeakPtr(), | 310 weak_ptr_factory_.GetWeakPtr(), |
| 353 error_callback)); | 311 error_callback)); |
| 354 } | 312 } |
| 355 | 313 |
| 356 void BluetoothDevice::ConnectToService(const std::string& service_uuid, | 314 void BluetoothDeviceChromeOs::ConnectToService(const std::string& service_uuid, |
| 357 const SocketCallback& callback) { | 315 const SocketCallback& callback) { |
| 358 GetServiceRecords( | 316 GetServiceRecords( |
| 359 base::Bind(&BluetoothDevice::GetServiceRecordsForConnectCallback, | 317 base::Bind(&BluetoothDeviceChromeOs::GetServiceRecordsForConnectCallback, |
| 360 weak_ptr_factory_.GetWeakPtr(), | 318 weak_ptr_factory_.GetWeakPtr(), |
| 361 service_uuid, | 319 service_uuid, |
| 362 callback), | 320 callback), |
| 363 base::Bind(&BluetoothDevice::GetServiceRecordsForConnectErrorCallback, | 321 base::Bind( |
| 364 weak_ptr_factory_.GetWeakPtr(), | 322 &BluetoothDeviceChromeOs::GetServiceRecordsForConnectErrorCallback, |
| 365 callback)); | 323 weak_ptr_factory_.GetWeakPtr(), |
| 324 callback)); | |
| 366 } | 325 } |
| 367 | 326 |
| 368 void BluetoothDevice::SetOutOfBandPairingData( | 327 void BluetoothDeviceChromeOs::SetOutOfBandPairingData( |
| 369 const chromeos::BluetoothOutOfBandPairingData& data, | 328 const chromeos::BluetoothOutOfBandPairingData& data, |
| 370 const base::Closure& callback, | 329 const base::Closure& callback, |
| 371 const ErrorCallback& error_callback) { | 330 const ErrorCallback& error_callback) { |
| 372 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> | 331 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> |
| 373 AddRemoteData( | 332 AddRemoteData( |
| 374 object_path_, | 333 object_path_, |
| 375 address(), | 334 address(), |
| 376 data, | 335 data, |
| 377 base::Bind(&BluetoothDevice::OnRemoteDataCallback, | 336 base::Bind(&BluetoothDeviceChromeOs::OnRemoteDataCallback, |
| 378 weak_ptr_factory_.GetWeakPtr(), | 337 weak_ptr_factory_.GetWeakPtr(), |
| 379 callback, | 338 callback, |
| 380 error_callback)); | 339 error_callback)); |
| 381 } | 340 } |
| 382 | 341 |
| 383 void BluetoothDevice::ClearOutOfBandPairingData( | 342 void BluetoothDeviceChromeOs::ClearOutOfBandPairingData( |
| 384 const base::Closure& callback, | 343 const base::Closure& callback, |
| 385 const ErrorCallback& error_callback) { | 344 const ErrorCallback& error_callback) { |
| 386 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> | 345 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> |
| 387 RemoveRemoteData( | 346 RemoveRemoteData( |
| 388 object_path_, | 347 object_path_, |
| 389 address(), | 348 address(), |
| 390 base::Bind(&BluetoothDevice::OnRemoteDataCallback, | 349 base::Bind(&BluetoothDeviceChromeOs::OnRemoteDataCallback, |
| 391 weak_ptr_factory_.GetWeakPtr(), | 350 weak_ptr_factory_.GetWeakPtr(), |
| 392 callback, | 351 callback, |
| 393 error_callback)); | 352 error_callback)); |
| 394 } | 353 } |
| 395 | 354 |
| 396 void BluetoothDevice::SetObjectPath(const dbus::ObjectPath& object_path) { | 355 void BluetoothDeviceChromeOs::SetObjectPath( |
| 356 const dbus::ObjectPath& object_path) { | |
| 397 DCHECK(object_path_ == dbus::ObjectPath("")); | 357 DCHECK(object_path_ == dbus::ObjectPath("")); |
| 398 object_path_ = object_path; | 358 object_path_ = object_path; |
| 399 } | 359 } |
| 400 | 360 |
| 401 void BluetoothDevice::RemoveObjectPath() { | 361 void BluetoothDeviceChromeOs::RemoveObjectPath() { |
| 402 DCHECK(object_path_ != dbus::ObjectPath("")); | 362 DCHECK(object_path_ != dbus::ObjectPath("")); |
| 403 object_path_ = dbus::ObjectPath(""); | 363 object_path_ = dbus::ObjectPath(""); |
| 404 } | 364 } |
| 405 | 365 |
| 406 void BluetoothDevice::Update( | 366 void BluetoothDeviceChromeOs::Update( |
| 407 const BluetoothDeviceClient::Properties* properties, | 367 const BluetoothDeviceClient::Properties* properties, |
| 408 bool update_state) { | 368 bool update_state) { |
| 409 std::string address = properties->address.value(); | 369 std::string address = properties->address.value(); |
| 410 std::string name = properties->name.value(); | 370 std::string name = properties->name.value(); |
| 411 uint32 bluetooth_class = properties->bluetooth_class.value(); | 371 uint32 bluetooth_class = properties->bluetooth_class.value(); |
| 412 const std::vector<std::string>& uuids = properties->uuids.value(); | 372 const std::vector<std::string>& uuids = properties->uuids.value(); |
| 413 | 373 |
| 414 if (!address.empty()) | 374 if (!address.empty()) |
| 415 address_ = address; | 375 address_ = address; |
| 416 if (!name.empty()) | 376 if (!name.empty()) |
| 417 name_ = name; | 377 name_ = name; |
| 418 if (bluetooth_class) | 378 if (bluetooth_class) |
| 419 bluetooth_class_ = bluetooth_class; | 379 bluetooth_class_ = bluetooth_class; |
| 420 if (!uuids.empty()) { | 380 if (!uuids.empty()) { |
| 421 service_uuids_.clear(); | 381 service_uuids_.clear(); |
| 422 service_uuids_.assign(uuids.begin(), uuids.end()); | 382 service_uuids_.assign(uuids.begin(), uuids.end()); |
| 423 } | 383 } |
| 424 | 384 |
| 425 if (update_state) { | 385 if (update_state) { |
| 426 // BlueZ uses paired to mean link keys exchanged, whereas the Bluetooth | 386 // BlueZ uses paired to mean link keys exchanged, whereas the Bluetooth |
| 427 // spec refers to this as bonded. Use the spec name for our interface. | 387 // spec refers to this as bonded. Use the spec name for our interface. |
| 428 bonded_ = properties->paired.value(); | 388 bonded_ = properties->paired.value(); |
| 429 connected_ = properties->connected.value(); | 389 connected_ = properties->connected.value(); |
| 430 } | 390 } |
| 431 } | 391 } |
| 432 | 392 |
| 433 void BluetoothDevice::ConnectCallback(const base::Closure& callback, | 393 void BluetoothDeviceChromeOs::ConnectCallback( |
| 434 const ErrorCallback& error_callback, | 394 const base::Closure& callback, |
| 435 const dbus::ObjectPath& device_path) { | 395 const ErrorCallback& error_callback, |
| 396 const dbus::ObjectPath& device_path) { | |
| 436 DVLOG(1) << "Connection successful: " << device_path.value(); | 397 DVLOG(1) << "Connection successful: " << device_path.value(); |
| 437 if (object_path_.value().empty()) { | 398 if (object_path_.value().empty()) { |
| 438 object_path_ = device_path; | 399 object_path_ = device_path; |
| 439 } else { | 400 } else { |
| 440 LOG_IF(WARNING, object_path_ != device_path) | 401 LOG_IF(WARNING, object_path_ != device_path) |
| 441 << "Conflicting device paths for objects, result gave: " | 402 << "Conflicting device paths for objects, result gave: " |
| 442 << device_path.value() << " but signal gave: " | 403 << device_path.value() << " but signal gave: " |
| 443 << object_path_.value(); | 404 << object_path_.value(); |
| 444 } | 405 } |
| 445 | 406 |
| 446 // Mark the device trusted so it can connect to us automatically, and | 407 // Mark the device trusted so it can connect to us automatically, and |
| 447 // we can connect after rebooting. This information is part of the | 408 // we can connect after rebooting. This information is part of the |
| 448 // pairing information of the device, and is unique to the combination | 409 // pairing information of the device, and is unique to the combination |
| 449 // of our bluetooth address and the device's bluetooth address. A | 410 // of our bluetooth address and the device's bluetooth address. A |
| 450 // different host needs a new pairing, so it's not useful to sync. | 411 // different host needs a new pairing, so it's not useful to sync. |
| 451 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 412 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 452 GetProperties(object_path_)->trusted.Set( | 413 GetProperties(object_path_)->trusted.Set( |
| 453 true, | 414 true, |
| 454 base::Bind(&BluetoothDevice::OnSetTrusted, | 415 base::Bind(&BluetoothDeviceChromeOs::OnSetTrusted, |
| 455 weak_ptr_factory_.GetWeakPtr(), | 416 weak_ptr_factory_.GetWeakPtr(), |
| 456 callback, | 417 callback, |
| 457 error_callback)); | 418 error_callback)); |
| 458 | 419 |
| 459 // Connect application-layer protocols. | 420 // Connect application-layer protocols. |
| 460 ConnectApplications(callback, error_callback); | 421 ConnectApplications(callback, error_callback); |
| 461 } | 422 } |
| 462 | 423 |
| 463 void BluetoothDevice::ConnectErrorCallback(const ErrorCallback& error_callback, | 424 void BluetoothDeviceChromeOs::ConnectErrorCallback( |
| 464 const std::string& error_name, | 425 const ErrorCallback& error_callback, |
| 465 const std::string& error_message) { | 426 const std::string& error_name, |
| 427 const std::string& error_message) { | |
| 466 LOG(WARNING) << "Connection failed: " << address_ | 428 LOG(WARNING) << "Connection failed: " << address_ |
| 467 << ": " << error_name << ": " << error_message; | 429 << ": " << error_name << ": " << error_message; |
| 468 error_callback.Run(); | 430 error_callback.Run(); |
| 469 } | 431 } |
| 470 | 432 |
| 471 void BluetoothDevice::CollectServiceRecordsCallback( | 433 void BluetoothDeviceChromeOs::CollectServiceRecordsCallback( |
| 472 const ServiceRecordsCallback& callback, | 434 const ServiceRecordsCallback& callback, |
| 473 const ErrorCallback& error_callback, | 435 const ErrorCallback& error_callback, |
| 474 const dbus::ObjectPath& device_path, | 436 const dbus::ObjectPath& device_path, |
| 475 const BluetoothDeviceClient::ServiceMap& service_map, | 437 const BluetoothDeviceClient::ServiceMap& service_map, |
| 476 bool success) { | 438 bool success) { |
| 477 if (!success) { | 439 if (!success) { |
| 478 error_callback.Run(); | 440 error_callback.Run(); |
| 479 return; | 441 return; |
| 480 } | 442 } |
| 481 | 443 |
| 482 ScopedVector<BluetoothServiceRecord> records; | 444 ScopedVector<BluetoothServiceRecord> records; |
| 483 for (BluetoothDeviceClient::ServiceMap::const_iterator i = | 445 for (BluetoothDeviceClient::ServiceMap::const_iterator i = |
| 484 service_map.begin(); i != service_map.end(); ++i) { | 446 service_map.begin(); i != service_map.end(); ++i) { |
| 485 records.push_back( | 447 records.push_back( |
| 486 new BluetoothServiceRecord(address(), i->second)); | 448 new BluetoothServiceRecord(address(), i->second)); |
| 487 } | 449 } |
| 488 callback.Run(records); | 450 callback.Run(records); |
| 489 } | 451 } |
| 490 | 452 |
| 491 void BluetoothDevice::OnSetTrusted(const base::Closure& callback, | 453 void BluetoothDeviceChromeOs::OnSetTrusted(const base::Closure& callback, |
| 492 const ErrorCallback& error_callback, | 454 const ErrorCallback& error_callback, |
| 493 bool success) { | 455 bool success) { |
| 494 if (success) { | 456 if (success) { |
| 495 callback.Run(); | 457 callback.Run(); |
| 496 } else { | 458 } else { |
| 497 LOG(WARNING) << "Failed to set device as trusted: " << address_; | 459 LOG(WARNING) << "Failed to set device as trusted: " << address_; |
| 498 error_callback.Run(); | 460 error_callback.Run(); |
| 499 } | 461 } |
| 500 } | 462 } |
| 501 | 463 |
| 502 void BluetoothDevice::ConnectApplications(const base::Closure& callback, | 464 void BluetoothDeviceChromeOs::ConnectApplications( |
| 503 const ErrorCallback& error_callback) { | 465 const base::Closure& callback, |
| 466 const ErrorCallback& error_callback) { | |
| 504 // Introspect the device object to determine supported applications. | 467 // Introspect the device object to determine supported applications. |
| 505 DBusThreadManager::Get()->GetIntrospectableClient()-> | 468 DBusThreadManager::Get()->GetIntrospectableClient()-> |
| 506 Introspect(bluetooth_device::kBluetoothDeviceServiceName, | 469 Introspect(bluetooth_device::kBluetoothDeviceServiceName, |
| 507 object_path_, | 470 object_path_, |
| 508 base::Bind(&BluetoothDevice::OnIntrospect, | 471 base::Bind(&BluetoothDeviceChromeOs::OnIntrospect, |
| 509 weak_ptr_factory_.GetWeakPtr(), | 472 weak_ptr_factory_.GetWeakPtr(), |
| 510 callback, | 473 callback, |
| 511 error_callback)); | 474 error_callback)); |
| 512 } | 475 } |
| 513 | 476 |
| 514 void BluetoothDevice::OnIntrospect(const base::Closure& callback, | 477 void BluetoothDeviceChromeOs::OnIntrospect(const base::Closure& callback, |
| 515 const ErrorCallback& error_callback, | 478 const ErrorCallback& error_callback, |
| 516 const std::string& service_name, | 479 const std::string& service_name, |
| 517 const dbus::ObjectPath& device_path, | 480 const dbus::ObjectPath& device_path, |
| 518 const std::string& xml_data, | 481 const std::string& xml_data, |
| 519 bool success) { | 482 bool success) { |
| 520 if (!success) { | 483 if (!success) { |
| 521 LOG(WARNING) << "Failed to determine supported applications: " << address_; | 484 LOG(WARNING) << "Failed to determine supported applications: " << address_; |
| 522 error_callback.Run(); | 485 error_callback.Run(); |
| 523 return; | 486 return; |
| 524 } | 487 } |
| 525 | 488 |
| 526 // The introspection data for the device object may list one or more | 489 // The introspection data for the device object may list one or more |
| 527 // additional D-Bus interfaces that BlueZ supports for this particular | 490 // additional D-Bus interfaces that BlueZ supports for this particular |
| 528 // device. Send appropraite Connect calls for each of those interfaces | 491 // device. Send appropraite Connect calls for each of those interfaces |
| 529 // to connect all of the application protocols for this device. | 492 // to connect all of the application protocols for this device. |
| 530 std::vector<std::string> interfaces = | 493 std::vector<std::string> interfaces = |
| 531 IntrospectableClient::GetInterfacesFromIntrospectResult(xml_data); | 494 IntrospectableClient::GetInterfacesFromIntrospectResult(xml_data); |
| 532 | 495 |
| 533 DCHECK_EQ(0, connecting_applications_counter_); | 496 DCHECK_EQ(0, connecting_applications_counter_); |
| 534 connecting_applications_counter_ = 0; | 497 connecting_applications_counter_ = 0; |
| 535 for (std::vector<std::string>::iterator iter = interfaces.begin(); | 498 for (std::vector<std::string>::iterator iter = interfaces.begin(); |
| 536 iter != interfaces.end(); ++iter) { | 499 iter != interfaces.end(); ++iter) { |
| 537 if (*iter == bluetooth_input::kBluetoothInputInterface) { | 500 if (*iter == bluetooth_input::kBluetoothInputInterface) { |
| 538 connecting_applications_counter_++; | 501 connecting_applications_counter_++; |
| 539 // Supports Input interface. | 502 // Supports Input interface. |
| 540 DBusThreadManager::Get()->GetBluetoothInputClient()-> | 503 DBusThreadManager::Get()->GetBluetoothInputClient()-> |
| 541 Connect(object_path_, | 504 Connect(object_path_, |
| 542 base::Bind(&BluetoothDevice::OnConnect, | 505 base::Bind(&BluetoothDeviceChromeOs::OnConnect, |
| 543 weak_ptr_factory_.GetWeakPtr(), | 506 weak_ptr_factory_.GetWeakPtr(), |
| 544 callback, | 507 callback, |
| 545 *iter), | 508 *iter), |
| 546 base::Bind(&BluetoothDevice::OnConnectError, | 509 base::Bind(&BluetoothDeviceChromeOs::OnConnectError, |
| 547 weak_ptr_factory_.GetWeakPtr(), | 510 weak_ptr_factory_.GetWeakPtr(), |
| 548 error_callback, *iter)); | 511 error_callback, *iter)); |
| 549 } | 512 } |
| 550 } | 513 } |
| 551 | 514 |
| 552 // If OnConnect has been called for every call to Connect above, then this | 515 // If OnConnect has been called for every call to Connect above, then this |
| 553 // will decrement the counter to -1. In that case, call the callback | 516 // will decrement the counter to -1. In that case, call the callback |
| 554 // directly as it has not been called by any of the OnConnect callbacks. | 517 // directly as it has not been called by any of the OnConnect callbacks. |
| 555 // This is safe because OnIntrospect and OnConnect run on the same thread. | 518 // This is safe because OnIntrospect and OnConnect run on the same thread. |
| 556 connecting_applications_counter_--; | 519 connecting_applications_counter_--; |
| 557 if (connecting_applications_counter_ == -1) | 520 if (connecting_applications_counter_ == -1) |
| 558 callback.Run(); | 521 callback.Run(); |
| 559 } | 522 } |
| 560 | 523 |
| 561 void BluetoothDevice::OnConnect(const base::Closure& callback, | 524 void BluetoothDeviceChromeOs::OnConnect(const base::Closure& callback, |
| 562 const std::string& interface_name, | 525 const std::string& interface_name, |
| 563 const dbus::ObjectPath& device_path) { | 526 const dbus::ObjectPath& device_path) { |
| 564 DVLOG(1) << "Application connection successful: " << device_path.value() | 527 DVLOG(1) << "Application connection successful: " << device_path.value() |
| 565 << ": " << interface_name; | 528 << ": " << interface_name; |
| 566 | 529 |
| 567 connecting_applications_counter_--; | 530 connecting_applications_counter_--; |
| 568 // |callback| should only be called once, meaning it cannot be called before | 531 // |callback| should only be called once, meaning it cannot be called before |
| 569 // all requests have been started. The extra decrement after all requests | 532 // all requests have been started. The extra decrement after all requests |
| 570 // have been started, and the check for -1 instead of 0 below, insure only a | 533 // have been started, and the check for -1 instead of 0 below, insure only a |
| 571 // single call to |callback| will occur (provided OnConnect and OnIntrospect | 534 // single call to |callback| will occur (provided OnConnect and OnIntrospect |
| 572 // run on the same thread, which is true). | 535 // run on the same thread, which is true). |
| 573 if (connecting_applications_counter_ == -1) { | 536 if (connecting_applications_counter_ == -1) { |
| 574 connecting_applications_counter_ = 0; | 537 connecting_applications_counter_ = 0; |
| 575 callback.Run(); | 538 callback.Run(); |
| 576 } | 539 } |
| 577 } | 540 } |
| 578 | 541 |
| 579 void BluetoothDevice::OnConnectError(const ErrorCallback& error_callback, | 542 void BluetoothDeviceChromeOs::OnConnectError( |
| 580 const std::string& interface_name, | 543 const ErrorCallback& error_callback, |
| 581 const dbus::ObjectPath& device_path, | 544 const std::string& interface_name, |
| 582 const std::string& error_name, | 545 const dbus::ObjectPath& device_path, |
| 583 const std::string& error_message) { | 546 const std::string& error_name, |
| 547 const std::string& error_message) { | |
| 584 LOG(WARNING) << "Connection failed: " << address_ << ": " << interface_name | 548 LOG(WARNING) << "Connection failed: " << address_ << ": " << interface_name |
| 585 << ": " << error_name << ": " << error_message; | 549 << ": " << error_name << ": " << error_message; |
| 586 error_callback.Run(); | 550 error_callback.Run(); |
| 587 } | 551 } |
| 588 | 552 |
| 589 void BluetoothDevice::DisconnectCallback(const base::Closure& callback, | 553 void BluetoothDeviceChromeOs::DisconnectCallback( |
| 590 const ErrorCallback& error_callback, | 554 const base::Closure& callback, |
| 591 const dbus::ObjectPath& device_path, | 555 const ErrorCallback& error_callback, |
| 592 bool success) { | 556 const dbus::ObjectPath& device_path, |
| 557 bool success) { | |
| 593 DCHECK(device_path == object_path_); | 558 DCHECK(device_path == object_path_); |
| 594 if (success) { | 559 if (success) { |
| 595 DVLOG(1) << "Disconnection successful: " << address_; | 560 DVLOG(1) << "Disconnection successful: " << address_; |
| 596 callback.Run(); | 561 callback.Run(); |
| 597 } else { | 562 } else { |
| 598 LOG(WARNING) << "Disconnection failed: " << address_; | 563 LOG(WARNING) << "Disconnection failed: " << address_; |
| 599 error_callback.Run(); | 564 error_callback.Run(); |
| 600 } | 565 } |
| 601 } | 566 } |
| 602 | 567 |
| 603 void BluetoothDevice::ForgetCallback(const ErrorCallback& error_callback, | 568 void BluetoothDeviceChromeOs::ForgetCallback( |
| 604 const dbus::ObjectPath& adapter_path, | 569 const ErrorCallback& error_callback, |
| 605 bool success) { | 570 const dbus::ObjectPath& adapter_path, |
| 571 bool success) { | |
| 606 // It's quite normal that this path never gets called on success; we use a | 572 // It's quite normal that this path never gets called on success; we use a |
| 607 // weak pointer, and bluetoothd might send the DeviceRemoved signal before | 573 // weak pointer, and bluetoothd might send the DeviceRemoved signal before |
| 608 // the method reply, in which case this object is deleted and the | 574 // the method reply, in which case this object is deleted and the |
| 609 // callback never takes place. Therefore don't do anything here for the | 575 // callback never takes place. Therefore don't do anything here for the |
| 610 // success case. | 576 // success case. |
| 611 if (!success) { | 577 if (!success) { |
| 612 LOG(WARNING) << "Forget failed: " << address_; | 578 LOG(WARNING) << "Forget failed: " << address_; |
| 613 error_callback.Run(); | 579 error_callback.Run(); |
| 614 } | 580 } |
| 615 } | 581 } |
| 616 | 582 |
| 617 void BluetoothDevice::SearchServicesForNameErrorCallback( | 583 void BluetoothDeviceChromeOs::SearchServicesForNameErrorCallback( |
| 618 const ProvidesServiceCallback& callback) { | 584 const ProvidesServiceCallback& callback) { |
| 619 callback.Run(false); | 585 callback.Run(false); |
| 620 } | 586 } |
| 621 | 587 |
| 622 void BluetoothDevice::SearchServicesForNameCallback( | 588 void BluetoothDeviceChromeOs::SearchServicesForNameCallback( |
| 623 const std::string& name, | 589 const std::string& name, |
| 624 const ProvidesServiceCallback& callback, | 590 const ProvidesServiceCallback& callback, |
| 625 const ServiceRecordList& list) { | 591 const ServiceRecordList& list) { |
| 626 for (ServiceRecordList::const_iterator i = list.begin(); | 592 for (ServiceRecordList::const_iterator i = list.begin(); |
| 627 i != list.end(); ++i) { | 593 i != list.end(); ++i) { |
| 628 if ((*i)->name() == name) { | 594 if ((*i)->name() == name) { |
| 629 callback.Run(true); | 595 callback.Run(true); |
| 630 return; | 596 return; |
| 631 } | 597 } |
| 632 } | 598 } |
| 633 callback.Run(false); | 599 callback.Run(false); |
| 634 } | 600 } |
| 635 | 601 |
| 636 void BluetoothDevice::GetServiceRecordsForConnectErrorCallback( | 602 void BluetoothDeviceChromeOs::GetServiceRecordsForConnectErrorCallback( |
| 637 const SocketCallback& callback) { | 603 const SocketCallback& callback) { |
| 638 callback.Run(NULL); | 604 callback.Run(NULL); |
| 639 } | 605 } |
| 640 | 606 |
| 641 void BluetoothDevice::GetServiceRecordsForConnectCallback( | 607 void BluetoothDeviceChromeOs::GetServiceRecordsForConnectCallback( |
| 642 const std::string& service_uuid, | 608 const std::string& service_uuid, |
| 643 const SocketCallback& callback, | 609 const SocketCallback& callback, |
| 644 const ServiceRecordList& list) { | 610 const ServiceRecordList& list) { |
| 645 for (ServiceRecordList::const_iterator i = list.begin(); | 611 for (ServiceRecordList::const_iterator i = list.begin(); |
| 646 i != list.end(); ++i) { | 612 i != list.end(); ++i) { |
| 647 if ((*i)->uuid() == service_uuid) { | 613 if ((*i)->uuid() == service_uuid) { |
| 648 // If multiple service records are found, use the first one that works. | 614 // If multiple service records are found, use the first one that works. |
| 649 scoped_refptr<BluetoothSocket> socket( | 615 scoped_refptr<BluetoothSocket> socket( |
| 650 BluetoothSocket::CreateBluetoothSocket(**i)); | 616 BluetoothSocketChromeOs::CreateBluetoothSocket(**i)); |
| 651 if (socket.get() != NULL) { | 617 if (socket.get() != NULL) { |
| 652 callback.Run(socket); | 618 callback.Run(socket); |
| 653 return; | 619 return; |
| 654 } | 620 } |
| 655 } | 621 } |
| 656 } | 622 } |
| 657 callback.Run(NULL); | 623 callback.Run(NULL); |
| 658 } | 624 } |
| 659 | 625 |
| 660 void BluetoothDevice::OnRemoteDataCallback(const base::Closure& callback, | 626 void BluetoothDeviceChromeOs::OnRemoteDataCallback( |
| 661 const ErrorCallback& error_callback, | 627 const base::Closure& callback, |
| 662 bool success) { | 628 const ErrorCallback& error_callback, |
| 629 bool success) { | |
| 663 if (success) | 630 if (success) |
| 664 callback.Run(); | 631 callback.Run(); |
| 665 else | 632 else |
| 666 error_callback.Run(); | 633 error_callback.Run(); |
| 667 } | 634 } |
| 668 | 635 |
| 669 void BluetoothDevice::DisconnectRequested(const dbus::ObjectPath& object_path) { | 636 void BluetoothDeviceChromeOs::DisconnectRequested( |
| 637 const dbus::ObjectPath& object_path) { | |
| 670 DCHECK(object_path == object_path_); | 638 DCHECK(object_path == object_path_); |
| 671 } | 639 } |
| 672 | 640 |
| 673 void BluetoothDevice::Release() { | 641 void BluetoothDeviceChromeOs::Release() { |
| 674 DCHECK(agent_.get()); | 642 DCHECK(agent_.get()); |
| 675 DVLOG(1) << "Release: " << address_; | 643 DVLOG(1) << "Release: " << address_; |
| 676 | 644 |
| 677 DCHECK(pairing_delegate_); | 645 DCHECK(pairing_delegate_); |
| 678 pairing_delegate_->DismissDisplayOrConfirm(); | 646 pairing_delegate_->DismissDisplayOrConfirm(); |
| 679 pairing_delegate_ = NULL; | 647 pairing_delegate_ = NULL; |
| 680 | 648 |
| 681 pincode_callback_.Reset(); | 649 pincode_callback_.Reset(); |
| 682 passkey_callback_.Reset(); | 650 passkey_callback_.Reset(); |
| 683 confirmation_callback_.Reset(); | 651 confirmation_callback_.Reset(); |
| 684 | 652 |
| 685 agent_.reset(); | 653 agent_.reset(); |
| 686 } | 654 } |
| 687 | 655 |
| 688 void BluetoothDevice::RequestPinCode(const dbus::ObjectPath& device_path, | 656 void BluetoothDeviceChromeOs::RequestPinCode( |
| 689 const PinCodeCallback& callback) { | 657 const dbus::ObjectPath& device_path, |
| 658 const PinCodeCallback& callback) { | |
| 690 DCHECK(agent_.get()); | 659 DCHECK(agent_.get()); |
| 691 DVLOG(1) << "RequestPinCode: " << device_path.value(); | 660 DVLOG(1) << "RequestPinCode: " << device_path.value(); |
| 692 | 661 |
| 693 DCHECK(pairing_delegate_); | 662 DCHECK(pairing_delegate_); |
| 694 DCHECK(pincode_callback_.is_null()); | 663 DCHECK(pincode_callback_.is_null()); |
| 695 pincode_callback_ = callback; | 664 pincode_callback_ = callback; |
| 696 pairing_delegate_->RequestPinCode(this); | 665 pairing_delegate_->RequestPinCode(this); |
| 697 } | 666 } |
| 698 | 667 |
| 699 void BluetoothDevice::RequestPasskey(const dbus::ObjectPath& device_path, | 668 void BluetoothDeviceChromeOs::RequestPasskey( |
| 700 const PasskeyCallback& callback) { | 669 const dbus::ObjectPath& device_path, |
| 670 const PasskeyCallback& callback) { | |
| 701 DCHECK(agent_.get()); | 671 DCHECK(agent_.get()); |
| 702 DCHECK(device_path == object_path_); | 672 DCHECK(device_path == object_path_); |
| 703 DVLOG(1) << "RequestPasskey: " << device_path.value(); | 673 DVLOG(1) << "RequestPasskey: " << device_path.value(); |
| 704 | 674 |
| 705 DCHECK(pairing_delegate_); | 675 DCHECK(pairing_delegate_); |
| 706 DCHECK(passkey_callback_.is_null()); | 676 DCHECK(passkey_callback_.is_null()); |
| 707 passkey_callback_ = callback; | 677 passkey_callback_ = callback; |
| 708 pairing_delegate_->RequestPasskey(this); | 678 pairing_delegate_->RequestPasskey(this); |
| 709 } | 679 } |
| 710 | 680 |
| 711 void BluetoothDevice::DisplayPinCode(const dbus::ObjectPath& device_path, | 681 void BluetoothDeviceChromeOs::DisplayPinCode( |
| 712 const std::string& pincode) { | 682 const dbus::ObjectPath& device_path, |
| 683 const std::string& pincode) { | |
| 713 DCHECK(agent_.get()); | 684 DCHECK(agent_.get()); |
| 714 DCHECK(device_path == object_path_); | 685 DCHECK(device_path == object_path_); |
| 715 DVLOG(1) << "DisplayPinCode: " << device_path.value() << " " << pincode; | 686 DVLOG(1) << "DisplayPinCode: " << device_path.value() << " " << pincode; |
| 716 | 687 |
| 717 DCHECK(pairing_delegate_); | 688 DCHECK(pairing_delegate_); |
| 718 pairing_delegate_->DisplayPinCode(this, pincode); | 689 pairing_delegate_->DisplayPinCode(this, pincode); |
| 719 } | 690 } |
| 720 | 691 |
| 721 void BluetoothDevice::DisplayPasskey(const dbus::ObjectPath& device_path, | 692 void BluetoothDeviceChromeOs::DisplayPasskey( |
| 722 uint32 passkey) { | 693 const dbus::ObjectPath& device_path, |
| 694 uint32 passkey) { | |
| 723 DCHECK(agent_.get()); | 695 DCHECK(agent_.get()); |
| 724 DCHECK(device_path == object_path_); | 696 DCHECK(device_path == object_path_); |
| 725 DVLOG(1) << "DisplayPasskey: " << device_path.value() << " " << passkey; | 697 DVLOG(1) << "DisplayPasskey: " << device_path.value() << " " << passkey; |
| 726 | 698 |
| 727 DCHECK(pairing_delegate_); | 699 DCHECK(pairing_delegate_); |
| 728 pairing_delegate_->DisplayPasskey(this, passkey); | 700 pairing_delegate_->DisplayPasskey(this, passkey); |
| 729 } | 701 } |
| 730 | 702 |
| 731 void BluetoothDevice::RequestConfirmation( | 703 void BluetoothDeviceChromeOs::RequestConfirmation( |
| 732 const dbus::ObjectPath& device_path, | 704 const dbus::ObjectPath& device_path, |
| 733 uint32 passkey, | 705 uint32 passkey, |
| 734 const ConfirmationCallback& callback) { | 706 const ConfirmationCallback& callback) { |
| 735 DCHECK(agent_.get()); | 707 DCHECK(agent_.get()); |
| 736 DCHECK(device_path == object_path_); | 708 DCHECK(device_path == object_path_); |
| 737 DVLOG(1) << "RequestConfirmation: " << device_path.value() << " " << passkey; | 709 DVLOG(1) << "RequestConfirmation: " << device_path.value() << " " << passkey; |
| 738 | 710 |
| 739 DCHECK(pairing_delegate_); | 711 DCHECK(pairing_delegate_); |
| 740 DCHECK(confirmation_callback_.is_null()); | 712 DCHECK(confirmation_callback_.is_null()); |
| 741 confirmation_callback_ = callback; | 713 confirmation_callback_ = callback; |
| 742 pairing_delegate_->ConfirmPasskey(this, passkey); | 714 pairing_delegate_->ConfirmPasskey(this, passkey); |
| 743 } | 715 } |
| 744 | 716 |
| 745 void BluetoothDevice::Authorize(const dbus::ObjectPath& device_path, | 717 void BluetoothDeviceChromeOs::Authorize(const dbus::ObjectPath& device_path, |
| 746 const std::string& uuid, | 718 const std::string& uuid, |
| 747 const ConfirmationCallback& callback) { | 719 const ConfirmationCallback& callback) { |
| 748 DCHECK(agent_.get()); | 720 DCHECK(agent_.get()); |
| 749 DCHECK(device_path == object_path_); | 721 DCHECK(device_path == object_path_); |
| 750 LOG(WARNING) << "Rejected authorization for service: " << uuid | 722 LOG(WARNING) << "Rejected authorization for service: " << uuid |
| 751 << " requested from device: " << device_path.value(); | 723 << " requested from device: " << device_path.value(); |
| 752 callback.Run(REJECTED); | 724 callback.Run(REJECTED); |
| 753 } | 725 } |
| 754 | 726 |
| 755 void BluetoothDevice::ConfirmModeChange(Mode mode, | 727 void BluetoothDeviceChromeOs::ConfirmModeChange( |
| 756 const ConfirmationCallback& callback) { | 728 Mode mode, |
| 729 const ConfirmationCallback& callback) { | |
| 757 DCHECK(agent_.get()); | 730 DCHECK(agent_.get()); |
| 758 LOG(WARNING) << "Rejected adapter-level mode change: " << mode | 731 LOG(WARNING) << "Rejected adapter-level mode change: " << mode |
| 759 << " made on agent for device: " << address_; | 732 << " made on agent for device: " << address_; |
| 760 callback.Run(REJECTED); | 733 callback.Run(REJECTED); |
| 761 } | 734 } |
| 762 | 735 |
| 763 void BluetoothDevice::Cancel() { | 736 void BluetoothDeviceChromeOs::Cancel() { |
| 764 DCHECK(agent_.get()); | 737 DCHECK(agent_.get()); |
| 765 DVLOG(1) << "Cancel: " << address_; | 738 DVLOG(1) << "Cancel: " << address_; |
| 766 | 739 |
| 767 DCHECK(pairing_delegate_); | 740 DCHECK(pairing_delegate_); |
| 768 pairing_delegate_->DismissDisplayOrConfirm(); | 741 pairing_delegate_->DismissDisplayOrConfirm(); |
| 769 } | 742 } |
| 770 | 743 |
| 771 | 744 |
| 772 // static | 745 // static |
| 773 BluetoothDevice* BluetoothDevice::Create(BluetoothAdapter* adapter) { | 746 BluetoothDeviceChromeOs* BluetoothDeviceChromeOs::Create( |
| 774 return new BluetoothDevice(adapter); | 747 BluetoothAdapterChromeOs* adapter) { |
| 748 return new BluetoothDeviceChromeOs(adapter); | |
| 775 } | 749 } |
| 776 | 750 |
| 777 } // namespace chromeos | 751 } // namespace chromeos |
| OLD | NEW |