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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/sequenced_task_runner.h" |
14 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 16 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
16 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | 17 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
17 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_profile.h" | 20 #include "device/bluetooth/bluetooth_profile.h" |
20 #include "device/bluetooth/bluetooth_uuid.h" | 21 #include "device/bluetooth/bluetooth_uuid.h" |
21 | 22 |
22 namespace dbus { | 23 namespace dbus { |
23 | 24 |
24 class FileDescriptor; | 25 class FileDescriptor; |
25 | 26 |
26 } // namespace dbus | 27 } // namespace dbus |
27 | 28 |
| 29 namespace device { |
| 30 class BluetoothSocketThread; |
| 31 } // namespace device |
| 32 |
28 namespace chromeos { | 33 namespace chromeos { |
29 | 34 |
| 35 class BluetoothSocketChromeOS; |
| 36 |
30 // The BluetoothProfileChromeOS class implements BluetoothProfile for the | 37 // The BluetoothProfileChromeOS class implements BluetoothProfile for the |
31 // Chrome OS platform. | 38 // Chrome OS platform. |
32 class CHROMEOS_EXPORT BluetoothProfileChromeOS | 39 class CHROMEOS_EXPORT BluetoothProfileChromeOS |
33 : public device::BluetoothProfile, | 40 : public device::BluetoothProfile, |
34 public device::BluetoothAdapter::Observer, | 41 public device::BluetoothAdapter::Observer, |
35 public BluetoothProfileServiceProvider::Delegate { | 42 public BluetoothProfileServiceProvider::Delegate { |
36 public: | 43 public: |
37 // BluetoothProfile override. | 44 // BluetoothProfile override. |
38 virtual void Unregister() OVERRIDE; | 45 virtual void Unregister() OVERRIDE; |
39 virtual void SetConnectionCallback( | 46 virtual void SetConnectionCallback( |
40 const ConnectionCallback& callback) OVERRIDE; | 47 const ConnectionCallback& callback) OVERRIDE; |
41 | 48 |
42 // Return the UUID of the profile. | 49 // Return the UUID of the profile. |
43 const device::BluetoothUUID& uuid() const { return uuid_; } | 50 const device::BluetoothUUID& uuid() const { return uuid_; } |
44 | 51 |
45 private: | 52 private: |
46 friend class BluetoothProfile; | 53 friend class BluetoothProfile; |
47 | 54 |
48 BluetoothProfileChromeOS(); | 55 BluetoothProfileChromeOS( |
| 56 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 57 scoped_refptr<device::BluetoothSocketThread> socket_thread); |
49 virtual ~BluetoothProfileChromeOS(); | 58 virtual ~BluetoothProfileChromeOS(); |
50 | 59 |
51 // Called by BluetoothProfile::Register to initialize the profile object | 60 // Called by BluetoothProfile::Register to initialize the profile object |
52 // asynchronously. |uuid|, |options| and |callback| are the arguments to | 61 // asynchronously. |uuid|, |options| and |callback| are the arguments to |
53 // BluetoothProfile::Register. | 62 // BluetoothProfile::Register. |
54 void Init(const device::BluetoothUUID& uuid, | 63 void Init(const device::BluetoothUUID& uuid, |
55 const device::BluetoothProfile::Options& options, | 64 const device::BluetoothProfile::Options& options, |
56 const ProfileCallback& callback); | 65 const ProfileCallback& callback); |
57 | 66 |
58 // BluetoothProfileServiceProvider::Delegate override. | 67 // BluetoothProfileServiceProvider::Delegate override. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // the device object to be passed to the connection callback. | 107 // the device object to be passed to the connection callback. |
99 // | 108 // |
100 // The |fd| argument is moved compared to the NewConnection() call since it | 109 // The |fd| argument is moved compared to the NewConnection() call since it |
101 // becomes the result of a PostTaskAndReplyWithResult() call. | 110 // becomes the result of a PostTaskAndReplyWithResult() call. |
102 void OnCheckValidity( | 111 void OnCheckValidity( |
103 const dbus::ObjectPath& device_path, | 112 const dbus::ObjectPath& device_path, |
104 const BluetoothProfileServiceProvider::Delegate::Options& options, | 113 const BluetoothProfileServiceProvider::Delegate::Options& options, |
105 const ConfirmationCallback& callback, | 114 const ConfirmationCallback& callback, |
106 scoped_ptr<dbus::FileDescriptor> fd); | 115 scoped_ptr<dbus::FileDescriptor> fd); |
107 | 116 |
| 117 // Methods run after the socket has been connected to a |
| 118 // BluetoothSocketChromeOS instance on the I/O thread, these methods complete |
| 119 // the incoming connection calling both the Bluetooth daemon callback |
| 120 // |callback| to indicate success or failure and calling this object's |
| 121 // new connection callback method. |
| 122 void OnConnect(const dbus::ObjectPath& device_path, |
| 123 scoped_refptr<BluetoothSocketChromeOS> socket, |
| 124 const ConfirmationCallback& callback); |
| 125 void OnConnectError(const ConfirmationCallback& callback, |
| 126 const std::string& error_message); |
| 127 |
108 // UUID of the profile passed during initialization. | 128 // UUID of the profile passed during initialization. |
109 device::BluetoothUUID uuid_; | 129 device::BluetoothUUID uuid_; |
110 | 130 |
111 // Copy of the profile options passed during initialization. | 131 // Copy of the profile options passed during initialization. |
112 BluetoothProfileManagerClient::Options options_; | 132 BluetoothProfileManagerClient::Options options_; |
113 | 133 |
114 // Object path of the local profile D-Bus object. | 134 // Object path of the local profile D-Bus object. |
115 dbus::ObjectPath object_path_; | 135 dbus::ObjectPath object_path_; |
116 | 136 |
117 // Local profile D-Bus object used for receiving profile delegate methods | 137 // Local profile D-Bus object used for receiving profile delegate methods |
118 // from BlueZ. | 138 // from BlueZ. |
119 scoped_ptr<BluetoothProfileServiceProvider> profile_; | 139 scoped_ptr<BluetoothProfileServiceProvider> profile_; |
120 | 140 |
121 // Reference to the adapter object, the profile is re-registered when the | 141 // Reference to the adapter object, the profile is re-registered when the |
122 // adapter changes. | 142 // adapter changes. |
123 scoped_refptr<device::BluetoothAdapter> adapter_; | 143 scoped_refptr<device::BluetoothAdapter> adapter_; |
124 | 144 |
125 // Callback used on both outgoing and incoming connections to pass the | 145 // Callback used on both outgoing and incoming connections to pass the |
126 // connected socket to profile object owner. | 146 // connected socket to profile object owner. |
127 ConnectionCallback connection_callback_; | 147 ConnectionCallback connection_callback_; |
128 | 148 |
| 149 // UI thread task runner and socket thread object used to create sockets. |
| 150 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 151 scoped_refptr<device::BluetoothSocketThread> socket_thread_; |
| 152 |
129 // Note: This should remain the last member so it'll be destroyed and | 153 // Note: This should remain the last member so it'll be destroyed and |
130 // invalidate its weak pointers before any other members are destroyed. | 154 // invalidate its weak pointers before any other members are destroyed. |
131 base::WeakPtrFactory<BluetoothProfileChromeOS> weak_ptr_factory_; | 155 base::WeakPtrFactory<BluetoothProfileChromeOS> weak_ptr_factory_; |
132 | 156 |
133 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileChromeOS); | 157 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileChromeOS); |
134 }; | 158 }; |
135 | 159 |
136 } // namespace chromeos | 160 } // namespace chromeos |
137 | 161 |
138 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_ | 162 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_ |
OLD | NEW |