OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_EXPERIMENTAL_CHROMEOS_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_EXPERIMENTAL_CHROMEOS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chromeos/chromeos_export.h" |
| 14 #include "chromeos/dbus/experimental_bluetooth_profile_service_provider.h" |
| 15 #include "dbus/object_path.h" |
| 16 #include "device/bluetooth/bluetooth_profile.h" |
| 17 |
| 18 namespace dbus { |
| 19 |
| 20 class FileDescriptor; |
| 21 |
| 22 } // namespace dbus |
| 23 |
| 24 namespace device { |
| 25 |
| 26 class BluetoothAdapter; |
| 27 |
| 28 } // namespace device |
| 29 |
| 30 namespace chromeos { |
| 31 |
| 32 class CHROMEOS_EXPORT BluetoothProfileExperimentalChromeOS |
| 33 : public device::BluetoothProfile, |
| 34 private ExperimentalBluetoothProfileServiceProvider::Delegate { |
| 35 public: |
| 36 // BluetoothProfile override. |
| 37 virtual void Unregister() OVERRIDE; |
| 38 virtual void SetConnectionCallback( |
| 39 const ConnectionCallback& callback) OVERRIDE; |
| 40 |
| 41 // Return the UUID of the profile. |
| 42 const std::string& uuid() const { return uuid_; } |
| 43 |
| 44 private: |
| 45 friend BluetoothProfile; |
| 46 |
| 47 BluetoothProfileExperimentalChromeOS(); |
| 48 virtual ~BluetoothProfileExperimentalChromeOS(); |
| 49 |
| 50 // Called by BluetoothProfile::Register to initialize the profile object |
| 51 // asynchronously. |uuid|, |options| and |callback| are the arguments to |
| 52 // BluetoothProfile::Register. |
| 53 void Init(const std::string& uuid, |
| 54 const device::BluetoothProfile::Options& options, |
| 55 const ProfileCallback& callback); |
| 56 |
| 57 // ExperimentalBluetoothProfileServiceProvider::Delegate override. |
| 58 virtual void Release() OVERRIDE; |
| 59 virtual void NewConnection( |
| 60 const dbus::ObjectPath& device_path, |
| 61 dbus::FileDescriptor* fd, |
| 62 const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
| 63 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; |
| 69 |
| 70 // Called by dbus:: on completion of the D-Bus method call to register the |
| 71 // profile object. |
| 72 void OnRegisterProfile(const ProfileCallback& callback); |
| 73 void OnRegisterProfileError(const ProfileCallback& callback, |
| 74 const std::string& error_name, |
| 75 const std::string& error_message); |
| 76 |
| 77 // Called by dbus:: on completion of the D-Bus method call to unregister |
| 78 // the profile object. |
| 79 void OnUnregisterProfile(); |
| 80 void OnUnregisterProfileError(const std::string& error_name, |
| 81 const std::string& error_message); |
| 82 |
| 83 // Method run on a thread where i/o is permitted to verify the validity of |
| 84 // the file descriptor obtained over D-Bus, and method run once that is |
| 85 // complete back on the origin thread. |
| 86 // |
| 87 // These methods do not own the file descriptor |fd|; it is owned by the |
| 88 // base::Bind call used to call them. |
| 89 void CheckValidity(dbus::FileDescriptor* fd); |
| 90 void OnCheckValidity( |
| 91 const dbus::ObjectPath& device_path, |
| 92 dbus::FileDescriptor* fd, |
| 93 const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
| 94 options, |
| 95 const ConfirmationCallback& callback); |
| 96 |
| 97 // Method run once the default adapter has been obtained, obtains the device |
| 98 // to be passed to the created BluetoothSocket. |
| 99 // |
| 100 // Does not own the file descriptor |fd| but can take the value. |
| 101 void OnGetAdapter( |
| 102 const dbus::ObjectPath& device_path, |
| 103 dbus::FileDescriptor* fd, |
| 104 const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
| 105 options, |
| 106 const ConfirmationCallback& callback, |
| 107 scoped_refptr<device::BluetoothAdapter>); |
| 108 |
| 109 // UUID of the profile passed during initialization. |
| 110 std::string uuid_; |
| 111 |
| 112 // Object path of the local profile D-Bus object. |
| 113 dbus::ObjectPath object_path_; |
| 114 |
| 115 // Local profile D-Bus object used for receiving profile delegate methods |
| 116 // from BlueZ. |
| 117 scoped_ptr<ExperimentalBluetoothProfileServiceProvider> profile_; |
| 118 |
| 119 // Callback used on both outgoing and incoming connections to pass the |
| 120 // connected socket to profile object owner. |
| 121 ConnectionCallback connection_callback_; |
| 122 |
| 123 // Note: This should remain the last member so it'll be destroyed and |
| 124 // invalidate its weak pointers before any other members are destroyed. |
| 125 base::WeakPtrFactory<BluetoothProfileExperimentalChromeOS> weak_ptr_factory_; |
| 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileExperimentalChromeOS); |
| 128 }; |
| 129 |
| 130 } // namespace chromeos |
| 131 |
| 132 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_EXPERIMENTAL_CHROMEOS_H_ |
OLD | NEW |