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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
16 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
17 #include "dbus/object_path.h"
18 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_profile.h"
20 #include "device/bluetooth/bluetooth_uuid.h"
30 // The BluetoothProfileChromeOS class implements BluetoothProfile for the
31 // Chrome OS platform.
32 class CHROMEOS_EXPORT BluetoothProfileChromeOS
33 : public device::BluetoothProfile
,
34 public device::BluetoothAdapter::Observer
,
35 public BluetoothProfileServiceProvider::Delegate
{
37 // BluetoothProfile override.
38 virtual void Unregister() OVERRIDE
;
39 virtual void SetConnectionCallback(
40 const ConnectionCallback
& callback
) OVERRIDE
;
42 // Return the UUID of the profile.
43 const device::BluetoothUUID
& uuid() const { return uuid_
; }
46 friend class BluetoothProfile
;
48 BluetoothProfileChromeOS();
49 virtual ~BluetoothProfileChromeOS();
51 // Called by BluetoothProfile::Register to initialize the profile object
52 // asynchronously. |uuid|, |options| and |callback| are the arguments to
53 // BluetoothProfile::Register.
54 void Init(const device::BluetoothUUID
& uuid
,
55 const device::BluetoothProfile::Options
& options
,
56 const ProfileCallback
& callback
);
58 // BluetoothProfileServiceProvider::Delegate override.
59 virtual void Released() OVERRIDE
;
60 virtual void NewConnection(
61 const dbus::ObjectPath
& device_path
,
62 scoped_ptr
<dbus::FileDescriptor
> fd
,
63 const BluetoothProfileServiceProvider::Delegate::Options
& options
,
64 const ConfirmationCallback
& callback
) OVERRIDE
;
65 virtual void RequestDisconnection(
66 const dbus::ObjectPath
& device_path
,
67 const ConfirmationCallback
& callback
) OVERRIDE
;
68 virtual void Cancel() OVERRIDE
;
70 // device::BluetoothAdapter::Observer override.
71 virtual void AdapterPresentChanged(device::BluetoothAdapter
* adapter
,
72 bool present
) OVERRIDE
;
74 // Called by dbus:: on completion of the D-Bus method call to register the
75 // profile object as a result of the adapter becoming present.
76 void OnInternalRegisterProfile();
77 void OnInternalRegisterProfileError(const std::string
& error_name
,
78 const std::string
& error_message
);
80 // Internal method run to get the adapter object during initialization.
81 void OnGetAdapter(const ProfileCallback
& callback
,
82 scoped_refptr
<device::BluetoothAdapter
> adapter
);
84 // Called by dbus:: on completion of the D-Bus method call to register the
85 // profile object during initialization.
86 void OnRegisterProfile(const ProfileCallback
& callback
);
87 void OnRegisterProfileError(const ProfileCallback
& callback
,
88 const std::string
& error_name
,
89 const std::string
& error_message
);
91 // Called by dbus:: on completion of the D-Bus method call to unregister
92 // the profile object.
93 void OnUnregisterProfile();
94 void OnUnregisterProfileError(const std::string
& error_name
,
95 const std::string
& error_message
);
97 // Method run once the file descriptor has been validated in order to get
98 // the device object to be passed to the connection callback.
100 // The |fd| argument is moved compared to the NewConnection() call since it
101 // becomes the result of a PostTaskAndReplyWithResult() call.
102 void OnCheckValidity(
103 const dbus::ObjectPath
& device_path
,
104 const BluetoothProfileServiceProvider::Delegate::Options
& options
,
105 const ConfirmationCallback
& callback
,
106 scoped_ptr
<dbus::FileDescriptor
> fd
);
108 // UUID of the profile passed during initialization.
109 device::BluetoothUUID uuid_
;
111 // Copy of the profile options passed during initialization.
112 BluetoothProfileManagerClient::Options options_
;
114 // Object path of the local profile D-Bus object.
115 dbus::ObjectPath object_path_
;
117 // Local profile D-Bus object used for receiving profile delegate methods
119 scoped_ptr
<BluetoothProfileServiceProvider
> profile_
;
121 // Reference to the adapter object, the profile is re-registered when the
123 scoped_refptr
<device::BluetoothAdapter
> adapter_
;
125 // Callback used on both outgoing and incoming connections to pass the
126 // connected socket to profile object owner.
127 ConnectionCallback connection_callback_
;
129 // Note: This should remain the last member so it'll be destroyed and
130 // invalidate its weak pointers before any other members are destroyed.
131 base::WeakPtrFactory
<BluetoothProfileChromeOS
> weak_ptr_factory_
;
133 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileChromeOS
);
136 } // namespace chromeos
138 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_