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_SOCKET_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chromeos/chromeos_export.h" | |
14 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | |
15 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | |
16 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
| 15 #include "device/bluetooth/bluetooth_export.h" |
18 #include "device/bluetooth/bluetooth_socket.h" | 16 #include "device/bluetooth/bluetooth_socket.h" |
19 #include "device/bluetooth/bluetooth_socket_net.h" | 17 #include "device/bluetooth/bluetooth_socket_net.h" |
20 #include "device/bluetooth/bluetooth_uuid.h" | 18 #include "device/bluetooth/bluetooth_uuid.h" |
| 19 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" |
| 20 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" |
21 | 21 |
22 namespace dbus { | 22 namespace dbus { |
23 class FileDescriptor; | 23 class FileDescriptor; |
24 } // namespace dbus | 24 } // namespace dbus |
25 | 25 |
26 namespace chromeos { | 26 namespace chromeos { |
27 | 27 |
28 class BluetoothDeviceChromeOS; | 28 class BluetoothDeviceChromeOS; |
29 class BluetoothAdapterChromeOS; | 29 class BluetoothAdapterChromeOS; |
30 class BluetoothAdapterProfileChromeOS; | 30 class BluetoothAdapterProfileChromeOS; |
31 | 31 |
32 // The BluetoothSocketChromeOS class implements BluetoothSocket for the | 32 // The BluetoothSocketChromeOS class implements BluetoothSocket for the |
33 // Chrome OS platform. | 33 // Chrome OS platform. |
34 // | 34 // |
35 // This class is not thread-safe, but is only called from the UI thread. | 35 // This class is not thread-safe, but is only called from the UI thread. |
36 class CHROMEOS_EXPORT BluetoothSocketChromeOS | 36 class DEVICE_BLUETOOTH_EXPORT BluetoothSocketChromeOS |
37 : public device::BluetoothSocketNet, | 37 : public device::BluetoothSocketNet, |
38 public device::BluetoothAdapter::Observer, | 38 public device::BluetoothAdapter::Observer, |
39 public BluetoothProfileServiceProvider::Delegate { | 39 public bluez::BluetoothProfileServiceProvider::Delegate { |
40 public: | 40 public: |
41 enum SecurityLevel { | 41 enum SecurityLevel { |
42 SECURITY_LEVEL_LOW, | 42 SECURITY_LEVEL_LOW, |
43 SECURITY_LEVEL_MEDIUM | 43 SECURITY_LEVEL_MEDIUM |
44 }; | 44 }; |
45 | 45 |
46 static scoped_refptr<BluetoothSocketChromeOS> CreateBluetoothSocket( | 46 static scoped_refptr<BluetoothSocketChromeOS> CreateBluetoothSocket( |
47 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 47 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
48 scoped_refptr<device::BluetoothSocketThread> socket_thread); | 48 scoped_refptr<device::BluetoothSocketThread> socket_thread); |
49 | 49 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 // BluetoothAdapter::Observer: | 106 // BluetoothAdapter::Observer: |
107 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 107 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
108 bool present) override; | 108 bool present) override; |
109 | 109 |
110 // Called by dbus:: on completion of the RegisterProfile() method call | 110 // Called by dbus:: on completion of the RegisterProfile() method call |
111 // triggered as a result of the adapter becoming present again. | 111 // triggered as a result of the adapter becoming present again. |
112 void OnInternalRegisterProfile(BluetoothAdapterProfileChromeOS* profile); | 112 void OnInternalRegisterProfile(BluetoothAdapterProfileChromeOS* profile); |
113 void OnInternalRegisterProfileError(const std::string& error_message); | 113 void OnInternalRegisterProfileError(const std::string& error_message); |
114 | 114 |
115 // BluetoothProfileServiceProvider::Delegate: | 115 // bluez::BluetoothProfileServiceProvider::Delegate: |
116 void Released() override; | 116 void Released() override; |
117 void NewConnection( | 117 void NewConnection( |
118 const dbus::ObjectPath& device_path, | 118 const dbus::ObjectPath& device_path, |
119 scoped_ptr<dbus::FileDescriptor> fd, | 119 scoped_ptr<dbus::FileDescriptor> fd, |
120 const BluetoothProfileServiceProvider::Delegate::Options& options, | 120 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, |
121 const ConfirmationCallback& callback) override; | 121 const ConfirmationCallback& callback) override; |
122 void RequestDisconnection(const dbus::ObjectPath& device_path, | 122 void RequestDisconnection(const dbus::ObjectPath& device_path, |
123 const ConfirmationCallback& callback) override; | 123 const ConfirmationCallback& callback) override; |
124 void Cancel() override; | 124 void Cancel() override; |
125 | 125 |
126 // Method run to accept a single incoming connection. | 126 // Method run to accept a single incoming connection. |
127 void AcceptConnectionRequest(); | 127 void AcceptConnectionRequest(); |
128 | 128 |
129 // Method run on the socket thread to validate the file descriptor of a new | 129 // Method run on the socket thread to validate the file descriptor of a new |
130 // connection and set up the underlying net::TCPSocket() for it. | 130 // connection and set up the underlying net::TCPSocket() for it. |
131 void DoNewConnection( | 131 void DoNewConnection( |
132 const dbus::ObjectPath& device_path, | 132 const dbus::ObjectPath& device_path, |
133 scoped_ptr<dbus::FileDescriptor> fd, | 133 scoped_ptr<dbus::FileDescriptor> fd, |
134 const BluetoothProfileServiceProvider::Delegate::Options& options, | 134 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, |
135 const ConfirmationCallback& callback); | 135 const ConfirmationCallback& callback); |
136 | 136 |
137 // Method run on the UI thread after a new connection has been accepted and | 137 // Method run on the UI thread after a new connection has been accepted and |
138 // a socket allocated in |socket|. Takes care of calling the Accept() | 138 // a socket allocated in |socket|. Takes care of calling the Accept() |
139 // callback and |callback| with the right arguments based on |status|. | 139 // callback and |callback| with the right arguments based on |status|. |
140 void OnNewConnection(scoped_refptr<BluetoothSocket> socket, | 140 void OnNewConnection(scoped_refptr<BluetoothSocket> socket, |
141 const ConfirmationCallback& callback, | 141 const ConfirmationCallback& callback, |
142 Status status); | 142 Status status); |
143 | 143 |
144 // Method run on the socket thread with a valid file descriptor |fd|, once | 144 // Method run on the socket thread with a valid file descriptor |fd|, once |
(...skipping 14 matching lines...) Expand all Loading... |
159 | 159 |
160 // Address and D-Bus object path of the device being connected to, empty and | 160 // Address and D-Bus object path of the device being connected to, empty and |
161 // ignored if the socket is listening. | 161 // ignored if the socket is listening. |
162 std::string device_address_; | 162 std::string device_address_; |
163 dbus::ObjectPath device_path_; | 163 dbus::ObjectPath device_path_; |
164 | 164 |
165 // UUID of the profile being connected to, or listening on. | 165 // UUID of the profile being connected to, or listening on. |
166 device::BluetoothUUID uuid_; | 166 device::BluetoothUUID uuid_; |
167 | 167 |
168 // Copy of the profile options used for registering the profile. | 168 // Copy of the profile options used for registering the profile. |
169 scoped_ptr<BluetoothProfileManagerClient::Options> options_; | 169 scoped_ptr<bluez::BluetoothProfileManagerClient::Options> options_; |
170 | 170 |
171 // The profile registered with the adapter for this socket. | 171 // The profile registered with the adapter for this socket. |
172 BluetoothAdapterProfileChromeOS* profile_; | 172 BluetoothAdapterProfileChromeOS* profile_; |
173 | 173 |
174 // Pending request to an Accept() call. | 174 // Pending request to an Accept() call. |
175 struct AcceptRequest { | 175 struct AcceptRequest { |
176 AcceptRequest(); | 176 AcceptRequest(); |
177 ~AcceptRequest(); | 177 ~AcceptRequest(); |
178 | 178 |
179 AcceptCompletionCallback success_callback; | 179 AcceptCompletionCallback success_callback; |
180 ErrorCompletionCallback error_callback; | 180 ErrorCompletionCallback error_callback; |
181 }; | 181 }; |
182 scoped_ptr<AcceptRequest> accept_request_; | 182 scoped_ptr<AcceptRequest> accept_request_; |
183 | 183 |
184 // Queue of incoming connection requests. | 184 // Queue of incoming connection requests. |
185 struct ConnectionRequest { | 185 struct ConnectionRequest { |
186 ConnectionRequest(); | 186 ConnectionRequest(); |
187 ~ConnectionRequest(); | 187 ~ConnectionRequest(); |
188 | 188 |
189 dbus::ObjectPath device_path; | 189 dbus::ObjectPath device_path; |
190 scoped_ptr<dbus::FileDescriptor> fd; | 190 scoped_ptr<dbus::FileDescriptor> fd; |
191 BluetoothProfileServiceProvider::Delegate::Options options; | 191 bluez::BluetoothProfileServiceProvider::Delegate::Options options; |
192 ConfirmationCallback callback; | 192 ConfirmationCallback callback; |
193 bool accepting; | 193 bool accepting; |
194 bool cancelled; | 194 bool cancelled; |
195 }; | 195 }; |
196 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; | 196 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; |
197 | 197 |
198 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); | 198 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); |
199 }; | 199 }; |
200 | 200 |
201 } // namespace chromeos | 201 } // namespace chromeos |
202 | 202 |
203 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ | 203 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |
OLD | NEW |