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

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

Issue 935383003: Fix BluetoothAdapterProfileChromeOS lifecycle management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: further fix ownership, address comments 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_ADAPTER_PROFILE_CHROMEOS_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_
7 7
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "chromeos/dbus/bluetooth_profile_manager_client.h" 9 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
10 #include "chromeos/dbus/bluetooth_profile_service_provider.h" 10 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 11 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
12 #include "device/bluetooth/bluetooth_export.h" 12 #include "device/bluetooth/bluetooth_export.h"
13 13
14 namespace device { 14 namespace device {
15 class BluetoothUUID; 15 class BluetoothUUID;
16 } // namespace device 16 } // namespace device
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 // The BluetoothAdapterProfileChromeOS class implements a multiplexing 20 // The BluetoothAdapterProfileChromeOS class implements a multiplexing
21 // profile for custom Bluetooth services managed by a BluetoothAdapter. 21 // profile for custom Bluetooth services managed by a BluetoothAdapter.
22 // Maintains a list of delegates which may serve the profile. 22 // Maintains a list of delegates which may serve the profile.
23 // One delegate is allowed for each device. 23 // One delegate is allowed for each device.
24 //
25 // BluetoothAdapterProfileChromeOS objects are owned by the
26 // BluetoothAdapterChromeOS and allocated through Register()
24 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileChromeOS 27 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileChromeOS
25 : public chromeos::BluetoothProfileServiceProvider::Delegate { 28 : public chromeos::BluetoothProfileServiceProvider::Delegate {
26 public: 29 public:
27 // Registers a profile with the BlueZ server for |uuid| with the 30 // Registers a profile with the BlueZ server for |uuid| with the
28 // options |options|. Returns a newly allocated pointer, or nullptr 31 // options |options|. Returns a newly allocated pointer, or nullptr
29 // if there was a problem. 32 // if there was a problem.
30 static BluetoothAdapterProfileChromeOS* Register( 33 static BluetoothAdapterProfileChromeOS* Register(
Ilya Sherman 2015/02/21 01:22:10 Optional: It would be nice if this returned a scop
31 BluetoothAdapterChromeOS* adapter,
32 const device::BluetoothUUID& uuid, 34 const device::BluetoothUUID& uuid,
33 const BluetoothProfileManagerClient::Options& options, 35 const BluetoothProfileManagerClient::Options& options,
34 const base::Closure& success_callback, 36 const base::Closure& success_callback,
35 const BluetoothProfileManagerClient::ErrorCallback& error_callback); 37 const BluetoothProfileManagerClient::ErrorCallback& error_callback);
36 38
37 ~BluetoothAdapterProfileChromeOS() override; 39 ~BluetoothAdapterProfileChromeOS() override;
38 40
39 // The object path of the profile. 41 // The object path of the profile.
40 const dbus::ObjectPath& object_path() const { return object_path_; } 42 const dbus::ObjectPath& object_path() const { return object_path_; }
41 43
44 // Returns the UUID of the profile
45 const device::BluetoothUUID& uuid() const { return uuid_; }
46
42 // Add a delegate for a device associated with this profile. 47 // Add a delegate for a device associated with this profile.
43 // An empty |device_path| indicates a local listening service. 48 // An empty |device_path| indicates a local listening service.
44 // Returns true if the delegate was set, and false if the |device_path| 49 // Returns true if the delegate was set, and false if the |device_path|
45 // already had a delegate set. 50 // already had a delegate set.
46 bool SetDelegate(const dbus::ObjectPath& device_path, 51 bool SetDelegate(const dbus::ObjectPath& device_path,
47 BluetoothProfileServiceProvider::Delegate* delegate); 52 BluetoothProfileServiceProvider::Delegate* delegate);
48 53
49 // Remove the delegate for a device. |unregistered_callback| will be called 54 // Remove the delegate for a device. |unregistered_callback| will be called
50 // if this unregisters the profile. 55 // if this unregisters the profile.
51 void RemoveDelegate(const dbus::ObjectPath& device_path, 56 void RemoveDelegate(const dbus::ObjectPath& device_path,
52 const base::Closure& unregistered_callback); 57 const base::Closure& unregistered_callback);
53 58
54 // Returns the number of delegates for this profile. 59 // Returns the number of delegates for this profile.
55 size_t DelegateCount() const { return delegates_.size(); } 60 size_t DelegateCount() const { return delegates_.size(); }
56 61
57 private: 62 private:
58 BluetoothAdapterProfileChromeOS(BluetoothAdapterChromeOS* adapter, 63 BluetoothAdapterProfileChromeOS(const device::BluetoothUUID& uuid);
59 const device::BluetoothUUID& uuid);
60 64
61 // BluetoothProfileServiceProvider::Delegate: 65 // BluetoothProfileServiceProvider::Delegate:
62 void Released() override; 66 void Released() override;
63 void NewConnection( 67 void NewConnection(
64 const dbus::ObjectPath& device_path, 68 const dbus::ObjectPath& device_path,
65 scoped_ptr<dbus::FileDescriptor> fd, 69 scoped_ptr<dbus::FileDescriptor> fd,
66 const BluetoothProfileServiceProvider::Delegate::Options& options, 70 const BluetoothProfileServiceProvider::Delegate::Options& options,
67 const ConfirmationCallback& callback) override; 71 const ConfirmationCallback& callback) override;
68 void RequestDisconnection(const dbus::ObjectPath& device_path, 72 void RequestDisconnection(const dbus::ObjectPath& device_path,
69 const ConfirmationCallback& callback) override; 73 const ConfirmationCallback& callback) override;
70 void Cancel() override; 74 void Cancel() override;
71 75
72 // Called by dbus:: on completion of the D-Bus method to unregister a profile. 76 // Called by dbus:: on completion of the D-Bus method to unregister a profile.
73 void OnUnregisterProfileError(const base::Closure& unregistered_callback, 77 void OnUnregisterProfileError(const base::Closure& unregistered_callback,
74 const std::string& error_name, 78 const std::string& error_name,
75 const std::string& error_message); 79 const std::string& error_message);
76 80
77 // List of delegates which this profile is multiplexing to. 81 // List of delegates which this profile is multiplexing to.
78 std::map<std::string, BluetoothProfileServiceProvider::Delegate*> delegates_; 82 std::map<std::string, BluetoothProfileServiceProvider::Delegate*> delegates_;
79 83
80 // The UUID that this profile represents. 84 // The UUID that this profile represents.
81 const device::BluetoothUUID& uuid_; 85 const device::BluetoothUUID& uuid_;
82 86
83 // Registered dbus object path for this profile. 87 // Registered dbus object path for this profile.
84 dbus::ObjectPath object_path_; 88 dbus::ObjectPath object_path_;
85 89
86 // Profile dbus object for receiving profile method calls from BlueZ 90 // Profile dbus object for receiving profile method calls from BlueZ
87 scoped_ptr<BluetoothProfileServiceProvider> profile_; 91 scoped_ptr<BluetoothProfileServiceProvider> profile_;
88 92
89 // Adapter that owns this profile.
90 BluetoothAdapterChromeOS* adapter_;
91
92 // Note: This should remain the last member so it'll be destroyed and 93 // Note: This should remain the last member so it'll be destroyed and
93 // invalidate its weak pointers before any other members are destroyed. 94 // invalidate its weak pointers before any other members are destroyed.
94 base::WeakPtrFactory<BluetoothAdapterProfileChromeOS> weak_ptr_factory_; 95 base::WeakPtrFactory<BluetoothAdapterProfileChromeOS> weak_ptr_factory_;
95 96
96 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileChromeOS); 97 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileChromeOS);
97 }; 98 };
98 99
99 } // namespace chromeos 100 } // namespace chromeos
100 101
101 #endif 102 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698