liveness_service_provider.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2012 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 ASH_DBUS_LIVENESS_SERVICE_PROVIDER_H_
  5. #define ASH_DBUS_LIVENESS_SERVICE_PROVIDER_H_
  6. #include <string>
  7. #include "base/compiler_specific.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "chromeos/ash/components/dbus/services/cros_dbus_service.h"
  11. #include "dbus/exported_object.h"
  12. namespace dbus {
  13. class MethodCall;
  14. }
  15. namespace ash {
  16. // This class exports a "CheckLiveness" D-Bus method that the session manager
  17. // calls periodically to confirm that Chrome's UI thread is responsive to D-Bus
  18. // messages. It can be tested with the following command:
  19. //
  20. // % dbus-send --system --type=method_call --print-reply
  21. // --dest=org.chromium.LivenessService
  22. // /org/chromium/LivenessService
  23. // org.chromium.LivenessServiceInterface.CheckLiveness
  24. //
  25. // -> method return sender=:1.9 -> dest=:1.27 reply_serial=2
  26. //
  27. // (An empty response should be returned.)
  28. class LivenessServiceProvider
  29. : public CrosDBusService::ServiceProviderInterface {
  30. public:
  31. LivenessServiceProvider();
  32. LivenessServiceProvider(const LivenessServiceProvider&) = delete;
  33. LivenessServiceProvider& operator=(const LivenessServiceProvider&) = delete;
  34. ~LivenessServiceProvider() override;
  35. // CrosDBusService::ServiceProviderInterface overrides:
  36. void Start(scoped_refptr<dbus::ExportedObject> exported_object) override;
  37. private:
  38. // Called from ExportedObject when CheckLiveness() is exported as a D-Bus
  39. // method or failed to be exported.
  40. void OnExported(const std::string& interface_name,
  41. const std::string& method_name,
  42. bool success);
  43. // Called on UI thread in response to a D-Bus request.
  44. void CheckLiveness(dbus::MethodCall* method_call,
  45. dbus::ExportedObject::ResponseSender response_sender);
  46. // Keep this last so that all weak pointers will be invalidated at the
  47. // beginning of destruction.
  48. base::WeakPtrFactory<LivenessServiceProvider> weak_ptr_factory_{this};
  49. };
  50. } // namespace ash
  51. #endif // ASH_DBUS_LIVENESS_SERVICE_PROVIDER_H_