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