dbus_thread_manager_base.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 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 CHROMEOS_DBUS_INIT_DBUS_THREAD_MANAGER_BASE_H_
  5. #define CHROMEOS_DBUS_INIT_DBUS_THREAD_MANAGER_BASE_H_
  6. #include <memory>
  7. #include "base/component_export.h"
  8. #include "base/memory/ref_counted.h"
  9. namespace base {
  10. class Thread;
  11. } // namespace base
  12. namespace dbus {
  13. class Bus;
  14. } // namespace dbus
  15. namespace chromeos {
  16. // DBusThreadManagerBase manages the D-Bus thread (the thread dedicated to
  17. // handling asynchronous D-Bus operations) and the D-Bus connection.
  18. // Derived classes and callers are responsible for managing D-Bus clients (which
  19. // depend on the D-Bus thread), and need to ensure that D-Bus clients shut down
  20. // before the D-Bus connection closes and the D-Bus thread stops in
  21. // ~DBusThreadManagerBase().
  22. class COMPONENT_EXPORT(CHROMEOS_DBUS_INIT) DBusThreadManagerBase {
  23. public:
  24. // Returns true if clients are faked.
  25. bool IsUsingFakes();
  26. // Returns various D-Bus bus instances, owned by DBusThreadManager.
  27. dbus::Bus* GetSystemBus();
  28. protected:
  29. DBusThreadManagerBase();
  30. DBusThreadManagerBase(const DBusThreadManagerBase&) = delete;
  31. const DBusThreadManagerBase& operator=(const DBusThreadManagerBase&) = delete;
  32. virtual ~DBusThreadManagerBase();
  33. private:
  34. // Whether to use real or fake dbus clients.
  35. const bool use_real_clients_;
  36. std::unique_ptr<base::Thread> dbus_thread_;
  37. scoped_refptr<dbus::Bus> system_bus_;
  38. };
  39. } // namespace chromeos
  40. #endif // CHROMEOS_DBUS_INIT_DBUS_THREAD_MANAGER_BASE_H_