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

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: fix profile memory leaks when adapter is gone Created 5 years, 10 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 void Close() override; 75 void Close() override;
74 void Disconnect(const base::Closure& callback) override; 76 void Disconnect(const base::Closure& callback) override;
75 void Accept(const AcceptCompletionCallback& success_callback, 77 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 ~BluetoothSocketChromeOS() override; 81 ~BluetoothSocketChromeOS() override;
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 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(); 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 void Released() override; 114 void Released() override;
116 void NewConnection( 115 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 void RequestDisconnection(const dbus::ObjectPath& device_path, 120 void RequestDisconnection(const dbus::ObjectPath& device_path,
122 const ConfirmationCallback& callback) override; 121 const ConfirmationCallback& callback) override;
(...skipping 21 matching lines...) Expand all
144 // complete calls |callback| on the UI thread with an appropriate argument 143 // complete calls |callback| on the UI thread with an appropriate argument
145 // indicating success or failure. 144 // indicating success or failure.
146 void DoConnect(scoped_ptr<dbus::FileDescriptor> fd, 145 void DoConnect(scoped_ptr<dbus::FileDescriptor> fd,
147 const ConfirmationCallback& callback); 146 const ConfirmationCallback& callback);
148 147
149 // Method run to clean-up a listening socket. 148 // Method run to clean-up a listening socket.
150 void DoCloseListening(); 149 void DoCloseListening();
151 150
152 // Unregister the underlying profile client object from the Bluetooth Daemon. 151 // Unregister the underlying profile client object from the Bluetooth Daemon.
153 void UnregisterProfile(); 152 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);
158 153
159 // Adapter the profile is registered against; this is only present when the 154 // Releases the profile after the delegate is gone.
160 // socket is listening. 155 void ReleaseProfile(BluetoothAdapterProfileChromeOS* profile);
156
157 // Adapter the profile is registered against
161 scoped_refptr<device::BluetoothAdapter> adapter_; 158 scoped_refptr<device::BluetoothAdapter> adapter_;
162 159
163 // 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
164 // ignored if the socket is listening. 161 // ignored if the socket is listening.
165 std::string device_address_; 162 std::string device_address_;
166 dbus::ObjectPath device_path_; 163 dbus::ObjectPath device_path_;
167 164
168 // UUID of the profile being connected to, or listening on. 165 // UUID of the profile being connected to, or listening on.
169 device::BluetoothUUID uuid_; 166 device::BluetoothUUID uuid_;
170 167
171 // Copy of the profile options used for registering the profile. 168 // Copy of the profile options used for registering the profile.
172 scoped_ptr<BluetoothProfileManagerClient::Options> options_; 169 scoped_ptr<BluetoothProfileManagerClient::Options> options_;
173 170
174 // Object path of the local profile D-Bus object. 171 // The profile registered with the adapter for this socket.
175 dbus::ObjectPath object_path_; 172 BluetoothAdapterProfileChromeOS* profile_;
176
177 // Local profile D-Bus object used for receiving profile delegate methods
178 // from BlueZ.
179 scoped_ptr<BluetoothProfileServiceProvider> profile_;
180 173
181 // Pending request to an Accept() call. 174 // Pending request to an Accept() call.
182 struct AcceptRequest { 175 struct AcceptRequest {
183 AcceptRequest(); 176 AcceptRequest();
184 ~AcceptRequest(); 177 ~AcceptRequest();
185 178
186 AcceptCompletionCallback success_callback; 179 AcceptCompletionCallback success_callback;
187 ErrorCompletionCallback error_callback; 180 ErrorCompletionCallback error_callback;
188 }; 181 };
189 scoped_ptr<AcceptRequest> accept_request_; 182 scoped_ptr<AcceptRequest> accept_request_;
(...skipping 11 matching lines...) Expand all
201 bool cancelled; 194 bool cancelled;
202 }; 195 };
203 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; 196 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_;
204 197
205 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); 198 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS);
206 }; 199 };
207 200
208 } // namespace chromeos 201 } // namespace chromeos
209 202
210 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ 203 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.h ('k') | device/bluetooth/bluetooth_socket_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698