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" | 13 #include "chromeos/chromeos_export.h" |
14 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 14 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
15 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | 15 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
18 #include "device/bluetooth/bluetooth_socket.h" | 18 #include "device/bluetooth/bluetooth_socket.h" |
19 #include "device/bluetooth/bluetooth_socket_net.h" | 19 #include "device/bluetooth/bluetooth_socket_net.h" |
20 #include "device/bluetooth/bluetooth_uuid.h" | 20 #include "device/bluetooth/bluetooth_uuid.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; | |
30 class BluetoothAdapterProfileChromeOS; | |
31 | 29 |
32 // The BluetoothSocketChromeOS class implements BluetoothSocket for the | 30 // The BluetoothSocketChromeOS class implements BluetoothSocket for the |
33 // Chrome OS platform. | 31 // Chrome OS platform. |
34 class CHROMEOS_EXPORT BluetoothSocketChromeOS | 32 class CHROMEOS_EXPORT BluetoothSocketChromeOS |
35 : public device::BluetoothSocketNet, | 33 : public device::BluetoothSocketNet, |
36 public device::BluetoothAdapter::Observer, | 34 public device::BluetoothAdapter::Observer, |
37 public BluetoothProfileServiceProvider::Delegate { | 35 public BluetoothProfileServiceProvider::Delegate { |
38 public: | 36 public: |
39 enum SecurityLevel { | 37 enum SecurityLevel { |
40 SECURITY_LEVEL_LOW, | 38 SECURITY_LEVEL_LOW, |
(...skipping 29 matching lines...) Expand all Loading... |
70 const device::BluetoothAdapter::ServiceOptions& service_options, | 68 const device::BluetoothAdapter::ServiceOptions& service_options, |
71 const base::Closure& success_callback, | 69 const base::Closure& success_callback, |
72 const ErrorCompletionCallback& error_callback); | 70 const ErrorCompletionCallback& error_callback); |
73 | 71 |
74 // BluetoothSocket: | 72 // BluetoothSocket: |
75 void Close() override; | 73 void Close() override; |
76 void Disconnect(const base::Closure& callback) override; | 74 void Disconnect(const base::Closure& callback) override; |
77 void Accept(const AcceptCompletionCallback& success_callback, | 75 void Accept(const AcceptCompletionCallback& success_callback, |
78 const ErrorCompletionCallback& error_callback) override; | 76 const ErrorCompletionCallback& error_callback) override; |
79 | 77 |
| 78 // Returns the object path of the socket. |
| 79 const dbus::ObjectPath& object_path() const { return object_path_; } |
| 80 |
80 protected: | 81 protected: |
81 ~BluetoothSocketChromeOS() override; | 82 ~BluetoothSocketChromeOS() override; |
82 | 83 |
83 private: | 84 private: |
84 BluetoothSocketChromeOS( | 85 BluetoothSocketChromeOS( |
85 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 86 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
86 scoped_refptr<device::BluetoothSocketThread> socket_thread); | 87 scoped_refptr<device::BluetoothSocketThread> socket_thread); |
87 | 88 |
88 // Register the underlying profile client object with the Bluetooth Daemon. | 89 // Register the underlying profile client object with the Bluetooth Daemon. |
89 void RegisterProfile(BluetoothAdapterChromeOS* adapter, | 90 void RegisterProfile(const base::Closure& success_callback, |
90 const base::Closure& success_callback, | |
91 const ErrorCompletionCallback& error_callback); | 91 const ErrorCompletionCallback& error_callback); |
92 void OnRegisterProfile(const base::Closure& success_callback, | 92 void OnRegisterProfile(const base::Closure& success_callback, |
93 const ErrorCompletionCallback& error_callback, | 93 const ErrorCompletionCallback& error_callback); |
94 BluetoothAdapterProfileChromeOS* profile); | |
95 void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, | 94 void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, |
| 95 const std::string& error_name, |
96 const std::string& error_message); | 96 const std::string& error_message); |
97 | 97 |
98 // Called by dbus:: on completion of the ConnectProfile() method. | 98 // Called by dbus:: on completion of the ConnectProfile() method. |
99 void OnConnectProfile(const base::Closure& success_callback); | 99 void OnConnectProfile(const base::Closure& success_callback); |
100 void OnConnectProfileError(const ErrorCompletionCallback& error_callback, | 100 void OnConnectProfileError(const ErrorCompletionCallback& error_callback, |
101 const std::string& error_name, | 101 const std::string& error_name, |
102 const std::string& error_message); | 102 const std::string& error_message); |
103 | 103 |
104 // BluetoothAdapter::Observer: | 104 // BluetoothAdapter::Observer: |
105 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 105 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
106 bool present) override; | 106 bool present) override; |
107 | 107 |
108 // Called by dbus:: on completion of the RegisterProfile() method call | 108 // Called by dbus:: on completion of the RegisterProfile() method call |
109 // triggered as a result of the adapter becoming present again. | 109 // triggered as a result of the adapter becoming present again. |
110 void OnInternalRegisterProfile(BluetoothAdapterProfileChromeOS* profile); | 110 void OnInternalRegisterProfile(); |
111 void OnInternalRegisterProfileError(const std::string& error_message); | 111 void OnInternalRegisterProfileError(const std::string& error_name, |
| 112 const std::string& error_message); |
112 | 113 |
113 // BluetoothProfileServiceProvider::Delegate: | 114 // BluetoothProfileServiceProvider::Delegate: |
114 void Released() override; | 115 void Released() override; |
115 void NewConnection( | 116 void NewConnection( |
116 const dbus::ObjectPath& device_path, | 117 const dbus::ObjectPath& device_path, |
117 scoped_ptr<dbus::FileDescriptor> fd, | 118 scoped_ptr<dbus::FileDescriptor> fd, |
118 const BluetoothProfileServiceProvider::Delegate::Options& options, | 119 const BluetoothProfileServiceProvider::Delegate::Options& options, |
119 const ConfirmationCallback& callback) override; | 120 const ConfirmationCallback& callback) override; |
120 void RequestDisconnection(const dbus::ObjectPath& device_path, | 121 void RequestDisconnection(const dbus::ObjectPath& device_path, |
121 const ConfirmationCallback& callback) override; | 122 const ConfirmationCallback& callback) override; |
(...skipping 21 matching lines...) Expand all Loading... |
143 // complete calls |callback| on the UI thread with an appropriate argument | 144 // complete calls |callback| on the UI thread with an appropriate argument |
144 // indicating success or failure. | 145 // indicating success or failure. |
145 void DoConnect(scoped_ptr<dbus::FileDescriptor> fd, | 146 void DoConnect(scoped_ptr<dbus::FileDescriptor> fd, |
146 const ConfirmationCallback& callback); | 147 const ConfirmationCallback& callback); |
147 | 148 |
148 // Method run to clean-up a listening socket. | 149 // Method run to clean-up a listening socket. |
149 void DoCloseListening(); | 150 void DoCloseListening(); |
150 | 151 |
151 // Unregister the underlying profile client object from the Bluetooth Daemon. | 152 // Unregister the underlying profile client object from the Bluetooth Daemon. |
152 void UnregisterProfile(); | 153 void UnregisterProfile(); |
| 154 void OnUnregisterProfile(const dbus::ObjectPath& object_path); |
| 155 void OnUnregisterProfileError(const dbus::ObjectPath& object_path, |
| 156 const std::string& error_name, |
| 157 const std::string& error_message); |
153 | 158 |
154 // Releases the profile after the delegate is gone. | 159 // Adapter the profile is registered against; this is only present when the |
155 void ReleaseProfile(); | 160 // socket is listening. |
156 | |
157 // Adapter the profile is registered against | |
158 scoped_refptr<device::BluetoothAdapter> adapter_; | 161 scoped_refptr<device::BluetoothAdapter> adapter_; |
159 | 162 |
160 // Address and D-Bus object path of the device being connected to, empty and | 163 // Address and D-Bus object path of the device being connected to, empty and |
161 // ignored if the socket is listening. | 164 // ignored if the socket is listening. |
162 std::string device_address_; | 165 std::string device_address_; |
163 dbus::ObjectPath device_path_; | 166 dbus::ObjectPath device_path_; |
164 | 167 |
165 // UUID of the profile being connected to, or listening on. | 168 // UUID of the profile being connected to, or listening on. |
166 device::BluetoothUUID uuid_; | 169 device::BluetoothUUID uuid_; |
167 | 170 |
168 // Copy of the profile options used for registering the profile. | 171 // Copy of the profile options used for registering the profile. |
169 scoped_ptr<BluetoothProfileManagerClient::Options> options_; | 172 scoped_ptr<BluetoothProfileManagerClient::Options> options_; |
170 | 173 |
171 // The profile registered with the adapter for this socket. | 174 // Object path of the local profile D-Bus object. |
172 BluetoothAdapterProfileChromeOS* profile_; | 175 dbus::ObjectPath object_path_; |
| 176 |
| 177 // Local profile D-Bus object used for receiving profile delegate methods |
| 178 // from BlueZ. |
| 179 scoped_ptr<BluetoothProfileServiceProvider> profile_; |
173 | 180 |
174 // Pending request to an Accept() call. | 181 // Pending request to an Accept() call. |
175 struct AcceptRequest { | 182 struct AcceptRequest { |
176 AcceptRequest(); | 183 AcceptRequest(); |
177 ~AcceptRequest(); | 184 ~AcceptRequest(); |
178 | 185 |
179 AcceptCompletionCallback success_callback; | 186 AcceptCompletionCallback success_callback; |
180 ErrorCompletionCallback error_callback; | 187 ErrorCompletionCallback error_callback; |
181 }; | 188 }; |
182 scoped_ptr<AcceptRequest> accept_request_; | 189 scoped_ptr<AcceptRequest> accept_request_; |
(...skipping 11 matching lines...) Expand all Loading... |
194 bool cancelled; | 201 bool cancelled; |
195 }; | 202 }; |
196 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; | 203 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; |
197 | 204 |
198 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); | 205 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); |
199 }; | 206 }; |
200 | 207 |
201 } // namespace chromeos | 208 } // namespace chromeos |
202 | 209 |
203 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ | 210 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |
OLD | NEW |