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_profile_chromeos.h" | 5 #include "device/bluetooth/bluetooth_profile_chromeos.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "dbus/bus.h" | 23 #include "dbus/bus.h" |
24 #include "dbus/file_descriptor.h" | 24 #include "dbus/file_descriptor.h" |
25 #include "dbus/object_path.h" | 25 #include "dbus/object_path.h" |
26 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 26 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
27 #include "device/bluetooth/bluetooth_adapter_factory.h" | 27 #include "device/bluetooth/bluetooth_adapter_factory.h" |
28 #include "device/bluetooth/bluetooth_device.h" | 28 #include "device/bluetooth/bluetooth_device.h" |
29 #include "device/bluetooth/bluetooth_device_chromeos.h" | 29 #include "device/bluetooth/bluetooth_device_chromeos.h" |
30 #include "device/bluetooth/bluetooth_profile.h" | 30 #include "device/bluetooth/bluetooth_profile.h" |
31 #include "device/bluetooth/bluetooth_socket.h" | 31 #include "device/bluetooth/bluetooth_socket.h" |
32 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 32 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 33 #include "device/bluetooth/bluetooth_socket_thread.h" |
33 #include "third_party/cros_system_api/dbus/service_constants.h" | 34 #include "third_party/cros_system_api/dbus/service_constants.h" |
34 | 35 |
35 using device::BluetoothAdapter; | 36 using device::BluetoothAdapter; |
36 using device::BluetoothAdapterFactory; | 37 using device::BluetoothAdapterFactory; |
37 using device::BluetoothDevice; | 38 using device::BluetoothDevice; |
38 using device::BluetoothProfile; | 39 using device::BluetoothProfile; |
39 using device::BluetoothSocket; | 40 using device::BluetoothSocket; |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Check the validity of a file descriptor received from D-Bus. Must be run | 44 // Check the validity of a file descriptor received from D-Bus. Must be run |
44 // on a thread where i/o is permitted. | 45 // on a thread where i/o is permitted. |
45 scoped_ptr<dbus::FileDescriptor> CheckValidity( | 46 scoped_ptr<dbus::FileDescriptor> CheckValidity( |
46 scoped_ptr<dbus::FileDescriptor> fd) { | 47 scoped_ptr<dbus::FileDescriptor> fd) { |
47 base::ThreadRestrictions::AssertIOAllowed(); | 48 base::ThreadRestrictions::AssertIOAllowed(); |
48 fd->CheckValidity(); | 49 fd->CheckValidity(); |
49 return fd.Pass(); | 50 return fd.Pass(); |
50 } | 51 } |
51 | 52 |
52 } // namespace | 53 } // namespace |
53 | 54 |
54 | 55 |
55 namespace chromeos { | 56 namespace chromeos { |
56 | 57 |
57 BluetoothProfileChromeOS::BluetoothProfileChromeOS() | 58 BluetoothProfileChromeOS::BluetoothProfileChromeOS( |
58 : weak_ptr_factory_(this) { | 59 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 60 scoped_refptr<device::BluetoothSocketThread> socket_thread) |
| 61 : ui_task_runner_(ui_task_runner), |
| 62 socket_thread_(socket_thread), |
| 63 weak_ptr_factory_(this) { |
59 } | 64 } |
60 | 65 |
61 BluetoothProfileChromeOS::~BluetoothProfileChromeOS() { | 66 BluetoothProfileChromeOS::~BluetoothProfileChromeOS() { |
62 DCHECK(object_path_.value().empty()); | 67 DCHECK(object_path_.value().empty()); |
63 DCHECK(profile_.get() == NULL); | 68 DCHECK(profile_.get() == NULL); |
64 | 69 |
65 if (adapter_.get()) { | 70 if (adapter_.get()) { |
66 adapter_->RemoveObserver(this); | 71 adapter_->RemoveObserver(this); |
67 adapter_ = NULL; | 72 adapter_ = NULL; |
68 } | 73 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 const dbus::ObjectPath& device_path, | 279 const dbus::ObjectPath& device_path, |
275 const BluetoothProfileServiceProvider::Delegate::Options& options, | 280 const BluetoothProfileServiceProvider::Delegate::Options& options, |
276 const ConfirmationCallback& callback, | 281 const ConfirmationCallback& callback, |
277 scoped_ptr<dbus::FileDescriptor> fd) { | 282 scoped_ptr<dbus::FileDescriptor> fd) { |
278 VLOG(1) << object_path_.value() << ": Validity check complete"; | 283 VLOG(1) << object_path_.value() << ": Validity check complete"; |
279 if (!fd->is_valid()) { | 284 if (!fd->is_valid()) { |
280 callback.Run(REJECTED); | 285 callback.Run(REJECTED); |
281 return; | 286 return; |
282 } | 287 } |
283 | 288 |
284 callback.Run(SUCCESS); | 289 scoped_refptr<BluetoothSocketChromeOS> socket = |
| 290 BluetoothSocketChromeOS::CreateBluetoothSocket( |
| 291 ui_task_runner_, |
| 292 socket_thread_, |
| 293 NULL, |
| 294 net::NetLog::Source()); |
| 295 socket->Connect(fd.Pass(), |
| 296 base::Bind(&BluetoothProfileChromeOS::OnConnect, |
| 297 weak_ptr_factory_.GetWeakPtr(), |
| 298 device_path, |
| 299 socket, |
| 300 callback), |
| 301 base::Bind(&BluetoothProfileChromeOS::OnConnectError, |
| 302 weak_ptr_factory_.GetWeakPtr(), |
| 303 callback)); |
| 304 } |
| 305 |
| 306 void BluetoothProfileChromeOS::OnConnect( |
| 307 const dbus::ObjectPath& device_path, |
| 308 scoped_refptr<BluetoothSocketChromeOS> socket, |
| 309 const ConfirmationCallback& callback) { |
| 310 VLOG(1) << object_path_.value() << ": Profile connection complete"; |
285 | 311 |
286 BluetoothDeviceChromeOS* device = | 312 BluetoothDeviceChromeOS* device = |
287 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> | 313 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> |
288 GetDeviceWithPath(device_path); | 314 GetDeviceWithPath(device_path); |
289 DCHECK(device); | 315 DCHECK(device); |
290 | 316 |
291 scoped_refptr<BluetoothSocket> socket(( | |
292 BluetoothSocketChromeOS::Create(fd.get()))); | |
293 connection_callback_.Run(device, socket); | 317 connection_callback_.Run(device, socket); |
| 318 callback.Run(SUCCESS); |
| 319 } |
| 320 |
| 321 void BluetoothProfileChromeOS::OnConnectError( |
| 322 const ConfirmationCallback& callback, |
| 323 const std::string& error_message) { |
| 324 VLOG(1) << object_path_.value() << ": Profile connection failed: " |
| 325 << error_message; |
| 326 |
| 327 callback.Run(REJECTED); |
294 } | 328 } |
295 | 329 |
296 } // namespace chromeos | 330 } // namespace chromeos |
OLD | NEW |