Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "device/bluetooth/bluetooth_socket_chromeos.h" | 5 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/threading/worker_pool.h" | 21 #include "base/threading/worker_pool.h" |
| 22 #include "chromeos/dbus/bluetooth_device_client.h" | 22 #include "chromeos/dbus/bluetooth_device_client.h" |
| 23 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 23 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| 24 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | 24 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
| 25 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
| 26 #include "dbus/bus.h" | 26 #include "dbus/bus.h" |
| 27 #include "dbus/file_descriptor.h" | 27 #include "dbus/file_descriptor.h" |
| 28 #include "dbus/object_path.h" | 28 #include "dbus/object_path.h" |
| 29 #include "device/bluetooth/bluetooth_adapter.h" | 29 #include "device/bluetooth/bluetooth_adapter.h" |
| 30 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 30 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 31 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" | |
| 31 #include "device/bluetooth/bluetooth_device.h" | 32 #include "device/bluetooth/bluetooth_device.h" |
| 32 #include "device/bluetooth/bluetooth_device_chromeos.h" | 33 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 33 #include "device/bluetooth/bluetooth_socket.h" | 34 #include "device/bluetooth/bluetooth_socket.h" |
| 34 #include "device/bluetooth/bluetooth_socket_net.h" | 35 #include "device/bluetooth/bluetooth_socket_net.h" |
| 35 #include "device/bluetooth/bluetooth_socket_thread.h" | 36 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 36 #include "net/base/ip_endpoint.h" | 37 #include "net/base/ip_endpoint.h" |
| 37 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
| 38 #include "third_party/cros_system_api/dbus/service_constants.h" | 39 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 39 | 40 |
| 40 using device::BluetoothAdapter; | 41 using device::BluetoothAdapter; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 69 | 70 |
| 70 BluetoothSocketChromeOS::ConnectionRequest::ConnectionRequest() | 71 BluetoothSocketChromeOS::ConnectionRequest::ConnectionRequest() |
| 71 : accepting(false), | 72 : accepting(false), |
| 72 cancelled(false) {} | 73 cancelled(false) {} |
| 73 | 74 |
| 74 BluetoothSocketChromeOS::ConnectionRequest::~ConnectionRequest() {} | 75 BluetoothSocketChromeOS::ConnectionRequest::~ConnectionRequest() {} |
| 75 | 76 |
| 76 BluetoothSocketChromeOS::BluetoothSocketChromeOS( | 77 BluetoothSocketChromeOS::BluetoothSocketChromeOS( |
| 77 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 78 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 78 scoped_refptr<BluetoothSocketThread> socket_thread) | 79 scoped_refptr<BluetoothSocketThread> socket_thread) |
| 79 : BluetoothSocketNet(ui_task_runner, socket_thread) { | 80 : BluetoothSocketNet(ui_task_runner, socket_thread), profile_(NULL) { |
| 80 } | 81 } |
| 81 | 82 |
| 82 BluetoothSocketChromeOS::~BluetoothSocketChromeOS() { | 83 BluetoothSocketChromeOS::~BluetoothSocketChromeOS() { |
| 83 DCHECK(object_path_.value().empty()); | 84 DCHECK(!profile_); |
| 84 DCHECK(profile_.get() == NULL); | |
| 85 | 85 |
| 86 if (adapter_.get()) { | 86 if (adapter_.get()) { |
| 87 adapter_->RemoveObserver(this); | 87 adapter_->RemoveObserver(this); |
| 88 adapter_ = NULL; | 88 adapter_ = NULL; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 void BluetoothSocketChromeOS::Connect( | 92 void BluetoothSocketChromeOS::Connect( |
| 93 const BluetoothDeviceChromeOS* device, | 93 const BluetoothDeviceChromeOS* device, |
| 94 const BluetoothUUID& uuid, | 94 const BluetoothUUID& uuid, |
| 95 SecurityLevel security_level, | 95 SecurityLevel security_level, |
| 96 const base::Closure& success_callback, | 96 const base::Closure& success_callback, |
| 97 const ErrorCompletionCallback& error_callback) { | 97 const ErrorCompletionCallback& error_callback) { |
| 98 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 98 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 99 DCHECK(object_path_.value().empty()); | 99 DCHECK(!profile_); |
| 100 DCHECK(!profile_.get()); | |
| 101 | 100 |
| 102 if (!uuid.IsValid()) { | 101 if (!uuid.IsValid()) { |
| 103 error_callback.Run(kInvalidUUID); | 102 error_callback.Run(kInvalidUUID); |
| 104 return; | 103 return; |
| 105 } | 104 } |
| 106 | 105 |
| 107 device_address_ = device->GetAddress(); | 106 device_address_ = device->GetAddress(); |
| 108 device_path_ = device->object_path(); | 107 device_path_ = device->object_path(); |
| 109 uuid_ = uuid; | 108 uuid_ = uuid; |
| 110 options_.reset(new BluetoothProfileManagerClient::Options()); | 109 options_.reset(new BluetoothProfileManagerClient::Options()); |
| 111 if (security_level == SECURITY_LEVEL_LOW) | 110 if (security_level == SECURITY_LEVEL_LOW) |
| 112 options_->require_authentication.reset(new bool(false)); | 111 options_->require_authentication.reset(new bool(false)); |
| 113 | 112 |
| 114 RegisterProfile(success_callback, error_callback); | 113 RegisterProfile(device->adapter(), success_callback, error_callback); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void BluetoothSocketChromeOS::Listen( | 116 void BluetoothSocketChromeOS::Listen( |
| 118 scoped_refptr<BluetoothAdapter> adapter, | 117 scoped_refptr<BluetoothAdapter> adapter, |
| 119 SocketType socket_type, | 118 SocketType socket_type, |
| 120 const BluetoothUUID& uuid, | 119 const BluetoothUUID& uuid, |
| 121 const BluetoothAdapter::ServiceOptions& service_options, | 120 const BluetoothAdapter::ServiceOptions& service_options, |
| 122 const base::Closure& success_callback, | 121 const base::Closure& success_callback, |
| 123 const ErrorCompletionCallback& error_callback) { | 122 const ErrorCompletionCallback& error_callback) { |
| 124 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 123 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 125 DCHECK(object_path_.value().empty()); | 124 DCHECK(!profile_); |
| 126 DCHECK(!profile_.get()); | |
| 127 | 125 |
| 128 if (!uuid.IsValid()) { | 126 if (!uuid.IsValid()) { |
| 129 error_callback.Run(kInvalidUUID); | 127 error_callback.Run(kInvalidUUID); |
| 130 return; | 128 return; |
| 131 } | 129 } |
| 132 | 130 |
| 133 adapter_ = adapter; | 131 adapter_ = adapter; |
| 134 adapter_->AddObserver(this); | 132 adapter_->AddObserver(this); |
| 135 | 133 |
| 136 uuid_ = uuid; | 134 uuid_ = uuid; |
| 137 options_.reset(new BluetoothProfileManagerClient::Options()); | 135 options_.reset(new BluetoothProfileManagerClient::Options()); |
| 138 if (service_options.name) | 136 if (service_options.name) |
| 139 options_->name.reset(new std::string(*service_options.name)); | 137 options_->name.reset(new std::string(*service_options.name)); |
| 140 | 138 |
| 141 switch (socket_type) { | 139 switch (socket_type) { |
| 142 case kRfcomm: | 140 case kRfcomm: |
| 143 options_->channel.reset( | 141 options_->channel.reset( |
| 144 new uint16(service_options.channel ? *service_options.channel : 0)); | 142 new uint16(service_options.channel ? *service_options.channel : 0)); |
| 145 break; | 143 break; |
| 146 case kL2cap: | 144 case kL2cap: |
| 147 options_->psm.reset( | 145 options_->psm.reset( |
| 148 new uint16(service_options.psm ? *service_options.psm : 0)); | 146 new uint16(service_options.psm ? *service_options.psm : 0)); |
| 149 break; | 147 break; |
| 150 default: | 148 default: |
| 151 NOTREACHED(); | 149 NOTREACHED(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 RegisterProfile(success_callback, error_callback); | 152 RegisterProfile(static_cast<BluetoothAdapterChromeOS*>(adapter_.get()), |
| 153 success_callback, error_callback); | |
| 155 } | 154 } |
| 156 | 155 |
| 157 void BluetoothSocketChromeOS::Close() { | 156 void BluetoothSocketChromeOS::Close() { |
| 158 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 157 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 159 | 158 |
| 160 if (profile_) | 159 if (profile_) |
| 161 UnregisterProfile(); | 160 UnregisterProfile(); |
| 162 | 161 |
| 163 // In the case below, where an asynchronous task gets posted on the socket | 162 // In the case below, where an asynchronous task gets posted on the socket |
| 164 // thread in BluetoothSocketNet::Close, a reference will be held to this | 163 // thread in BluetoothSocketNet::Close, a reference will be held to this |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 accept_request_.reset(new AcceptRequest); | 208 accept_request_.reset(new AcceptRequest); |
| 210 accept_request_->success_callback = success_callback; | 209 accept_request_->success_callback = success_callback; |
| 211 accept_request_->error_callback = error_callback; | 210 accept_request_->error_callback = error_callback; |
| 212 | 211 |
| 213 if (connection_request_queue_.size() >= 1) { | 212 if (connection_request_queue_.size() >= 1) { |
| 214 AcceptConnectionRequest(); | 213 AcceptConnectionRequest(); |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 | 216 |
| 218 void BluetoothSocketChromeOS::RegisterProfile( | 217 void BluetoothSocketChromeOS::RegisterProfile( |
| 218 BluetoothAdapterChromeOS* adapter, | |
| 219 const base::Closure& success_callback, | 219 const base::Closure& success_callback, |
| 220 const ErrorCompletionCallback& error_callback) { | 220 const ErrorCompletionCallback& error_callback) { |
| 221 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 221 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 222 DCHECK(object_path_.value().empty()); | 222 DCHECK(!profile_); |
| 223 DCHECK(!profile_.get()); | 223 DCHECK(adapter); |
| 224 | 224 |
| 225 // The object path is relatively meaningless, but has to be unique, so for | 225 // If the adapter is not present, this is a listening socket and the |
| 226 // connecting profiles use a combination of the device address and profile | 226 // adapter isn't running yet. Report success and carry on; |
| 227 // UUID. | |
| 228 std::string device_address_path, uuid_path; | |
| 229 base::ReplaceChars(device_address_, ":-", "_", &device_address_path); | |
| 230 base::ReplaceChars(uuid_.canonical_value(), ":-", "_", &uuid_path); | |
| 231 if (!device_address_path.empty()) { | |
| 232 object_path_ = dbus::ObjectPath("/org/chromium/bluetooth_profile/" + | |
| 233 device_address_path + "/" + uuid_path); | |
| 234 } else { | |
| 235 object_path_ = dbus::ObjectPath("/org/chromium/bluetooth_profile/" + | |
| 236 uuid_path); | |
| 237 } | |
| 238 | |
| 239 // Create the service provider for the profile object. | |
| 240 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | |
| 241 profile_.reset(BluetoothProfileServiceProvider::Create( | |
| 242 system_bus, object_path_, this)); | |
| 243 DCHECK(profile_.get()); | |
| 244 | |
| 245 // Before reaching out to the Bluetooth Daemon to register a listening socket, | |
| 246 // make sure it's actually running. If not, report success and carry on; | |
| 247 // the profile will be registered when the daemon becomes available. | 227 // the profile will be registered when the daemon becomes available. |
| 248 if (adapter_.get() && !adapter_->IsPresent()) { | 228 if (!adapter->IsPresent()) { |
| 249 VLOG(1) << object_path_.value() << ": Delaying profile registration."; | 229 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() |
| 250 success_callback.Run(); | 230 << ": Delaying profile registration."; |
| 231 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback); | |
| 251 return; | 232 return; |
| 252 } | 233 } |
| 253 | 234 |
| 254 VLOG(1) << object_path_.value() << ": Registering profile."; | 235 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() |
| 255 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> | 236 << ": Acquiring profile."; |
| 256 RegisterProfile( | 237 |
| 257 object_path_, | 238 profile_ = adapter->UseProfile( |
| 258 uuid_.canonical_value(), | 239 uuid_, device_path_, options_.get(), this, |
| 259 *options_, | 240 base::Bind(&BluetoothSocketChromeOS::OnRegisterProfile, this, |
| 260 base::Bind(&BluetoothSocketChromeOS::OnRegisterProfile, | 241 success_callback, error_callback), |
| 261 this, | 242 base::Bind(&BluetoothSocketChromeOS::OnRegisterProfileError, this, |
| 262 success_callback, | 243 error_callback)); |
| 263 error_callback), | |
| 264 base::Bind(&BluetoothSocketChromeOS::OnRegisterProfileError, | |
| 265 this, | |
| 266 error_callback)); | |
| 267 } | 244 } |
| 268 | 245 |
| 269 void BluetoothSocketChromeOS::OnRegisterProfile( | 246 void BluetoothSocketChromeOS::OnRegisterProfile( |
| 270 const base::Closure& success_callback, | 247 const base::Closure& success_callback, |
| 271 const ErrorCompletionCallback& error_callback) { | 248 const ErrorCompletionCallback& error_callback) { |
| 272 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 249 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 250 | |
| 273 if (!device_path_.value().empty()) { | 251 if (!device_path_.value().empty()) { |
| 274 VLOG(1) << object_path_.value() << ": Profile registered, connecting to " | 252 VLOG(1) << uuid_.canonical_value() << ": Got profile, connecting to " |
| 275 << device_path_.value(); | 253 << device_path_.value(); |
| 276 | 254 |
| 277 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 255 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 278 ConnectProfile( | 256 ConnectProfile( |
| 279 device_path_, | 257 device_path_, |
| 280 uuid_.canonical_value(), | 258 uuid_.canonical_value(), |
| 281 base::Bind( | 259 base::Bind( |
| 282 &BluetoothSocketChromeOS::OnConnectProfile, | 260 &BluetoothSocketChromeOS::OnConnectProfile, |
| 283 this, | 261 this, |
| 284 success_callback), | 262 success_callback), |
| 285 base::Bind( | 263 base::Bind( |
| 286 &BluetoothSocketChromeOS::OnConnectProfileError, | 264 &BluetoothSocketChromeOS::OnConnectProfileError, |
| 287 this, | 265 this, |
| 288 error_callback)); | 266 error_callback)); |
| 289 } else { | 267 } else { |
| 290 VLOG(1) << object_path_.value() << ": Profile registered."; | 268 VLOG(1) << uuid_.canonical_value() << ": Profile registered."; |
| 291 success_callback.Run(); | 269 success_callback.Run(); |
| 292 } | 270 } |
|
armansito
2015/01/21 01:44:48
I'd turn this if statement around with an early re
Marie Janssen
2015/01/22 21:55:33
Done.
| |
| 293 } | 271 } |
| 294 | 272 |
| 295 void BluetoothSocketChromeOS::OnRegisterProfileError( | 273 void BluetoothSocketChromeOS::OnRegisterProfileError( |
| 296 const ErrorCompletionCallback& error_callback, | 274 const ErrorCompletionCallback& error_callback, |
| 297 const std::string& error_name, | |
| 298 const std::string& error_message) { | 275 const std::string& error_message) { |
| 299 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 276 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 300 LOG(WARNING) << object_path_.value() << ": Failed to register profile: " | 277 |
| 301 << error_name << ": " << error_message; | 278 LOG(WARNING) << uuid_.canonical_value() |
| 279 << ": Failed to register profile: " << error_message; | |
| 302 error_callback.Run(error_message); | 280 error_callback.Run(error_message); |
| 303 } | 281 } |
| 304 | 282 |
| 305 void BluetoothSocketChromeOS::OnConnectProfile( | 283 void BluetoothSocketChromeOS::OnConnectProfile( |
| 306 const base::Closure& success_callback) { | 284 const base::Closure& success_callback) { |
| 307 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 285 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 308 VLOG(1) << object_path_.value() << ": Profile connected."; | 286 DCHECK(profile_); |
| 287 | |
| 288 VLOG(1) << profile_->object_path().value() << ": Profile connected."; | |
| 309 UnregisterProfile(); | 289 UnregisterProfile(); |
| 310 success_callback.Run(); | 290 success_callback.Run(); |
| 311 } | 291 } |
| 312 | 292 |
| 313 void BluetoothSocketChromeOS::OnConnectProfileError( | 293 void BluetoothSocketChromeOS::OnConnectProfileError( |
| 314 const ErrorCompletionCallback& error_callback, | 294 const ErrorCompletionCallback& error_callback, |
| 315 const std::string& error_name, | 295 const std::string& error_name, |
| 316 const std::string& error_message) { | 296 const std::string& error_message) { |
| 317 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 297 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 318 LOG(WARNING) << object_path_.value() << ": Failed to connect profile: " | 298 DCHECK(profile_); |
| 319 << error_name << ": " << error_message; | 299 |
| 300 LOG(WARNING) << profile_->object_path().value() | |
| 301 << ": Failed to connect profile: " << error_name << ": " | |
| 302 << error_message; | |
| 320 UnregisterProfile(); | 303 UnregisterProfile(); |
| 321 error_callback.Run(error_message); | 304 error_callback.Run(error_message); |
| 322 } | 305 } |
| 323 | 306 |
| 324 void BluetoothSocketChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, | 307 void BluetoothSocketChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, |
| 325 bool present) { | 308 bool present) { |
| 326 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 309 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 327 DCHECK(!object_path_.value().empty()); | |
| 328 DCHECK(profile_.get()); | |
| 329 | 310 |
| 330 if (!present) | 311 if (!present) { |
| 312 // Adapter removed, the profile is now invalid. | |
| 313 UnregisterProfile(); | |
| 331 return; | 314 return; |
| 315 } | |
| 332 | 316 |
| 333 VLOG(1) << object_path_.value() << ": Re-register profile."; | 317 DCHECK(!profile_); |
| 334 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> | 318 |
| 335 RegisterProfile( | 319 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() |
| 336 object_path_, | 320 << ": Acquiring profile."; |
| 337 uuid_.canonical_value(), | 321 |
| 338 *options_, | 322 profile_ = static_cast<BluetoothAdapterChromeOS*>(adapter)->UseProfile( |
| 339 base::Bind(&BluetoothSocketChromeOS::OnInternalRegisterProfile, | 323 uuid_, device_path_, options_.get(), this, |
| 340 this), | 324 base::Bind(&BluetoothSocketChromeOS::OnInternalRegisterProfile, this), |
| 341 base::Bind(&BluetoothSocketChromeOS::OnInternalRegisterProfileError, | 325 base::Bind(&BluetoothSocketChromeOS::OnInternalRegisterProfileError, |
| 342 this)); | 326 this)); |
| 343 } | 327 } |
| 344 | 328 |
| 345 void BluetoothSocketChromeOS::OnInternalRegisterProfile() { | 329 void BluetoothSocketChromeOS::OnInternalRegisterProfile() { |
| 346 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 330 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 347 | 331 |
| 348 VLOG(1) << object_path_.value() << ": Profile re-registered"; | 332 VLOG(1) << uuid_.canonical_value() << ": Profile re-registered"; |
| 349 } | 333 } |
| 350 | 334 |
| 351 void BluetoothSocketChromeOS::OnInternalRegisterProfileError( | 335 void BluetoothSocketChromeOS::OnInternalRegisterProfileError( |
| 352 const std::string& error_name, | |
| 353 const std::string& error_message) { | 336 const std::string& error_message) { |
| 354 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 337 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 338 DCHECK(profile_); | |
| 355 | 339 |
| 356 // It's okay if the profile already exists, it means we registered it on | 340 LOG(WARNING) << profile_->object_path().value() |
| 357 // initialization. | 341 << ": Failed to re-register profile: " << error_message; |
| 358 if (error_name == bluetooth_profile_manager::kErrorAlreadyExists) | |
| 359 return; | |
| 360 | |
| 361 LOG(WARNING) << object_path_.value() << ": Failed to re-register profile: " | |
| 362 << error_name << ": " << error_message; | |
| 363 } | 342 } |
| 364 | 343 |
| 365 void BluetoothSocketChromeOS::Released() { | 344 void BluetoothSocketChromeOS::Released() { |
| 366 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 345 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 367 VLOG(1) << object_path_.value() << ": Release"; | 346 DCHECK(profile_); |
| 347 | |
| 348 VLOG(1) << profile_->object_path().value() << ": Release"; | |
| 368 } | 349 } |
| 369 | 350 |
| 370 void BluetoothSocketChromeOS::NewConnection( | 351 void BluetoothSocketChromeOS::NewConnection( |
| 371 const dbus::ObjectPath& device_path, | 352 const dbus::ObjectPath& device_path, |
| 372 scoped_ptr<dbus::FileDescriptor> fd, | 353 scoped_ptr<dbus::FileDescriptor> fd, |
| 373 const BluetoothProfileServiceProvider::Delegate::Options& options, | 354 const BluetoothProfileServiceProvider::Delegate::Options& options, |
| 374 const ConfirmationCallback& callback) { | 355 const ConfirmationCallback& callback) { |
| 375 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 356 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 376 VLOG(1) << object_path_.value() << ": New connection from device: " | 357 |
| 377 << device_path.value(); | 358 VLOG(1) << uuid_.canonical_value() |
| 359 << ": New connection from device: " << device_path.value(); | |
| 378 | 360 |
| 379 if (!device_path_.value().empty()) { | 361 if (!device_path_.value().empty()) { |
| 380 DCHECK(device_path_ == device_path); | 362 DCHECK(device_path_ == device_path); |
| 381 | 363 |
| 382 socket_thread()->task_runner()->PostTask( | 364 socket_thread()->task_runner()->PostTask( |
| 383 FROM_HERE, | 365 FROM_HERE, |
| 384 base::Bind( | 366 base::Bind( |
| 385 &BluetoothSocketChromeOS::DoNewConnection, | 367 &BluetoothSocketChromeOS::DoNewConnection, |
| 386 this, | 368 this, |
| 387 device_path_, | 369 device_path_, |
| 388 base::Passed(&fd), | 370 base::Passed(&fd), |
| 389 options, | 371 options, |
| 390 callback)); | 372 callback)); |
| 391 } else { | 373 } else { |
| 392 linked_ptr<ConnectionRequest> request(new ConnectionRequest()); | 374 linked_ptr<ConnectionRequest> request(new ConnectionRequest()); |
| 393 request->device_path = device_path; | 375 request->device_path = device_path; |
| 394 request->fd = fd.Pass(); | 376 request->fd = fd.Pass(); |
| 395 request->options = options; | 377 request->options = options; |
| 396 request->callback = callback; | 378 request->callback = callback; |
| 397 | 379 |
| 398 connection_request_queue_.push(request); | 380 connection_request_queue_.push(request); |
| 399 VLOG(1) << object_path_.value() << ": Connection is now pending."; | 381 VLOG(1) << uuid_.canonical_value() << ": Connection is now pending."; |
| 400 if (accept_request_) { | 382 if (accept_request_) { |
| 401 AcceptConnectionRequest(); | 383 AcceptConnectionRequest(); |
| 402 } | 384 } |
| 403 } | 385 } |
| 404 } | 386 } |
| 405 | 387 |
| 406 void BluetoothSocketChromeOS::RequestDisconnection( | 388 void BluetoothSocketChromeOS::RequestDisconnection( |
| 407 const dbus::ObjectPath& device_path, | 389 const dbus::ObjectPath& device_path, |
| 408 const ConfirmationCallback& callback) { | 390 const ConfirmationCallback& callback) { |
| 409 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 391 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 410 VLOG(1) << object_path_.value() << ": Request disconnection"; | 392 DCHECK(profile_); |
| 393 | |
| 394 VLOG(1) << profile_->object_path().value() << ": Request disconnection"; | |
| 411 callback.Run(SUCCESS); | 395 callback.Run(SUCCESS); |
| 412 } | 396 } |
| 413 | 397 |
| 414 void BluetoothSocketChromeOS::Cancel() { | 398 void BluetoothSocketChromeOS::Cancel() { |
| 415 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 399 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 416 VLOG(1) << object_path_.value() << ": Cancel"; | 400 DCHECK(profile_); |
| 401 | |
| 402 VLOG(1) << profile_->object_path().value() << ": Cancel"; | |
| 417 | 403 |
| 418 if (!connection_request_queue_.size()) | 404 if (!connection_request_queue_.size()) |
| 419 return; | 405 return; |
| 420 | 406 |
| 421 // If the front request is being accepted mark it as cancelled, otherwise | 407 // If the front request is being accepted mark it as cancelled, otherwise |
| 422 // just pop it from the queue. | 408 // just pop it from the queue. |
| 423 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); | 409 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); |
| 424 if (!request->accepting) { | 410 if (!request->accepting) { |
| 425 request->cancelled = true; | 411 request->cancelled = true; |
| 426 } else { | 412 } else { |
| 427 connection_request_queue_.pop(); | 413 connection_request_queue_.pop(); |
| 428 } | 414 } |
| 429 } | 415 } |
| 430 | 416 |
| 431 void BluetoothSocketChromeOS::AcceptConnectionRequest() { | 417 void BluetoothSocketChromeOS::AcceptConnectionRequest() { |
| 432 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 418 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 433 DCHECK(accept_request_.get()); | 419 DCHECK(accept_request_.get()); |
| 434 DCHECK(connection_request_queue_.size() >= 1); | 420 DCHECK(connection_request_queue_.size() >= 1); |
| 421 DCHECK(profile_); | |
| 435 | 422 |
| 436 VLOG(1) << object_path_.value() << ": Accepting pending connection."; | 423 VLOG(1) << profile_->object_path().value() |
| 424 << ": Accepting pending connection."; | |
| 437 | 425 |
| 438 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); | 426 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); |
| 439 request->accepting = true; | 427 request->accepting = true; |
| 440 | 428 |
| 441 BluetoothDeviceChromeOS* device = | 429 BluetoothDeviceChromeOS* device = |
| 442 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> | 430 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> |
| 443 GetDeviceWithPath(request->device_path); | 431 GetDeviceWithPath(request->device_path); |
| 444 DCHECK(device); | 432 DCHECK(device); |
| 445 | 433 |
| 446 scoped_refptr<BluetoothSocketChromeOS> client_socket = | 434 scoped_refptr<BluetoothSocketChromeOS> client_socket = |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 467 | 455 |
| 468 void BluetoothSocketChromeOS::DoNewConnection( | 456 void BluetoothSocketChromeOS::DoNewConnection( |
| 469 const dbus::ObjectPath& device_path, | 457 const dbus::ObjectPath& device_path, |
| 470 scoped_ptr<dbus::FileDescriptor> fd, | 458 scoped_ptr<dbus::FileDescriptor> fd, |
| 471 const BluetoothProfileServiceProvider::Delegate::Options& options, | 459 const BluetoothProfileServiceProvider::Delegate::Options& options, |
| 472 const ConfirmationCallback& callback) { | 460 const ConfirmationCallback& callback) { |
| 473 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 461 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
| 474 base::ThreadRestrictions::AssertIOAllowed(); | 462 base::ThreadRestrictions::AssertIOAllowed(); |
| 475 fd->CheckValidity(); | 463 fd->CheckValidity(); |
| 476 | 464 |
| 477 VLOG(1) << object_path_.value() << ": Validity check complete."; | 465 VLOG(1) << uuid_.canonical_value() << ": Validity check complete."; |
| 478 if (!fd->is_valid()) { | 466 if (!fd->is_valid()) { |
| 479 LOG(WARNING) << object_path_.value() << " :" << fd->value() | 467 LOG(WARNING) << uuid_.canonical_value() << " :" << fd->value() |
| 480 << ": Invalid file descriptor received from Bluetooth Daemon."; | 468 << ": Invalid file descriptor received from Bluetooth Daemon."; |
| 481 ui_task_runner()->PostTask(FROM_HERE, | 469 ui_task_runner()->PostTask(FROM_HERE, |
| 482 base::Bind(callback, REJECTED));; | 470 base::Bind(callback, REJECTED));; |
| 483 return; | 471 return; |
| 484 } | 472 } |
| 485 | 473 |
| 486 if (tcp_socket()) { | 474 if (tcp_socket()) { |
| 487 LOG(WARNING) << object_path_.value() << ": Already connected"; | 475 LOG(WARNING) << uuid_.canonical_value() << ": Already connected"; |
| 488 ui_task_runner()->PostTask(FROM_HERE, | 476 ui_task_runner()->PostTask(FROM_HERE, |
| 489 base::Bind(callback, REJECTED));; | 477 base::Bind(callback, REJECTED));; |
| 490 return; | 478 return; |
| 491 } | 479 } |
| 492 | 480 |
| 493 ResetTCPSocket(); | 481 ResetTCPSocket(); |
| 494 | 482 |
| 495 // Note: We don't have a meaningful |IPEndPoint|, but that is ok since the | 483 // Note: We don't have a meaningful |IPEndPoint|, but that is ok since the |
| 496 // TCPSocket implementation does not actually require one. | 484 // TCPSocket implementation does not actually require one. |
| 497 int net_result = tcp_socket()->AdoptConnectedSocket(fd->value(), | 485 int net_result = tcp_socket()->AdoptConnectedSocket(fd->value(), |
| 498 net::IPEndPoint()); | 486 net::IPEndPoint()); |
| 499 if (net_result != net::OK) { | 487 if (net_result != net::OK) { |
| 500 LOG(WARNING) << object_path_.value() << ": Error adopting socket: " | 488 LOG(WARNING) << uuid_.canonical_value() << ": Error adopting socket: " |
| 501 << std::string(net::ErrorToString(net_result)); | 489 << std::string(net::ErrorToString(net_result)); |
| 502 ui_task_runner()->PostTask(FROM_HERE, | 490 ui_task_runner()->PostTask(FROM_HERE, |
| 503 base::Bind(callback, REJECTED));; | 491 base::Bind(callback, REJECTED));; |
| 504 return; | 492 return; |
| 505 } | 493 } |
| 506 | 494 |
| 507 VLOG(2) << object_path_.value() << ": Taking descriptor, confirming success."; | 495 VLOG(2) << uuid_.canonical_value() |
| 496 << ": Taking descriptor, confirming success."; | |
| 508 fd->TakeValue(); | 497 fd->TakeValue(); |
| 509 ui_task_runner()->PostTask(FROM_HERE, | 498 ui_task_runner()->PostTask(FROM_HERE, |
| 510 base::Bind(callback, SUCCESS));; | 499 base::Bind(callback, SUCCESS));; |
| 511 } | 500 } |
| 512 | 501 |
| 513 void BluetoothSocketChromeOS::OnNewConnection( | 502 void BluetoothSocketChromeOS::OnNewConnection( |
| 514 scoped_refptr<BluetoothSocket> socket, | 503 scoped_refptr<BluetoothSocket> socket, |
| 515 const ConfirmationCallback& callback, | 504 const ConfirmationCallback& callback, |
| 516 Status status) { | 505 Status status) { |
| 517 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 506 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 547 | 536 |
| 548 while (connection_request_queue_.size() > 0) { | 537 while (connection_request_queue_.size() > 0) { |
| 549 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); | 538 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); |
| 550 request->callback.Run(REJECTED); | 539 request->callback.Run(REJECTED); |
| 551 connection_request_queue_.pop(); | 540 connection_request_queue_.pop(); |
| 552 } | 541 } |
| 553 } | 542 } |
| 554 | 543 |
| 555 void BluetoothSocketChromeOS::UnregisterProfile() { | 544 void BluetoothSocketChromeOS::UnregisterProfile() { |
| 556 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 545 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 557 DCHECK(!object_path_.value().empty()); | 546 DCHECK(profile_); |
| 558 DCHECK(profile_.get()); | |
| 559 | 547 |
| 560 VLOG(1) << object_path_.value() << ": Unregister profile"; | 548 VLOG(1) << profile_->object_path().value() << ": Release profile"; |
| 561 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> | |
| 562 UnregisterProfile( | |
| 563 object_path_, | |
| 564 base::Bind(&BluetoothSocketChromeOS::OnUnregisterProfile, | |
| 565 this, | |
| 566 object_path_), | |
| 567 base::Bind(&BluetoothSocketChromeOS::OnUnregisterProfileError, | |
| 568 this, | |
| 569 object_path_)); | |
| 570 | 549 |
| 571 profile_.reset(); | 550 profile_->RemoveDelegate(device_path_); |
| 572 object_path_ = dbus::ObjectPath(""); | |
| 573 } | |
| 574 | 551 |
| 575 void BluetoothSocketChromeOS::OnUnregisterProfile( | 552 profile_ = NULL; |
| 576 const dbus::ObjectPath& object_path) { | |
| 577 VLOG(1) << object_path.value() << ": Profile unregistered"; | |
| 578 } | |
| 579 | |
| 580 void BluetoothSocketChromeOS::OnUnregisterProfileError( | |
| 581 const dbus::ObjectPath& object_path, | |
| 582 const std::string& error_name, | |
| 583 const std::string& error_message) { | |
| 584 // It's okay if the profile doesn't exist, it means we haven't registered it | |
| 585 // yet. | |
| 586 if (error_name == bluetooth_profile_manager::kErrorDoesNotExist) | |
| 587 return; | |
| 588 | |
| 589 LOG(WARNING) << object_path_.value() << ": Failed to unregister profile: " | |
| 590 << error_name << ": " << error_message; | |
| 591 } | 553 } |
| 592 | 554 |
| 593 } // namespace chromeos | 555 } // namespace chromeos |
| OLD | NEW |