Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_profile_chromeos.h
blobfbbb9f660ad3fe69d64050271d51e8b6c4c89e7c
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_
8 #include "base/memory/weak_ptr.h"
9 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
10 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
12 #include "device/bluetooth/bluetooth_export.h"
14 namespace device {
15 class BluetoothUUID;
16 } // namespace device
18 namespace chromeos {
20 // The BluetoothAdapterProfileChromeOS class implements a multiplexing
21 // profile for custom Bluetooth services managed by a BluetoothAdapter.
22 // Maintains a list of delegates which may serve the profile.
23 // One delegate is allowed for each device.
25 // BluetoothAdapterProfileChromeOS objects are owned by the
26 // BluetoothAdapterChromeOS and allocated through Register()
27 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileChromeOS
28 : public chromeos::BluetoothProfileServiceProvider::Delegate {
29 public:
30 typedef base::Callback<void(scoped_ptr<BluetoothAdapterProfileChromeOS>
31 profile)> ProfileRegisteredCallback;
33 // Registers a profile with the BlueZ server for |uuid| with the
34 // options |options|. |success_callback| is provided with a newly
35 // allocated profile if registration is successful, otherwise |error_callback|
36 // will be called.
37 static void Register(
38 const device::BluetoothUUID& uuid,
39 const BluetoothProfileManagerClient::Options& options,
40 const ProfileRegisteredCallback& success_callback,
41 const BluetoothProfileManagerClient::ErrorCallback& error_callback);
43 ~BluetoothAdapterProfileChromeOS() override;
45 // The object path of the profile.
46 const dbus::ObjectPath& object_path() const { return object_path_; }
48 // Returns the UUID of the profile
49 const device::BluetoothUUID& uuid() const { return uuid_; }
51 // Add a delegate for a device associated with this profile.
52 // An empty |device_path| indicates a local listening service.
53 // Returns true if the delegate was set, and false if the |device_path|
54 // already had a delegate set.
55 bool SetDelegate(const dbus::ObjectPath& device_path,
56 BluetoothProfileServiceProvider::Delegate* delegate);
58 // Remove the delegate for a device. |unregistered_callback| will be called
59 // if this unregisters the profile.
60 void RemoveDelegate(const dbus::ObjectPath& device_path,
61 const base::Closure& unregistered_callback);
63 // Returns the number of delegates for this profile.
64 size_t DelegateCount() const { return delegates_.size(); }
66 private:
67 BluetoothAdapterProfileChromeOS(const device::BluetoothUUID& uuid);
69 // BluetoothProfileServiceProvider::Delegate:
70 void Released() override;
71 void NewConnection(
72 const dbus::ObjectPath& device_path,
73 scoped_ptr<dbus::FileDescriptor> fd,
74 const BluetoothProfileServiceProvider::Delegate::Options& options,
75 const ConfirmationCallback& callback) override;
76 void RequestDisconnection(const dbus::ObjectPath& device_path,
77 const ConfirmationCallback& callback) override;
78 void Cancel() override;
80 // Called by dbus:: on completion of the D-Bus method to unregister a profile.
81 void OnUnregisterProfileError(const base::Closure& unregistered_callback,
82 const std::string& error_name,
83 const std::string& error_message);
85 // List of delegates which this profile is multiplexing to.
86 std::map<std::string, BluetoothProfileServiceProvider::Delegate*> delegates_;
88 // The UUID that this profile represents.
89 const device::BluetoothUUID& uuid_;
91 // Registered dbus object path for this profile.
92 dbus::ObjectPath object_path_;
94 // Profile dbus object for receiving profile method calls from BlueZ
95 scoped_ptr<BluetoothProfileServiceProvider> profile_;
97 // Note: This should remain the last member so it'll be destroyed and
98 // invalidate its weak pointers before any other members are destroyed.
99 base::WeakPtrFactory<BluetoothAdapterProfileChromeOS> weak_ptr_factory_;
101 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileChromeOS);
104 } // namespace chromeos
106 #endif