Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: device/bluetooth/bluetooth_socket_chromeos.h

Issue 851123002: Manage profiles in BluetoothAdapter on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments, slight refactor Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 BluetoothAdapterProfileChromeOS* profile);
94 void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, 95 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 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, 105 virtual 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(); 110 void OnInternalRegisterProfile(BluetoothAdapterProfileChromeOS* profile);
111 void OnInternalRegisterProfileError(const std::string& error_name, 111 void OnInternalRegisterProfileError(const std::string& error_message);
112 const std::string& error_message);
113 112
114 // BluetoothProfileServiceProvider::Delegate: 113 // BluetoothProfileServiceProvider::Delegate:
115 virtual void Released() override; 114 virtual void Released() override;
116 virtual void NewConnection( 115 virtual void NewConnection(
117 const dbus::ObjectPath& device_path, 116 const dbus::ObjectPath& device_path,
118 scoped_ptr<dbus::FileDescriptor> fd, 117 scoped_ptr<dbus::FileDescriptor> fd,
119 const BluetoothProfileServiceProvider::Delegate::Options& options, 118 const BluetoothProfileServiceProvider::Delegate::Options& options,
120 const ConfirmationCallback& callback) override; 119 const ConfirmationCallback& callback) override;
121 virtual void RequestDisconnection( 120 virtual void RequestDisconnection(
122 const dbus::ObjectPath& device_path, 121 const dbus::ObjectPath& device_path,
(...skipping 22 matching lines...) Expand all
145 // complete calls |callback| on the UI thread with an appropriate argument 144 // complete calls |callback| on the UI thread with an appropriate argument
146 // indicating success or failure. 145 // indicating success or failure.
147 void DoConnect(scoped_ptr<dbus::FileDescriptor> fd, 146 void DoConnect(scoped_ptr<dbus::FileDescriptor> fd,
148 const ConfirmationCallback& callback); 147 const ConfirmationCallback& callback);
149 148
150 // Method run to clean-up a listening socket. 149 // Method run to clean-up a listening socket.
151 void DoCloseListening(); 150 void DoCloseListening();
152 151
153 // Unregister the underlying profile client object from the Bluetooth Daemon. 152 // Unregister the underlying profile client object from the Bluetooth Daemon.
154 void UnregisterProfile(); 153 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 154
160 // Adapter the profile is registered against; this is only present when the 155 // Releases the profile after the delegate is gone.
161 // socket is listening. 156 void ReleaseProfile();
157
158 // Adapter the profile is registered against
162 scoped_refptr<device::BluetoothAdapter> adapter_; 159 scoped_refptr<device::BluetoothAdapter> adapter_;
163 160
164 // Address and D-Bus object path of the device being connected to, empty and 161 // Address and D-Bus object path of the device being connected to, empty and
165 // ignored if the socket is listening. 162 // ignored if the socket is listening.
166 std::string device_address_; 163 std::string device_address_;
167 dbus::ObjectPath device_path_; 164 dbus::ObjectPath device_path_;
168 165
169 // UUID of the profile being connected to, or listening on. 166 // UUID of the profile being connected to, or listening on.
170 device::BluetoothUUID uuid_; 167 device::BluetoothUUID uuid_;
171 168
172 // Copy of the profile options used for registering the profile. 169 // Copy of the profile options used for registering the profile.
173 scoped_ptr<BluetoothProfileManagerClient::Options> options_; 170 scoped_ptr<BluetoothProfileManagerClient::Options> options_;
174 171
175 // Object path of the local profile D-Bus object. 172 // The profile registered with the adapter for this socket.
176 dbus::ObjectPath object_path_; 173 BluetoothAdapterProfileChromeOS* profile_;
177
178 // Local profile D-Bus object used for receiving profile delegate methods
179 // from BlueZ.
180 scoped_ptr<BluetoothProfileServiceProvider> profile_;
181 174
182 // Pending request to an Accept() call. 175 // Pending request to an Accept() call.
183 struct AcceptRequest { 176 struct AcceptRequest {
184 AcceptRequest(); 177 AcceptRequest();
185 ~AcceptRequest(); 178 ~AcceptRequest();
186 179
187 AcceptCompletionCallback success_callback; 180 AcceptCompletionCallback success_callback;
188 ErrorCompletionCallback error_callback; 181 ErrorCompletionCallback error_callback;
189 }; 182 };
190 scoped_ptr<AcceptRequest> accept_request_; 183 scoped_ptr<AcceptRequest> accept_request_;
(...skipping 11 matching lines...) Expand all
202 bool cancelled; 195 bool cancelled;
203 }; 196 };
204 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; 197 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_;
205 198
206 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); 199 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS);
207 }; 200 };
208 201
209 } // namespace chromeos 202 } // namespace chromeos
210 203
211 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ 204 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698