fake_bluetooth_admin_policy_client.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2021 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. #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_ADMIN_POLICY_CLIENT_H_
  5. #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_ADMIN_POLICY_CLIENT_H_
  6. #include <cstdint>
  7. #include <map>
  8. #include <memory>
  9. #include <vector>
  10. #include "base/observer_list.h"
  11. #include "dbus/object_path.h"
  12. #include "dbus/property.h"
  13. #include "device/bluetooth/bluetooth_export.h"
  14. #include "device/bluetooth/dbus/bluetooth_admin_policy_client.h"
  15. namespace bluez {
  16. // FakeBluetoothAdminPolicyClient simulates the behavior of the Bluetooth Daemon
  17. // admin policy objects and is used both in test cases in place of a mock and on
  18. // the Linux desktop.
  19. class DEVICE_BLUETOOTH_EXPORT FakeBluetoothAdminPolicyClient
  20. : public BluetoothAdminPolicyClient {
  21. public:
  22. struct Properties : public BluetoothAdminPolicyClient::Properties {
  23. explicit Properties(const PropertyChangedCallback& callback);
  24. ~Properties() override;
  25. // dbus::PropertySet override
  26. void Get(dbus::PropertyBase* property,
  27. dbus::PropertySet::GetCallback callback) override;
  28. void GetAll() override;
  29. void Set(dbus::PropertyBase* property,
  30. dbus::PropertySet::SetCallback callback) override;
  31. };
  32. FakeBluetoothAdminPolicyClient();
  33. ~FakeBluetoothAdminPolicyClient() override;
  34. // BluetoothAdminPolicyClient overrides
  35. void Init(dbus::Bus* bus, const std::string& bluetooth_service_name) override;
  36. void AddObserver(Observer* observer) override;
  37. void RemoveObserver(Observer* observer) override;
  38. Properties* GetProperties(const dbus::ObjectPath& object_path) override;
  39. void SetServiceAllowList(const dbus::ObjectPath& object_path,
  40. const UUIDList& service_uuids,
  41. base::OnceClosure callback,
  42. ErrorCallback error_callback) override;
  43. void CreateAdminPolicy(const dbus::ObjectPath& object_path,
  44. bool is_blocked_by_policy);
  45. void ChangeAdminPolicy(const dbus::ObjectPath& object_path,
  46. bool is_blocked_by_policy);
  47. void RemoveAdminPolicy(const dbus::ObjectPath& object_path);
  48. private:
  49. // Property callback passed when we create Properties* structures.
  50. void OnPropertyChanged(const dbus::ObjectPath& object_path,
  51. const std::string& property_name);
  52. // List of observers interested in event notifications from us.
  53. base::ObserverList<Observer>::Unchecked observers_;
  54. using PropertiesMap =
  55. std::map<const dbus::ObjectPath, std::unique_ptr<Properties>>;
  56. PropertiesMap properties_map_;
  57. };
  58. } // namespace bluez
  59. #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_ADMIN_POLICY_CLIENT_H_